Aktuelle Zeit: 20.10.2020 14:13

Alle Zeiten sind UTC + 1 Stunde [ Sommerzeit ]




Ein neues Thema erstellen Auf das Thema antworten  [ 5 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)

_________________
Betriebssysteme: MX Linux 19 / Windows 10 / Mac OS 10.15.2 / Android 7.0 ;)


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)

_________________
Betriebssysteme: MX Linux 19 / Windows 10 / Mac OS 10.15.2 / Android 7.0 ;)


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

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

_________________
BildBildBildBild BildBild


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Wie kann man libmpg123 benutzen ?
BeitragVerfasst: 04.10.2020 12:47 
Offline

Registriert: 27.11.2016 18:13
Wohnort: Erzgebirge
Hallo Leute,

ich will mal wieder was mit der mpg123 - Bibliothek machen.

Hat jemand Ahnung wie ich damit den id3-Tag von Mp3-Dateien auslesen kann ?

Code:
;sudo apt-get install libmpg123-dev libao-dev

;https://en.wikipedia.org/wiki/Mpg123
;https://www.mpg123.org/

;x64

#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)

Global MP3_FILENAME.s = GetCurrentDirectory()+"funny.mp3"

Structure ao_device Align #PB_Structure_AlignC
  type.i
  driver_id.i
  *funcs
  *file
  client_byte_format.i
  machine_byte_format.i
  driver_byte_format.i
  *swap_buffer
  swap_buffer_size.i
  *internal
EndStructure

Structure ao_sample_format Align #PB_Structure_AlignC
  bits.l
  rate.l
  channels.l
  byte_format.l
  *matrix
EndStructure

Structure ao_option
  *key
  *value
  *next.ao_option
EndStructure

;mpg123-Structures
 
Structure mpg123_string Align #PB_Structure_AlignC
  *p
  size.i
  fill.i
EndStructure

Structure mpg123_text Align #PB_Structure_AlignC
  lang.b[3]
  id.b[4]
  description.mpg123_string
  text.mpg123_string
EndStructure

Enumeration mpg123_state
  #MPG123_ACCURATE = 1
  #MPG123_BUFFERFILL
  #MPG123_FRANKENSTEIN
  #MPG123_FRESH_DECODER
  #MPG123_ENC_DELAY
  #MPG123_ENC_PADDING
  #MPG123_DEC_DELAY
EndEnumeration

Enumeration mpg123_text_encoding
  #mpg123_text_unknown = 0
  #mpg123_text_utf8 = 1
  #mpg123_text_latin1 = 2
  #mpg123_text_icy = 3
  #mpg123_text_cp1252 = 4
  #mpg123_text_utf16 = 5
  #mpg123_text_utf16bom = 6
  #mpg123_text_utf16be = 7
  #mpg123_text_max = 7
EndEnumeration

Enumeration mpg123_id3_enc
  #mpg123_id3_latin1 = 0
  #mpg123_id3_utf16bom = 1
  #mpg123_id3_utf16be = 2
  #mpg123_id3_utf8 = 3
  #mpg123_id3_enc_max = 3
EndEnumeration

Structure mpg123_picture Align #PB_Structure_AlignC
  type.c
  description.mpg123_string
  mime_type.mpg123_string
  size.i
  datas.i
EndStructure

Structure mpg123_id3v2 Align #PB_Structure_AlignC
  version.b
  *title.mpg123_string
  *artist.mpg123_string
  *album.mpg123_string
  *year.mpg123_string
  *genre.mpg123_string
  *comment.mpg123_string
  *comment_list.mpg123_text
  comments.i
  *text.mpg123_text
  texts.i
  *extra.mpg123_text
  extras.i
  *picture.mpg123_picture
  pictures.i
EndStructure

Structure mpg123_id3v1 Align #PB_Structure_AlignC
  tag.c[3]
  title.c[30]
  artist.c[30]
  album.c[30]
  year.c[4]
  comment.c[30]
  genre.c
EndStructure


ImportC "-lmpg123";"libmpg123.so.0"
  mpg123_init()
  mpg123_new(*decoder, *error)
  mpg123_open(*mh, *path.p-utf8)
  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)
  mpg123_encsize(encoding.i)
  mpg123_tell(*mh)
  mpg123_tellframe(*mh)
  mpg123_tell_stream(*mh)
  mpg123_seek(*mh, sampleoff.i, whence.l)
  mpg123_feedseek(*mh, sampleoff.i, whence.l, *input_offset)
  mpg123_seek_frame(*mh, frameoff.i, whence.l)
  mpg123_getstate(*mh, key.i, *val, *fval)
  mpg123_scan(*mh)
  mpg123_framelength(*mh)
  mpg123_tpf.d(*mh) ;Get MPEG frame duration in seconds.
  mpg123_spf(*mh) ;Get MPEG frame duration in samples.
  mpg123_param(*mh, type.i, value.l, fvalue.d)
  ;mpg123_id3(*mh, *v1.mpg123_id3v1, *v2.mpg123_id3v2)
  mpg123_id3(*mh, *v1, *v2)
  mpg123_store_utf8(*sb.mpg123_string, enc.i, *source, source_size.i)
  mpg123_meta_check(*mh)
  mpg123_meta_free(*mh)
EndImport

Import "-lao"
  ao_initialize()
  ao_default_driver_id()
  ao_open_live(driver_id.i, *format.ao_sample_format, *options.ao_option)
  ao_play(*device.ao_device, *output_samples, num_bytes.i)
  ao_close(*device.ao_device)
  ao_shutdown()
EndImport

#BITS = 8

#AO_FMT_LITTLE = 1
#AO_FMT_BIG = 2
#AO_FMT_NATIVE = 4

Procedure GetMp3File()
  MP3_FILENAME = OpenFileRequester("Mp3-Datei wählen", "*.mp3", "*.mp3", 0)
EndProcedure

Procedure start(*id)
  Protected *mh, *buffer, buffer_size.i, done.i, err.i
  Protected driver.i, *dev.ao_device, format.ao_sample_format
  Protected channels.l, encoding.l, rate.l
  Protected meta.i
  Protected *v1.mpg123_id3v1, *v2.mpg123_id3v2
 
  ;Debug SizeOf(mpg123_id3v2)

  ao_initialize()
  driver = ao_default_driver_id()
 
  mpg123_init()
  *mh = mpg123_new(#Null, @err)
  buffer_size = mpg123_outblock(*mh)
  *buffer = AllocateMemory(buffer_size * SizeOf(Word))
 
  mpg123_open(*mh, UTF8(MP3_FILENAME))
 
  mpg123_scan(*mh)
  meta = mpg123_meta_check(*mh)
  If (meta And mpg123_id3(*mh, *v1, *v2)) = #MPG123_OK
    Debug "Wie komme ich an den id3-tag ?"
  EndIf
 
  mpg123_getformat(*mh, @rate, @channels, @encoding)
 
  format\bits = mpg123_encsize(encoding) * #BITS
  format\rate = rate
  format\channels = channels
  format\byte_format = #AO_FMT_NATIVE
  format\matrix = 0
  *dev = ao_open_live(driver, @format, #Null)
 

  While (mpg123_read(*mh, *buffer, buffer_size, @done) = #MPG123_OK)
    ao_play(*dev, *buffer, done)
  Wend
 
  ;Clean
  FreeMemory(*buffer)
  ao_close(*dev)
  mpg123_close(*mh)
  mpg123_delete(*mh)
  mpg123_exit()
  ao_shutdown()
 
EndProcedure

Global Thread

GetMp3File()
Thread = CreateThread(@start(), 0)
While IsThread(Thread)
Wend


_________________
Betriebssysteme: MX Linux 19 / Windows 10 / Mac OS 10.15.2 / Android 7.0 ;)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Wie kann man libout123 benutzen ?
BeitragVerfasst: 04.10.2020 15:46 
Offline

Registriert: 27.11.2016 18:13
Wohnort: Erzgebirge
Ich habe die Lösung:

Code:
;sudo apt-get install libmpg123-dev libao-dev

;https://en.wikipedia.org/wiki/Mpg123
;https://www.mpg123.org/

;x64

#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)

#MPG123_ID3 = $3

Global MP3_FILENAME.s = GetCurrentDirectory()+"funny.mp3"

Structure ao_device Align #PB_Structure_AlignC
  type.i
  driver_id.i
  *funcs
  *file
  client_byte_format.i
  machine_byte_format.i
  driver_byte_format.i
  *swap_buffer
  swap_buffer_size.i
  *internal
EndStructure

Structure ao_sample_format Align #PB_Structure_AlignC
  bits.l
  rate.l
  channels.l
  byte_format.l
  *matrix
EndStructure

Structure ao_option Align #PB_Structure_AlignC
  *key
  *value
  *next.ao_option
EndStructure

;mpg123-Structures

Structure Char
  z.b
EndStructure
 
Structure mpg123_string Align #PB_Structure_AlignC
  *p.Char
  size.i
  fill.i
EndStructure

Structure mpg123_text Align #PB_Structure_AlignC
  lang.b[3]
  id.b[4]
  description.mpg123_string
  text.mpg123_string
EndStructure

Enumeration mpg123_state
  #MPG123_ACCURATE = 1
  #MPG123_BUFFERFILL
  #MPG123_FRANKENSTEIN
  #MPG123_FRESH_DECODER
  #MPG123_ENC_DELAY
  #MPG123_ENC_PADDING
  #MPG123_DEC_DELAY
EndEnumeration

Enumeration mpg123_text_encoding
  #mpg123_text_unknown = 0
  #mpg123_text_utf8 = 1
  #mpg123_text_latin1 = 2
  #mpg123_text_icy = 3
  #mpg123_text_cp1252 = 4
  #mpg123_text_utf16 = 5
  #mpg123_text_utf16bom = 6
  #mpg123_text_utf16be = 7
  #mpg123_text_max = 7
EndEnumeration

Enumeration mpg123_id3_enc
  #mpg123_id3_latin1 = 0
  #mpg123_id3_utf16bom = 1
  #mpg123_id3_utf16be = 2
  #mpg123_id3_utf8 = 3
  #mpg123_id3_enc_max = 3
EndEnumeration

Structure mpg123_picture Align #PB_Structure_AlignC
  type.c
  description.mpg123_string
  mime_type.mpg123_string
  size.i
  *data
EndStructure

Structure mpg123_id3v2 Align #PB_Structure_AlignC
  version.c
  *title.mpg123_string
  *artist.mpg123_string
  *album.mpg123_string
  *year.mpg123_string
  *genre.mpg123_string
  *comment.mpg123_string
  *comment_list.mpg123_text
  comments.i
  *text.mpg123_text
  texts.i
  *extra.mpg123_text
  extras.i
  *picture.mpg123_picture
  pictures.i
EndStructure

Structure mpg123_id3v1 Align #PB_Structure_AlignC
  tag.b[3]
  title.b[30]
  artist.b[30]
  album.b[30]
  year.b[4]
  comment.b[30]
  genre.b
EndStructure


ImportC "-lmpg123";"libmpg123.so.0"
  mpg123_init()
  mpg123_new(*decoder, *error)
  mpg123_open(*mh, *path.p-utf8)
  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.l, *outmemory, outmemsize.l, *done)
  mpg123_close(*mh)
  mpg123_delete(*mp)
  mpg123_exit()
  mpg123_length(*mh)
  mpg123_encsize(encoding.i)
  mpg123_tell(*mh)
  mpg123_tellframe(*mh)
  mpg123_tell_stream(*mh)
  mpg123_seek(*mh, sampleoff.i, whence.l)
  mpg123_feedseek(*mh, sampleoff.i, whence.l, *input_offset)
  mpg123_seek_frame(*mh, frameoff.i, whence.l)
  mpg123_getstate(*mh, key.i, *val, *fval)
  mpg123_scan(*mh)
  mpg123_framelength(*mh)
  mpg123_tpf.d(*mh) ;Get MPEG frame duration in seconds.
  mpg123_spf(*mh) ;Get MPEG frame duration in samples.
  mpg123_param(*mh, type.i, value.l, fvalue.d)
  mpg123_id3(*mh, *v1.mpg123_id3v1, *v2.mpg123_id3v2)
  ;mpg123_id3(*mh, *v1, *v2)
  mpg123_store_utf8(*sb.mpg123_string, enc.i, *source, source_size.i)
  mpg123_meta_check(*mh)
  mpg123_meta_free(*mh)
EndImport

Import "-lao"
  ao_initialize()
  ao_default_driver_id()
  ao_open_live(driver_id.i, *format.ao_sample_format, *options.ao_option)
  ao_play(*device.ao_device, *output_samples, num_bytes.i)
  ao_close(*device.ao_device)
  ao_shutdown()
EndImport

#BITS = 8

#AO_FMT_LITTLE = 1
#AO_FMT_BIG = 2
#AO_FMT_NATIVE = 4

Procedure GetMp3File()
  MP3_FILENAME = OpenFileRequester("Mp3-Datei wählen", "*.mp3", "*.mp3", 0)
EndProcedure

Procedure start(*id)
  Protected *mh, *buffer, buffer_size.i, done.i, err.i
  Protected driver.i, *dev.ao_device, format.ao_sample_format
  Protected channels.l, encoding.l, rate.l
  Protected meta.i
 
  *v1.mpg123_id3v1 = AllocateStructure(mpg123_id3v1)
  *v2.mpg123_id3v2 = AllocateStructure(mpg123_id3v2)

  ao_initialize()
  driver = ao_default_driver_id()
 
  mpg123_init()
  *mh = mpg123_new(#Null, @err)
  buffer_size = mpg123_outblock(*mh)
  *buffer = AllocateMemory(buffer_size * SizeOf(Word))
 
  mpg123_open(*mh, UTF8(MP3_FILENAME))
 
  mpg123_scan(*mh)
  meta = mpg123_meta_check(*mh)
 
  ;Painful double pointer
  If (meta And #MPG123_ID3 And mpg123_id3(*mh, @*v1, @*v2)) = #MPG123_OK
    Debug "ID3v2-Tag:"
    Debug "Title: " + PeekS(*v2\title\p, *v2\title\size, #PB_UTF8)
    Debug "Artist: " + PeekS(*v2\artist\p, *v2\artist\size, #PB_UTF8)
  EndIf
 
  mpg123_getformat(*mh, @rate, @channels, @encoding)
 
  format\bits = mpg123_encsize(encoding) * #BITS
  format\rate = rate
  format\channels = channels
  format\byte_format = #AO_FMT_NATIVE
  format\matrix = 0
  *dev = ao_open_live(driver, @format, #Null)
 
  While (mpg123_read(*mh, *buffer, buffer_size, @done) = #MPG123_OK)
    ao_play(*dev, *buffer, done)
  Wend
 
  ;Clean
  FreeMemory(*buffer)
  ao_close(*dev)
  mpg123_close(*mh)
  mpg123_delete(*mh)
  mpg123_exit()
  ao_shutdown()
 
EndProcedure

Global Thread

GetMp3File()
Thread = CreateThread(@start(), 0)
While IsThread(Thread)
Wend

_________________
Betriebssysteme: MX Linux 19 / Windows 10 / Mac OS 10.15.2 / Android 7.0 ;)


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

Alle Zeiten sind UTC + 1 Stunde [ Sommerzeit ]


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 2 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