AmiBlitz³
TK Player Source - Druckversion

+- AmiBlitz³ (https://www.amiblitz.de/community)
+-- Forum: AmiBlitz³ (https://www.amiblitz.de/community/forum-3.html)
+--- Forum: Snippets & Libraries (https://www.amiblitz.de/community/forum-9.html)
+--- Thema: TK Player Source (/thread-248.html)



TK Player Source - HelmutH - 04.07.2021

Zum Projekt: TK Player - Multiformat AHI Player
Dies ist der Code zum

TK Player013 lite.bb2
Code:
WBStartup
optimize 7
Syntax 2
ver.s = "$VER: TKPlayer Lite 1.2 (\\__DATE_GER__)"

#buffersize  = 250      ; 100 msecs double buffering
#ahi_unit    = 0        ; play on ahi.device unit 0

#max_files=2

XINCLUDE "dos.include.bb2"
XINCLUDE "file_audio.include.bb2"
XINCLUDE "ahi_device.include.bb2"
error_flags {#error_stout}


dummy.l = dos_settaskpri {2}
succ.l  = True
If NumPars>0 Then filename.s = Par$(1)
If ahi_open{#ahi_unit} ; open ahi.device
 If ahi_stream_open{filename.s,#buffersize}
   While succ=True
     succ = ahi_stream_do{}
     signals.l = Wait_(-1)
     If (signals & #SIGBREAKF_CTRL_C) Then succ=False
   Wend
 End If
 Delay_ 2
 ahi_close {}
End If
ffa_free{}
End

Und dieser für 
TK Player014.bb2 
Code:
WBStartup

optimize 7
Syntax 2
ver.s = "$VER: TKPlayer 1.4 (\\__DATE_GER__)"

#max_files= 2
XINCLUDE "dos.include.bb2"
XINCLUDE "file_audio.include.bb2"
XINCLUDE "ahi_device.include.bb2"
error_flags{#error_stout}
speed.l      = dos_gettoolvalue{"SPEED",100}
infos.l      = dos_gettoolvalue{"INFO",0}
nogui.l      = dos_gettoolvalue{"NOGUI",0}
ahiunit.l    = dos_gettoolvalue{"AHIUNIT",0}
pri.l        = dos_gettoolvalue{"PRI",2}
buffersize.l = dos_gettoolvalue{"BUFFERSIZE",250}

 If dos_numpars{}>0 Then filename.s = dos_nextarg{};:Else error {"no cli args !"}

 Repeat
   option.s = UCase$(dos_nextarg{})
   If Peek.b(&option.s) = @"-" Then option.s = Right$(option.s,Len(otpion.s)-1)
   Select option.s
     Case "NOGUI"
       nogui.l = True

     Case "SPEED"
       speed.l = Vallong(dos_nextarg{})

     Case "OFFSET"
         msoffset.l = Vallong(dos_nextarg{})
         If msoffset<0 Then msoffset=0

     Case "INFO"
       infos.l = True

     Case "AHIUNIT"
       ahiunit = Vallong(dos_nextarg{})

     Case "BUFFERSIZE"
       buffersize = Vallong(dos_nextarg{})

     Case "PRI"
       pri.l = Vallong(dos_nextarg{})

   End Select
 Until option.s = ""
 If nogui=False Then infos=False
 If buffersize<10 Then buffersize=10
 If buffersize>10000 Then buffersize=10000
 If speed<50 Then speed=50
 If speed>200 Then speed=200
 If ahiunit>3 OR ahiunit<0 Then ahiunit=0


 If filename.s><"?" AND filename.s><"-h"
 dos.l = ffa_read {filename.s}

 If dos.l><-1
   fil.s        = file_name {dos}         ; read file properties
   channels.l   = ffa_channels {dos}      : If channels><1 AND channels><2 Then channels = 2
   samplerate.l = ffa_samplerate {dos}
   bits.l       = ffa_bits {dos}          : If bits><16 AND bits><8 Then bits = 16
   todo.l       = ffa_blength {dos}
   frsize.l     = ffa_framesize {dos}
   filename.s   = file_fullname {dos}
   ahibuffersize.l = buffersize
   buffersize.l = buffersize * samplerate / 1000
   buffersize   * channels * Int(bits/2)
   If buffersize<256 Then buffersize=256

   blength.l     = todo.l
   bufflength.l  = todo / buffersize
   If bufflength<1 Then bufflength=1
   succ.l        = True
   fsamplerate.f = samplerate
   foffset.f     = msoffset
   foffset       = foffset * fsamplerate / 1000
   fileoffset.l  = foffset

   If fileoffset>0
     succ.l = ffa_seek{dos,fileoffset}
     todo - fileoffset *frsize
   End If

   sectime.l = blength / samplerate / channels * 8 / bits

   totaltime.l = sectime : If totaltime<1 Then totaltime=1

   mintime.l = sectime / 60
   sectime.l = sectime MOD 60
   Format "00"
   tim.s = "/"+Str$(mintime)+":"+Str$(sectime)+" "+fil.s
   b.s = Str$(0)+":"+Str$(0)+tim.s

   flength.l = blength/frsize
   If infos
     Format ""

     NPrint "File:         ",filename.s

     Format "00"

     NPrint "Duration:     ",Str$(mintime)+":"+Str$(sectime)
     Format ""

     NPrint "Samplerate:   ",samplerate
     NPrint "Bits:         ",bits
     NPrint "Channels:     ",channels
     NPrint "Sampleframes: ",flength
     Format "00"
     NPrint "Starting ..."

   End If


   If nogui=False
     *scr.Screen = Peek.l(Addr Screen(0))
     titleheight.l = *scr\WBorTop + *scr\Font\ta_YSize + 1
     pixwidth.l = Min(TextLength_ (*scr\RastPort,&b.s,Peek.l(&b.s-4)) +64,*scr\Width-32)
     DefaultIDCMP #IDCMP_CLOSEWINDOW|#IDCMP_ACTIVEWINDOW
     Window 0,(*scr\Width-pixwidth)/2,*scr\Height/2-6,pixwidth,titleheight,$E,b.s,1,0
   End If

   dummy.l = dos_settaskpri {pri}

   If ahi_open{ahiunit} ; open ahi.device
     If ahi_stream_open{filename.s,ahibuffersize,speed}
       While succ=True
         If succ Then succ = ahi_stream_do{}
         sectime.l = ahi_stream_timeindex{} / samplerate
         mintime.l = sectime / 60
         sectime.l = sectime MOD 60
         procent.l = ahi_stream_timeindex{} / samplerate * 100 / totaltime

         a.s = Str$(mintime)+":"+Str$(sectime)+tim.s
         If a.s >< b.s
           If nogui=False
             ;If locklayer{0}
               SetWindowTitles_ Peek.l(Addr Window(0)),&a.s,0
             ;  unlocklayer{}
             ;End If
           End If
           If infos
             Format ""
             c.s = Str$(procent)+"% - "
             Format "00"
             c.s = Str$(mintime)+":"+Str$(sectime)
             NPrint Chr$(11)+"playing ",c.s,tim.s
           End If
           b.s = a.s
         End If

         signals.l = Wait_(-1)

         If (signals & #SIGBREAKF_CTRL_C) Then succ=False

         Repeat ; check for closewindow event
           idcmp.l=Event
           If idcmp = #IDCMP_CLOSEWINDOW Then succ=False
         Until idcmp = 0

       Wend
     End If
     Delay_ 5
     ahi_close {}
   End If
   ffa_close {dos}
 End If
 Else
   NPrint "Usage: TKPlayer [?] [<filename>] [ahiunit ...] [buffersize ...] [info] [nogui] [speed ...] [offset ...] [pri ...]"
   NPrint " "
   NPrint "Parameters:"
   NPrint "  filename   - valid DOS filename with path"
   NPrint "  ahiunit    - 0..3, unit of ahi.device"
   NPrint "  buffersize - buffersize in milliseconds, default is 250"
   NPrint "  speed      - playback speed in %, default is 100"
   NPrint "  offset     - offset from where to start playback in ms, default is 0"
   NPrint "  info       - display infos in shell"
   NPrint "  nogui      - do not open playback window"
   NPrint "  pri        - set task priority, default is 2"
   NPrint "  ?          - display this help"
   NPrint " "
   NPrint "Example: TKPlayer Sys:Music/mymusic.mp3 ahiunit 1 buffersize 500 nogui speed 75 offset 1000"
   NPrint "This will play the file \\22Sys:Music/mymusic.mp3\\22 on ahi unit 1 with a buffersize of 0,5 secs, at 75% speed, from 1sec after the beginning, showing no gui window"
   NPrint " "
 End If

 If infos
   NPrint "Done."
 End If
 ffa_free{}
End