Aktuelle Zeit: 19.07.2018 08:07

Alle Zeiten sind UTC + 1 Stunde [ Sommerzeit ]




Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: Wie kann man libout123 benutzen ?
BeitragVerfasst: 07.04.2018 22:53 
Offline

Registriert: 27.11.2016 18:13
Wohnort: Erzgebirge
Hallo Leute,
ich probiere eine Mp3 mit der libmpg123.so.0 zu dekodieren.

Das funktioniert auch.
Es wird eine Roh-Audio-Datei erstellt. (Diese kann man z.B. mit Audacity öffnen.)

Zum Abspielen kann man aber auch die weiter Bibliothek "libout123.so.0" verwenden.

Nur ich weiß noch nicht so richtig wie.

Hier zum testen: (64bit)

Testfile

Hier einmal ein Ansatz:

Code:
#MPG123_DONE=-12
#MPG123_ERR=-1
#MPG123_OK = 0
#OUT123_OK = 0
#MPG123_ENC_16        = $040      ; < 0000 0100 0000 Some 16 bit integer encoding.
#MPG123_ENC_SIGNED    = $080      ; < 0000 1000 0000 Some signed integer encoding.
#MPG123_ENC_SIGNED_16 = (#MPG123_ENC_16|#MPG123_ENC_SIGNED|$10)

MP3_FILENAME.s = GetCurrentDirectory()+"test.mp3"

ImportC "libout123.so.0"
  out123_del(*ao)
  out123_new()
  out123_enc_byname(*name)    
  out123_enc_name(encoding)
  out123_drivers(*ao, *names, *descr)
  out123_driver_info(*ao, *driver, *device)
  out123_open(*ao, *driver, *device)
  out123_start(*ao, rate.l, channels, encoding)
  out123_getformat(*ao, *rate, *channels, *encoding, *framesize)    
  out123_play(*ao, *buffer, bytes)
EndImport

ImportC "libmpg123.so.0"
  mpg123_init()
  mpg123_new(*decoder, *error)
  mpg123_open(*mh, *path)
  mpg123_getformat(*mh, *rate, *channels, *encoding)
  mpg123_plain_strerror(errcode.l)
  mpg123_strerror(*mh)
  mpg123_format_none(*mh)
  mpg123_format(*mh, rate.l, channels.l, encodings.l)
  mpg123_outblock(*mh)
  mpg123_read(*mh, *outmemory, outmemsize, *done)
  mpg123_decode(*mh, *inmemory, inmemsize, *outmemory, outmemsize.l, *done)
  mpg123_close(*mh)
  mpg123_delete(*mp)
  mpg123_exit()
  mpg123_length(*mh)
EndImport

Global *mpg123_handle, *out123_handle, *driver, *outfile

;Force a pointer To be 16 byte Aligned
Macro Align16(pointer)
  (((pointer) + 15) &~ $0F)
EndMacro

Procedure AllocateAlignedMemory(Size.l)
Protected pointer.l, ReturningPointer.l
  pointer = AllocateMemory(Size + 16)
  ReturningPointer = Align16(pointer)
  PokeB(ReturningPointer + Size + 1, (pointer % 16))
  ProcedureReturn ReturningPointer
EndProcedure

Procedure DBG(msg.s)
  CompilerIf #PB_Compiler_Debugger = 1
    Debug msg
  CompilerElse
    MessageRequester("Debug", msg)
  CompilerEndIf
EndProcedure

Procedure Mp3_To_MemoryPlay(filename.s)
  Protected err.l = #MPG123_OK, err_open.l = #MPG123_OK, err_getformat.l = #MPG123_OK
  Protected channels.l = 0, encoding.l = 0
  Protected rate.l = 0
  Protected buffer_size.l = 0
  Protected num_samples.l = 0
  Protected bytes_memory.l = 0
  Protected *buffer_memory, *ptr_buffer_memory
  Protected bytes_read.l, delta.l, remaining.l
  Protected done.l = #MPG123_OK
  Protected enc, encname.s, framesize = 1, played, *play_buffer
  Protected *diver_names, *driver
 
  *outfile = Ascii(GetCurrentDirectory()+"test.wav")
 
  err = mpg123_init()
  *mpg123_handle = mpg123_new(#Null, @err)
  *out123_handle = out123_new()
  enc = out123_enc_byname(*outfile)
 
  err_open = mpg123_open(*mpg123_handle, UTF8(filename))
  err_getformat = mpg123_getformat(*mpg123_handle, @rate, @channels, @encoding)
  If err <> #MPG123_OK Or *mpg123_handle = #Null Or err_open <> #MPG123_OK Or err_getformat <> #MPG123_OK
    If *mpg123_handle = #Null                 
      DBG(PeekS(mpg123_plain_strerror(err), -1, #PB_Ascii))
    Else
      DBG(PeekS(mpg123_strerror(*mpg123_handle), -1, #PB_Ascii))
    EndIf
    out123_del(*out123_handle)
    mpg123_close(*mpg123_handle)
    mpg123_delete(*mpg123_handle)
    mpg123_exit() 
    ProcedureReturn -1           
  EndIf
 
  If(encoding <> #MPG123_ENC_SIGNED_16)
    DBG("Bad encoding: " + Str(encoding) )
    ProcedureReturn -2
  EndIf
  mpg123_format_none(*mpg123_handle)
  mpg123_format(*mpg123_handle, rate, channels, encoding)
  buffer_size = mpg123_outblock(*mpg123_handle)
  num_samples = mpg123_length(*mpg123_handle)
  bytes_memory = num_samples * channels * SizeOf(Word) ;convert samples to bytes
  *buffer_memory = AllocateMemory(bytes_memory)
  If MemorySize(*buffer_memory) <> bytes_memory
    DBG("Failed to alloc a buffer memory, size = " + Str(MemorySize(*buffer_memory)) )
    ProcedureReturn -1
  EndIf
 
  *diver_names = AllocateMemory(20)
 
  out123_drivers(*out123_handle, *driver, #Null)
 
  ;Debug PeekS(*driver_names)
 
  ;out123_driver_info(*out123_handle, *driver, #Null)
 
  ;Debug PeekS(@driver, -1, #PB_Ascii)
 
  If out123_open(*out123_handle, #Null, #Null) <> #OUT123_OK
    out123_del(*out123_handle)
    mpg123_close(*mpg123_handle)
    mpg123_delete(*mpg123_handle)
    mpg123_exit() 
    ProcedureReturn -1   
  EndIf
 
  encname = PeekS(out123_enc_name(encoding), -1, #PB_Ascii)
 
  If out123_start(*out123_handle, rate, channels, encoding) Or out123_getformat(*out123_handle, #Null, #Null, #Null, @framesize)
    out123_del(*out123_handle)
    mpg123_close(*mpg123_handle)
    mpg123_delete(*mpg123_handle)
    mpg123_exit() 
    ProcedureReturn -1
  EndIf
 
  ;Mp3 abspielen über Audio-Driver.
  ;Geht noch nicht!!!
  ;Wie könnte es funktionieren ? (Probleme mit Audio-Driver)
 
;   *play_buffer = AllocateMemory(buffer_size)
;   
;   Repeat
;     err = mpg123_read(*mpg123_handle, *play_buffer, buffer_size, @done)
;     played = out123_play(*out123_handle, *play_buffer, done)
;     If played <> done
;       Debug @done
;     EndIf
;     ;samples + played / framesize
;   Until done And err = #MPG123_OK
;   
;   FreeMemory(*play_buffer)
 
  ;Rohdaten schreiben !
  *ptr_buffer_memory = *buffer_memory
  bytes_read = 0
  remaining = bytes_memory
  While 1
    delta = buffer_size
    remaining = bytes_memory - bytes_read
    If remaining <= 0
      Break
    EndIf
    If delta > remaining
      delta = remaining
    EndIf
   
    err = mpg123_read(*mpg123_handle, *ptr_buffer_memory, delta, @done)
   
    If err <> #MPG123_OK
      Break
    EndIf   
    *ptr_buffer_memory + done
    bytes_read + done
    remaining - delta
  Wend
 
  If bytes_read <> bytes_memory
    Debug "num_samples done <> num_samples to read !"
  EndIf
 
  If err <> #MPG123_DONE
    If err = #MPG123_ERR
      DBG(PeekS(mpg123_strerror(*mpg123_handle), -1, #PB_Ascii))
    Else
      DBG(PeekS(mpg123_plain_strerror(err), -1, #PB_Ascii))
    EndIf
  EndIf
 
  ;Eine decodiere Mp3-Datei als RAW-Audio-Datei (Kann man z.B. mit Audacity (über Import) öffnen.)
  If CreateFile(0, "test.raw")
    WriteData(0, *buffer_memory, bytes_memory)
    CloseFile(0)
  EndIf
 
  out123_del(*out123_handle)
  mpg123_close(*mpg123_handle)
  mpg123_delete(*mpg123_handle)
  mpg123_exit()
EndProcedure

Mp3_To_MemoryPlay(MP3_FILENAME)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Wie kann man libout123 benutzen ?
BeitragVerfasst: 07.04.2018 23:58 
Offline

Registriert: 27.11.2016 18:13
Wohnort: Erzgebirge
Es funktioniert!!!

Code:
#MPG123_DONE=-12
#MPG123_ERR=-1
#MPG123_OK = 0
#OUT123_OK = 0
#MPG123_ENC_16        = $040      ; < 0000 0100 0000 Some 16 bit integer encoding.
#MPG123_ENC_SIGNED    = $080      ; < 0000 1000 0000 Some signed integer encoding.
#MPG123_ENC_SIGNED_16 = (#MPG123_ENC_16|#MPG123_ENC_SIGNED|$10)

MP3_FILENAME.s = GetCurrentDirectory()+"test.mp3"

ImportC "libout123.so.0" ;"libout123-0.dll"
  out123_del(*ao)
  out123_new()
  out123_enc_byname(*name)    
  out123_enc_name(encoding)
  out123_drivers(*ao, *names, *descr)
  out123_driver_info(*ao, *driver, *device)
  out123_open(*ao, *driver, *device)
  out123_start(*ao, rate.l, channels, encoding)
  out123_getformat(*ao, *rate, *channels, *encoding, *framesize)    
  out123_play(*ao, *buffer, bytes)
EndImport

ImportC "libmpg123.so.0" ;"libmpg123-0.dll"
  mpg123_init()
  mpg123_new(*decoder, *error)
  mpg123_open(*mh, *path)
  mpg123_getformat(*mh, *rate, *channels, *encoding)
  mpg123_plain_strerror(errcode.l)
  mpg123_strerror(*mh)
  mpg123_format_none(*mh)
  mpg123_format(*mh, rate.l, channels.l, encodings.l)
  mpg123_outblock(*mh)
  mpg123_read(*mh, *outmemory, outmemsize, *done)
  mpg123_decode(*mh, *inmemory, inmemsize, *outmemory, outmemsize.l, *done)
  mpg123_close(*mh)
  mpg123_delete(*mp)
  mpg123_exit()
  mpg123_length(*mh)
EndImport

Global *mpg123_handle, *out123_handle, *driver, *outfile

;Force a pointer To be 16 byte Aligned
Macro Align16(pointer)
  (((pointer) + 15) &~ $0F)
EndMacro

Procedure AllocateAlignedMemory(Size.l)
  Protected pointer.l, ReturningPointer.l
  pointer = AllocateMemory(Size + 16)
  ReturningPointer = Align16(pointer)
  PokeB(ReturningPointer + Size + 1, (pointer % 16))
  ProcedureReturn ReturningPointer
EndProcedure

Procedure DBG(msg.s)
  CompilerIf #PB_Compiler_Debugger = 1
    Debug msg
  CompilerElse
    MessageRequester("Debug", msg)
  CompilerEndIf
EndProcedure

Procedure Mp3_To_MemoryPlay(filename.s)
  Protected err.l = #MPG123_OK, err_open.l = #MPG123_OK, err_getformat.l = #MPG123_OK
  Protected channels.l = 0, encoding.l = 0
  Protected rate.l = 0
  Protected buffer_size.l = 0
  Protected num_samples.l = 0
  Protected bytes_memory.l = 0
  Protected *buffer_memory, *ptr_buffer_memory
  Protected bytes_read.l, delta.l, remaining.l
  Protected done.l = #MPG123_OK
  Protected enc, encname.s, framesize = 1, played, *play_buffer
  Protected *driver
 
  *outfile = Ascii(GetCurrentDirectory()+"test.wav")
 
  err = mpg123_init()
  *mpg123_handle = mpg123_new(#Null, @err)
  *out123_handle = out123_new()
  enc = out123_enc_byname(*outfile)
 
  err_open = mpg123_open(*mpg123_handle, UTF8(filename))
  err_getformat = mpg123_getformat(*mpg123_handle, @rate, @channels, @encoding)
  If err <> #MPG123_OK Or *mpg123_handle = #Null Or err_open <> #MPG123_OK Or err_getformat <> #MPG123_OK
    If *mpg123_handle = #Null                 
      DBG(PeekS(mpg123_plain_strerror(err), -1, #PB_Ascii))
    Else
      DBG(PeekS(mpg123_strerror(*mpg123_handle), -1, #PB_Ascii))
    EndIf
    out123_del(*out123_handle)
    mpg123_close(*mpg123_handle)
    mpg123_delete(*mpg123_handle)
    mpg123_exit() 
    ProcedureReturn -1           
  EndIf
 
  If(encoding <> #MPG123_ENC_SIGNED_16)
    DBG("Bad encoding: " + Str(encoding) )
    ProcedureReturn -2
  EndIf
  mpg123_format_none(*mpg123_handle)
  mpg123_format(*mpg123_handle, rate, channels, encoding)
  buffer_size = mpg123_outblock(*mpg123_handle)
  num_samples = mpg123_length(*mpg123_handle)
  bytes_memory = num_samples * channels * SizeOf(Word) ;convert samples to bytes
  *buffer_memory = AllocateMemory(bytes_memory)
  If MemorySize(*buffer_memory) <> bytes_memory
    DBG("Failed to alloc a buffer memory, size = " + Str(MemorySize(*buffer_memory)) )
    ProcedureReturn -1
  EndIf
 
  If out123_open(*out123_handle, #Null, #Null) <> #OUT123_OK
    out123_del(*out123_handle)
    mpg123_close(*mpg123_handle)
    mpg123_delete(*mpg123_handle)
    mpg123_exit() 
    ProcedureReturn -1   
  EndIf
 
  encname = PeekS(out123_enc_name(encoding), -1, #PB_Ascii)
 
  If out123_start(*out123_handle, rate, channels, encoding) Or out123_getformat(*out123_handle, #Null, #Null, #Null, @framesize)
    out123_del(*out123_handle)
    mpg123_close(*mpg123_handle)
    mpg123_delete(*mpg123_handle)
    mpg123_exit() 
    ProcedureReturn -1
  EndIf
 
  ;   Mp3 abspielen über Audio-Driver.
 
  *play_buffer = AllocateMemory(buffer_size)
 
  Repeat
    err = mpg123_read(*mpg123_handle, *play_buffer, buffer_size, @done)
    played = out123_play(*out123_handle, *play_buffer, done)
    If played <> done
      Debug @done
    EndIf
    samples + played / framesize
    Debug samples
  Until done = #MPG123_OK And err = #MPG123_DONE
 
  FreeMemory(*play_buffer)
 
  ;   ;Rohdaten schreiben !
  ;   *ptr_buffer_memory = *buffer_memory
  ;   bytes_read = 0
  ;   remaining = bytes_memory
  ;   While 1
  ;     delta = buffer_size
  ;     remaining = bytes_memory - bytes_read
  ;     If remaining <= 0
  ;       Break
  ;     EndIf
  ;     If delta > remaining
  ;       delta = remaining
  ;     EndIf
  ;     
  ;     err = mpg123_read(*mpg123_handle, *ptr_buffer_memory, delta, @done)
  ;     
  ;     If err <> #MPG123_OK
  ;       Break
  ;     EndIf   
  ;     *ptr_buffer_memory + done
  ;     bytes_read + done
  ;     remaining - delta
  ;   Wend
  ;   
  ;   If bytes_read <> bytes_memory
  ;     Debug "num_samples done <> num_samples to read !"
  ;   EndIf
  ;   
  ;   If err <> #MPG123_DONE
  ;     If err = #MPG123_ERR
  ;       DBG(PeekS(mpg123_strerror(*mpg123_handle), -1, #PB_Ascii))
  ;     Else
  ;       DBG(PeekS(mpg123_plain_strerror(err), -1, #PB_Ascii))
  ;     EndIf
  ;   EndIf
  ;   
  ;   ;Eine decodiere Mp3-Datei als RAW-Audio-Datei (Kann man z.B. mit Audacity (über Import) öffnen.)
  ;   If CreateFile(0, "test.raw")
  ;     WriteData(0, *buffer_memory, bytes_memory)
  ;     CloseFile(0)
  ;   EndIf
  ;   
  out123_del(*out123_handle)
  mpg123_close(*mpg123_handle)
  mpg123_delete(*mpg123_handle)
  mpg123_exit()
EndProcedure


Mp3_To_MemoryPlay(MP3_FILENAME)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Wie kann man libout123 benutzen ?
BeitragVerfasst: 08.04.2018 10:52 
Offline
Moderator
Benutzeravatar

Registriert: 05.10.2006 18:55
Wohnort: Rupture Farms
Leider konnte ich dir nicht helfen, aber schön, dass du das Problem selber lösen konntest. :allright:

_________________
BildBildBildBild
Bild | EnableExplicit ist kostenlos und vermeidet Fehler | Gib Goto keine Chance | Schneller als die Telekom erlaubt | Avira? Nein Danke
WinAPI forever | Bei Problemen bitte Beispielcode posten | Mit Adblock werbefrei, schneller und sicherer surfen | brain.exe ist der beste Schutz | Userlibrary ohne Source = NoGo


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 

Alle Zeiten sind UTC + 1 Stunde [ Sommerzeit ]


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 3 Gäste


Sie dürfen keine neuen Themen in diesem Forum erstellen.
Sie dürfen keine Antworten zu Themen in diesem Forum erstellen.
Sie dürfen Ihre Beiträge in diesem Forum nicht ändern.
Sie dürfen Ihre Beiträge in diesem Forum nicht löschen.

Suche nach:
Gehe zu:  

 


Powered by phpBB © 2008 phpBB Group | Deutsche Übersetzung durch phpBB.de
subSilver+ theme by Canver Software, sponsor Sanal Modifiye