|
|
(7 versioni intermedie di uno stesso utente non sono mostrate) |
Riga 1: |
Riga 1: |
− | Mostriamo di seguito il codice per di un semplice applicativo ''a riga di comando'' per la riproduzione di file Midi.
| + | * [[Eseguire un file MIDI mediante le funzioni esterne del API di Fluidsynth]] |
| | | |
− | E' necessario avere installata e richiamare in Gambas la libreria condivisa: "libfluidsynth.so.2.3.1"
| + | * [[Ottenere un file WAV da un file Midi con le funzioni esterne del API di FluidSynth]] |
− | | |
− | Bisogna anche avere installato il programma ''Jackd''.
| |
− | <BR>Una volta lanciato l'applicativo, aprire ''Jackd'' e nella parte "''Audio''" della finestra "''Connessioni''" connettere il dispositivo "''Fluidsynth''", presente nella colonna "''Clients leggibili/Porte d'uscita''", al dispositivo "''system''" presente nella colonna "''Clients scrivibili/Porte d'entrata''".
| |
− | | |
− | Si dovrà, inoltre, individuare un file ''soundfont bank'' con estensione <FONT color=#B22222>.sf2</font>, da far caricare successivamente dalla funzione esterna "''fluid_synth_sfload''" per poter ottenere i suoni.
| |
− | Library "libfluidsynth:2.3.1"
| |
− |
| |
− | <FONT color=gray>' ''fluid_settings_t* new_fluid_settings(void)''
| |
− | ' ''Create a new settings object. ''</font>
| |
− | Private Extern new_fluid_settings() As Pointer
| |
− |
| |
− | <FONT color=gray>' ''fluid_synth_t * new_fluid_synth (fluid_settings_t *settings)''
| |
− | ' ''Create new FluidSynth instance.''</font>
| |
− | Private Extern new_fluid_synth(settings As Pointer) As Pointer
| |
− |
| |
− | <FONT color=gray>' ''fluid_player_t* new_fluid_player(fluid_synth_t * synth)''
| |
− | ' ''Create a new MIDI player.''</font>
| |
− | Private Extern new_fluid_player(synth As Pointer) As Pointer
| |
− |
| |
− | <FONT color=gray>' ''fluid_audio_driver_t* new_fluid_audio_driver(fluid_settings_t * settings, fluid_synth_t * synth)''
| |
− | ' ''Create a new audio driver.''</font>
| |
− | Private Extern new_fluid_audio_driver(settings As Pointer, synth As Pointer) As Pointer
| |
− |
| |
− | <FONT color=gray>' ''int fluid_is_soundfont(const char * filename)''
| |
− | ' ''Check if a file is a SoundFont file.''</font>
| |
− | Private Extern fluid_is_soundfont(filename As String) As Integer
| |
− |
| |
− | <FONT color=gray>' ''int fluid_synth_sfload(fluid_synth_t * synth, const char * filename, nt reset_presets)''
| |
− | ' ''Load a SoundFont file (filename is interpreted by SoundFont loaders).''</font>
| |
− | Private Extern fluid_synth_sfload(synth As Pointer, filename As String, reset_presets As Integer) As Integer
| |
− |
| |
− | <FONT color=gray>' ''int fluid_is_midifile(const char * filename)''
| |
− | ' ''Check if a file is a MIDI file.''</font>
| |
− | Private Extern fluid_is_midifile(filename As String) As Integer
| |
− |
| |
− | <FONT color=gray>' ''int fluid_player_add(fluid_player_t * player, Const char * midifile)
| |
− | ' ''Add a MIDI file to a player queue.''</font>
| |
− | Private Extern fluid_player_add(player As Pointer, midifile As String) As Integer
| |
− |
| |
− | <FONT color=gray>' ''int fluid_player_play(fluid_player_t * player)''
| |
− | ' ''Activates play mode for a MIDI player if not already playing.''</font>
| |
− | Private Extern fluid_player_play(player As Pointer) As Integer
| |
− |
| |
− | <FONT color=gray>' ''int fluid_player_get_status(fluid_player_t * player)''
| |
− | ' ''Get MIDI player status.''</font>
| |
− | Private Extern fluid_player_get_status(player As Pointer) As Integer
| |
− |
| |
− | <FONT color=gray>' ''void delete_fluid_audio_driver(fluid_audio_driver_t * driver)''
| |
− | ' ''Deletes an audio driver instance.''</font>
| |
− | Private Extern delete_fluid_audio_driver(driver As Pointer)
| |
− |
| |
− | <FONT color=gray>' ''int delete_fluid_player(fluid_player_t * player)''
| |
− | ' ''Delete a MIDI player instance.''</font>
| |
− | Private Extern delete_fluid_player(player As Pointer) As Integer
| |
− |
| |
− | <FONT color=gray>' ''int delete_fluid_synth(fluid_synth_t * synth)''
| |
− | ' ''Delete a FluidSynth instance.''</font>
| |
− | Private Extern delete_fluid_synth(synth As Pointer) As Integer
| |
− |
| |
− | <FONT color=gray>' ''void delete_fluid_settings(fluid_settings_t * settings)''
| |
− | ' ''Delete the provided settings object.''</font>
| |
− | Private Extern delete_fluid_settings(settings As Pointer)
| |
− |
| |
− |
| |
− | '''Public''' Sub Main()
| |
− |
| |
− | Dim set, syn, pla, drv As Pointer
| |
− | Dim filesbk, fileMidi As String
| |
− | Dim tempus As Date
| |
− |
| |
− | set = new_fluid_settings()
| |
− | If set == 0 Then Error.Raise("Errore !")
| |
− |
| |
− | syn = new_fluid_synth(set)
| |
− | If syn == 0 Then Error.Raise("Errore !")
| |
− |
| |
− | pla = new_fluid_player(syn)
| |
− | If pla == 0 Then Error.Raise("Errore !")
| |
− |
| |
− | <FONT color=gray>' ''Carica il soundfont bank per i suoni:''</font>
| |
− | filesbk = "<FONT color=gray>''/percorso/del/file/soundfont.sf2''</font>"
| |
− | If Not fluid_is_soundfont(filesbk) Then Error.Raise("Il file non è un soundfont bank !")
| |
− | If fluid_synth_sfload(syn, filesbk, 1) < 0 Then Error.Raise("Errore !")
| |
− |
| |
− | <FONT color=gray>' ''Carica il file Midi prescelto:''</font>
| |
− | fileMidi = "<FONT color=gray>''/percorso/del/file.mid''</font>"
| |
− | If fluid_is_midifile(fileMidi) < 0 Then Error.Raise("Il file non è un file 'Midi' !")
| |
− | If fluid_player_add(pla, fileMidi) < 0 Then Error.Raise("Errore !")
| |
− |
| |
− | drv = new_fluid_audio_driver(set, syn)
| |
− | If drv == 0 Then Error.Raise("Impossibile creare un driver audio !")
| |
− |
| |
− | <FONT color=gray>' ''Avvia l'esecuzione del file Midi:''</font>
| |
− | If fluid_player_play(pla) < 0 Then Error.Raise("Errore !")
| |
− | Print
| |
− | tempus = Now
| |
− |
| |
− | While fluid_player_get_status(pla) == FLUID_PLAYER_PLAYING
| |
− | Write "\r\e[0mFile Midi: " & fileMidi & " - \e[31m" & CStr(Date(0, 0, 0, 0, 0, 0, DateDiff(tempus, Now, gb.Millisecond)))
| |
− | Wait 0.01
| |
− | Wend
| |
− |
| |
− | <FONT color=gray>' ''Libera la memoria precedentemente occupata e chiude il programma:''</font>
| |
− | delete_fluid_audio_driver(drv)
| |
− | delete_fluid_player(pla)
| |
− | delete_fluid_synth(syn)
| |
− | delete_fluid_settings(set)
| |
− |
| |
− | Print "\nEsecuzione terminata !"
| |
− |
| |
− | '''End'''
| |
− | | |
− | | |
− | | |
− | | |
− | =Riferimenti=
| |
− | * http://www.fluidsynth.org/
| |
− | * http://www.fluidsynth.org/api/index.html
| |