Differenze tra le versioni di "Ottenere un file audio da un file Midi con le funzioni esterne del API di VLC"
Da Gambas-it.org - Wikipedia.
Riga 5: | Riga 5: | ||
Mostriamo un esempio pratico in ambiente grafico, in cui da un file Midi si otterrà un file audio di formato ''wav'': | Mostriamo un esempio pratico in ambiente grafico, in cui da un file Midi si otterrà un file audio di formato ''wav'': | ||
− | + | Library "libvlc:5.4.0" | |
− | + | Private Enum libvlc_NothingSpecial = 0, | |
− | + | libvlc_Opening, | |
+ | libvlc_Buffering, | ||
+ | libvlc_Playing, | ||
+ | libvlc_Paused, | ||
+ | libvlc_Stopped, | ||
+ | libvlc_Ended, | ||
+ | libvlc_Error | ||
<FONT Color=gray>' ''libvlc_instance_t * libvlc_new (int argc, const char *const *argv)'' | <FONT Color=gray>' ''libvlc_instance_t * libvlc_new (int argc, const char *const *argv)'' | ||
Riga 29: | Riga 35: | ||
' ''Play the video file.''</font> | ' ''Play the video file.''</font> | ||
Private Extern libvlc_media_player_play(p_mi As Pointer) As Integer | Private Extern libvlc_media_player_play(p_mi As Pointer) As Integer | ||
+ | |||
+ | <FONT color=gray>' ''libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)'' | ||
+ | ' ''Get current movie state.''</font> | ||
+ | Private Extern libvlc_media_player_get_state(p_mi As Pointer) As Integer | ||
<FONT Color=gray>' ''libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)'' | <FONT Color=gray>' ''libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)'' | ||
' ''Get the current movie time (in ms).''</font> | ' ''Get the current movie time (in ms).''</font> | ||
Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Integer | Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Integer | ||
+ | |||
+ | <FONT color=gray>' ''void libvlc_media_player_release (libvlc_media_player_t * p_mi)'' | ||
+ | ' ''Release a media_player after use Decrement the reference count of a media player object.''</font> | ||
+ | Private Extern libvlc_media_player_release(p_mi As Pointer) | ||
<FONT Color=gray>' ''libvlc_release (libvlc_instance_t * p_instance)'' | <FONT Color=gray>' ''libvlc_release (libvlc_instance_t * p_instance)'' | ||
' ''Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.''</font> | ' ''Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.''</font> | ||
Private Extern libvlc_release(p_instance As Pointer) | Private Extern libvlc_release(p_instance As Pointer) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | '''Public''' Sub Main() | |
− | '''Public''' Sub | ||
Dim inst, mp, m As Pointer | Dim inst, mp, m As Pointer | ||
Riga 72: | Riga 79: | ||
<FONT Color=gray>' ''Avvia la realizzazione del file audio da parte del media player:''</font> | <FONT Color=gray>' ''Avvia la realizzazione del file audio da parte del media player:''</font> | ||
libvlc_media_player_play(mp) | libvlc_media_player_play(mp) | ||
− | + | ||
− | While | + | While libvlc_media_player_get_state(mp) < libvlc_Stopped |
− | + | Write #File.Out, Str(Date(0, 0, 0, 0, 0, 0, libvlc_media_player_get_time(mp))) & "\r" | |
− | |||
− | |||
Wend | Wend | ||
− | <FONT Color=gray>' ''Chiude la libreria VLC ed il programma:''</font> | + | <FONT Color=gray>' ''Chiude il media player, la libreria VLC ed il programma:''</font> |
+ | libvlc_media_player_release(mp) | ||
libvlc_release(inst) | libvlc_release(inst) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
'''End''' | '''End''' | ||
+ | |||
Versione delle 07:13, 8 mag 2016
La libreria VLC consente di poter ottenere un file audio da un file Midi.
E' necessario aver installata nel proprio sistema la risorsa FluidSynth, nonché anche richiamare in Gambas la libreria dinamica condivisa: "libvlc.so.5.4.0"
Mostriamo un esempio pratico in ambiente grafico, in cui da un file Midi si otterrà un file audio di formato wav:
Library "libvlc:5.4.0" Private Enum libvlc_NothingSpecial = 0, libvlc_Opening, libvlc_Buffering, libvlc_Playing, libvlc_Paused, libvlc_Stopped, libvlc_Ended, libvlc_Error ' libvlc_instance_t * libvlc_new (int argc, const char *const *argv) ' Create And initialize a libvlc instance. Private Extern libvlc_new(argc As Integer, argv As String[]) As Pointer ' libvlc_media_t *libvlc_media_new_path(libvlc_instance_t *p_instance, const char * path) ' Create a media for a certain file path. Private Extern libvlc_media_new_path(p_instance As Pointer, path As String) As Pointer ' libvlc_media_player_t * libvlc_media_player_new(libvlc_instance_t *p_libvlc_instance) ' Create an empty Media Player object. Private Extern libvlc_media_player_new(p_libvlc_instance As Pointer) As Pointer ' void libvlc_media_player_set_media(libvlc_media_player_t *p_mi, libvlc_media_t *p_md) ' Set the media that will be used by the media_player. Private Extern libvlc_media_player_set_media(p_md As Pointer, mp As Pointer) ' int libvlc_media_player_play (libvlc_media_player_t * p_mi) ' Play the video file. Private Extern libvlc_media_player_play(p_mi As Pointer) As Integer ' libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi) ' Get current movie state. Private Extern libvlc_media_player_get_state(p_mi As Pointer) As Integer ' libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi) ' Get the current movie time (in ms). Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Integer ' void libvlc_media_player_release (libvlc_media_player_t * p_mi) ' Release a media_player after use Decrement the reference count of a media player object. Private Extern libvlc_media_player_release(p_mi As Pointer) ' libvlc_release (libvlc_instance_t * p_instance) ' Decrement the reference count of a libvlc instance, and destroy it if it reaches zero. Private Extern libvlc_release(p_instance As Pointer) Public Sub Main() Dim inst, mp, m As Pointer Dim ss As String[] Dim argc as Integer ' Vengono impostate le opzioni ed il percorso ove sarà salvato il file audio wav: ss = ["--sout=#transcode{acodec=s16l,ab=128,samplerate=44100, channels=2}:standard{access-file,mux=wav,dst=/tmp/audio.wav}"] ' Imposta il valore del 1° argomento della funzione "libvlc_new()": argc = 1 ' Inizializza la libreria VLC: inst = libvlc_new(argc, ss) ' Crea il media player: mp = libvlc_media_player_new(inst) ' Crea un nuovo oggetto multimedia. ' Nel secondo argomento della funzione va specificato il percorso del file Midi da cui ottenere il file audio wav: m = libvlc_media_new_path(inst, "/percorso/del/file.mid") libvlc_media_player_set_media(mp, m) ' Avvia la realizzazione del file audio da parte del media player: libvlc_media_player_play(mp) While libvlc_media_player_get_state(mp) < libvlc_Stopped Write #File.Out, Str(Date(0, 0, 0, 0, 0, 0, libvlc_media_player_get_time(mp))) & "\r" Wend ' Chiude il media player, la libreria VLC ed il programma: libvlc_media_player_release(mp) libvlc_release(inst) End
Indice
Ottenere altri formati di file audio
Oltre al formato WAV è possibile ottenere qualche altro formato di file audio.
Formato audio MP3
Per ottenere un file audio di formato mp3, è necessario sostituire la stringa delle opzioni con la seguente:
ss = ["--sout=#transcode{acodec=mp3,ab=128,samplerate=44100, channels=2}:standard{access-file,mux=raw,dst=/tmp/audio.mp3}"]
Formato audio OggVorbis
Per ottenere un file audio di formato OggVorbis, è necessario sostituire la stringa delle opzioni con la seguente:
ss = ["--sout=#transcode{acodec=vorb,ab=96,channels=2}:standard{access-file,mux=ogg,dst=/tmp/audio.ogg}"]