Estrarre informazioni generali da un file audio flac

Da Gambas-it.org - Wikipedia.

Nel blocco chiamato METADATA_BLOCK_STREAMINFO di un file di formato FLAC sono contenute alcune informazioni di carattere generali del file medesimo che possono ovviamente essere estratte.


Struttura generale del file FLAC

Estrarre le informazioni mediante le sole risorse di Gambas

Estrarre le informazioni mediante le funzioni esterne di Libflac

Library "libFLAC:8.3.0"

Private Const FLAC__STREAM_DECODER_INIT_STATUS_OK As Integer = 0

' FLAC__StreamDecoder *FLAC__stream_decoder_new(void) ' Create a new stream decoder instance. Private Extern FLAC__stream_decoder_new() As Pointer

' FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(FLAC__StreamDecoder *decoder, const char *filename, FLAC__StreamDecoderWriteCallback write_callback, FLAC__StreamDecoderMetadataCallback metadata_callback, FLAC__StreamDecoderErrorCallback error_callback, void *client_data) ' Initialize the decoder instance to decode native FLAC files. Private Extern FLAC__stream_decoder_init_file(decoder As Pointer, filename As String, write_callback As Pointer, metadata_callback As Pointer, error_callback As Pointer, client_data As Pointer) As Integer

' FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder) ' Decode until the end of the stream. Private Extern FLAC__stream_decoder_process_until_end_of_stream(decoder As Pointer) As Boolean

' unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder) ' Get the current sample rate in Hz of the stream being decoded. Private Extern FLAC__stream_decoder_get_sample_rate(decoder As Pointer) As Integer

' unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder) ' Get the current number of channels in the stream being decoded. Private Extern FLAC__stream_decoder_get_channels(decoder As Pointer) As Byte

' unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder) ' Get the current sample resolution in the stream being decoded. Private Extern FLAC__stream_decoder_get_bits_per_sample(decoder As Pointer) As Byte

' FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder) ' Get the total number of samples in the stream being decoded. Private Extern FLAC__stream_decoder_get_total_samples(decoder As Pointer) As Long

' void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder) ' Free a decoder instance. Private Extern FLAC__stream_decoder_delete(decoder As Pointer)


Public Sub Main()

 Dim deco, fout As Pointer
 Dim fileFlac As String
 Dim status, frequenza As Integer
 Dim canali, bit As Byte
 Dim bo As Boolean
 Dim campioni As Long
 
   fileFlac = "/home/ploppo/Scrivania/AUDIO/stereo-44k-16bit.flac"
 
   deco = FLAC__stream_decoder_new()
   If deco = 0 Then Error.Raise("Impossibile inizializzare la libreria 'Flac' !")
   
   status = FLAC__stream_decoder_init_file(deco, fileFlac, write_callback, metadata_callback, error_callback, fout)
   If status <> FLAC__STREAM_DECODER_INIT_STATUS_OK Then Error.Raise("Impossibile inizializzare il decodificatore !")
   bo = FLAC__stream_decoder_process_until_end_of_stream(deco)
   If bo = False Then Error.Raise("Decodifica fallita !")
   
   frequenza = FLAC__stream_decoder_get_sample_rate(deco)
   Print "Frequenza:       "; frequenza; " Hertz"
   canali = FLAC__stream_decoder_get_channels(deco)
   Print "Numero canali:   "; canali
   bit = FLAC__stream_decoder_get_bits_per_sample(deco)
   Print "Risoluzione:     "; bit; "-bit"
   campioni = FLAC__stream_decoder_get_total_samples(deco)
   Print "Totale Campioni: "; campioni
   Print "Durata audio:    "; CStr(Date(0, 0, 0, 0, 0, 0, (campioni / frequenza) * 1000))
   FLAC__stream_decoder_delete(deco)

End


Private Function write_callback(decoder As Pointer, frame As Pointer, buffer As Pointer, client_data As Pointer)

End

Private Function metadata_callback(decoder As Pointer, metadata As Pointer, client_data As Pointer)

End

Private Function error_callback(decoder As Pointer, errori As Integer, client_data As Pointer)

End



Riferimenti


Pagina in costruzione !