Eseguire un file mp3 usando le API di mpg123 e di Alsa

Da Gambas-it.org - Wikipedia.
Versione del 26 lug 2013 alle 10:29 di Vuott (Discussione | contributi) (Creata pagina con 'E' possibile utilizzare in un medesimo applicativo le funzioni esterne dell'[http://it.wikipedia.org/wiki/Application_programming_interface API] di '''''[http://www.mpg123.de ...')

(diff) ← Versione meno recente | Versione attuale (diff) | Versione più recente → (diff)

E' possibile utilizzare in un medesimo applicativo le funzioni esterne dell'API di mpg123 unitamente a quelle di Alsa.
Le funzioni di mpg123 effettueranno la decodifica del file mp3 ed l'assegnazione dei dati ad un buffer. Tale buffer sarà, poi, passato all'apposita funzione esterna di Alsa per la scrittura dei dati nel suo sub-sistema PCM.


Vediamo, di seguito, un semplice esempio di quanto detto. Distingueremo le funzioni e la parte attinenti alla libreria mpg123 colorandole di blu-marino e quelle alla libreria Alsa colorandole di marrone:

Public Struct SF_INFO
 frames As Long
 samplerate As Integer
 channels As Integer
 formatI As Integer
 sections As Integer
 seekable As Integer
End Struct

Private Const MPG123_OK As Byte = 0
Private Const MPG123_ADD_FLAGS As Byte = 2
Private Const MPG123_FORCE_FLOAT As Short = 1024
Private Const MPG123_ENC_SIGNED_16 As Byte = 208

Library "libmpg123:0.36.6"

' int mpg123_init (void)  --> Function to initialise the mpg123 library.
Private Extern mpg123_init() As Integer

' const char* mpg123_plain_strerror   (int errcode)  --> Return a string describing that error errcode means.
Private Extern mpg123_plain_strerror(errcode As Integer) As String

' mpg123_handle *, mpg123_new (const char *decoder, int *error)  --> Create a handle with optional choice of decoder (named by a string)
Private Extern mpg123_new(decoder As String, errorI As Integer) As Pointer

' int mpg123_param   (mpg123_handle * mh, Enum mpg123_parms type, long value, double fvalue)
' --> Set a specific parameter, For a specific mpg123_handle, using a parameter type key chosen From the mpg123_parms enumeration, To the specified value.
Private Extern mpg123_param(mhP As Pointer, type As Integer, valueL As Long, fvalue As Float) As Integer

' int mpg123_open   (mpg123_handle * mh, const char * path)  --> Open and prepare to decode the specified file by filesystem path. This does not open HTTP urls.
Private Extern mpg123_open(mhP As Pointer, pathFile As String) As Integer

' const char* mpg123_strerror   (mpg123_handle * mh)  --> Give string describing what error has occured in the context of handle mh.
Private Extern mpg123_strerror(mhP As Pointer) As String

' int mpg123_getformat   (mpg123_handle * mh, long * rate, Int * channels, Int * encoding) --> Get the current output format written to the addresses given.
Private Extern mpg123_getformat(mhP As Pointer, ratP As Pointer, channP As Pointer, encodP As Pointer) As Integer

' int mpg123_format_none (mpg123_handle * mh)  --> Configure a mpg123 handle to accept no output format at all, use before specifying supported formats with mpg123_format.
Private Extern mpg123_format_none(mhP As Pointer) As Integer

' size_t mpg123_outblock   (mpg123_handle * mh)  --> The max size of one frame's decoded output with current settings.
' Use that to determine an appropriate minimum buffer size for decoding one frame.
Private Extern mpg123_outblock(mhP As Pointer) As Integer

' int mpg123_read   (mpg123_handle * mh, unsigned char * outmemory, size_t outmemsize, size_t * done) --> Read from stream and decode up to outmemsize bytes.
Private Extern mpg123_read(mhP As Pointer, outmemory As Pointer, outmemsize As Integer, done As Pointer) As Integer



Public Sub Form_Open()

End


Public Sub Button1_Click()
 
Dim err, channels, encoding, buffer_size, frames As Integer
Dim rate As Long
Dim mh, buffer, handle As Pointer


 




End


Pagina in costruzione !