|
|
(10 versioni intermedie di uno stesso utente non sono mostrate) |
Riga 1: |
Riga 1: |
− | Rinviamo all'analogo capitolo sulla [http://www.gambas-it.org/wiki/index.php?title=Gestione_dei_dati_media_con_GStreamer gestione delle funzioni delle API di GStreamer per l'audio]: per l'esecuzione dei file Midi si adotteranno le medesime funzioni e risorse lì descritte, precisando che è necessario aver installato il file banco di suoni di default di Timidity: "''/usr/share/sounds/sf2/<FONT color=#B22222>TimGM6mb.sf2</font>''", oppure di FluidSynth: "''/usr/share/sounds/sf2/<FONT color=#B22222>FluidR3_GM.sf2</font>''". | + | Rinviamo all'analogo capitolo sulla [http://www.gambas-it.org/wiki/index.php?title=Gestione_dei_dati_media_con_GStreamer gestione delle funzioni delle API di GStreamer per l'audio]: per l'esecuzione dei file Midi si adotteranno le medesime funzioni e risorse lì descritte, precisando che è necessario aver installato il file banco di suoni di default di Timidity "''<FONT color=#B22222>TimGM6mb.sf2</font>'' ", oppure di FluidSynth "''<FONT color=#B22222>FluidR3_GM.sf2</font>'' ". |
| | | |
| + | * [[Eseguire un file Midi mediante le funzioni esterne del API di GStreamer]] |
| | | |
− | ''Pro memoria'' riportiamo l'esempio per un'applicazione ''a riga di comando'', utilizzando però in questo caso un file Midi:
| + | * [[Eseguire un file Midi con la funzione esterna ''gst parse launch()'' del API di GStreamer]] |
− | Private elem As Pointer
| |
− |
| |
− |
| |
− | Library "libgstreamer-1.0"
| |
− |
| |
− | Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING
| |
− | Private Const GST_FORMAT_TIME As Integer = 3
| |
− | Private stato As Integer = GST_STATE_PLAYING
| |
− |
| |
− | <FONT color=gray>' ''gst_init (int *argc, char **argv[])''
| |
− | ' ''Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.''</font>
| |
− | Private Extern gst_init(argc As Pointer, argv As Pointer)
| |
− |
| |
− | <FONT color=gray>' ''GstElement * gst_element_factory_make(const gchar *factoryname, Const gchar * name)''
| |
− | ' ''Create a new element of the type defined by the given element factory.''</font>
| |
− | Private Extern gst_element_factory_make(factoryname As String, name As String) As Pointer
| |
− |
| |
− | <FONT color=gray>' ''gchar * g_filename_to_uri (const gchar *filename, const gchar *hostname, GError **error)''
| |
− | ' ''Converts an absolute filename to an escaped ASCII-encoded URI.''</font>
| |
− | Private Extern g_filename_to_uri(filename As String, hostname As String, GError As Pointer) As String
| |
− |
| |
− | <FONT color=gray>' ''void g_object_set(gpointer object, const gchar *first_property_name, ...)''
| |
− | ' ''Sets properties on an object.''</font>
| |
− | Private Extern g_object_set(gobject As Pointer, key As String, value_1 As String, value_2 As String, value_3 As Float)
| |
− |
| |
− | <FONT color=gray>' ''GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state)''
| |
− | ' ''Sets the state of the element.''</font>
| |
− | Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer
| |
− |
| |
− | <FONT color=gray>' ''gboolean gst_element_query_duration (GstElement *element, GstFormat format, gint64 *duration)''
| |
− | ' ''Queries an element for the total stream duration in nanoseconds.''</font>
| |
− | Private Extern gst_element_query_duration(gstelement As Pointer, gstformat As Pointer, duration As Pointer) As Boolean
| |
− |
| |
− | <FONT color=gray>' ''gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur)''
| |
− | ' ''Queries an element for the stream position in nanoseconds.''</font>
| |
− | Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean
| |
− |
| |
− | <FONT color=gray>' ''void gst_object_unref(gpointer object)''
| |
− | ' ''Decrements the reference count on object .''</font>
| |
− | Private Extern gst_object_unref(gobject As Pointer)
| |
− |
| |
− |
| |
− | '''Public''' Sub Main()
| |
− |
| |
− | Dim fileaudio as string
| |
− | Dim posizione, durata As Long
| |
− | Dim volume As Float
| |
− |
| |
− | gst_init(0, 0)
| |
− |
| |
− | elem = gst_element_factory_make("playbin", "riproduzione")
| |
− |
| |
− | fileaudio = "<FONT color=gray>''/percorso/del/file.mid''</font>"
| |
− |
| |
− | <FONT color=gray>' ''Imposta il percorso del file Midi da eseguire:''</font>
| |
− | g_object_set(elem, "uri", g_filename_to_uri(fileaudio, Null, 0), Null, 0.0)
| |
− |
| |
− | <FONT color=gray>' ''Imposta il valore del volume (da 0 a 10) di esecuzione:''</font>
| |
− | volume = 7.0
| |
− | g_object_set(elem, "volume", Null, Null, volume)
| |
− |
| |
− | <FONT color=gray>' ''Avvia la riproduzione del file Midi:''</font>
| |
− | gst_element_set_state(elem, GST_STATE_PLAYING)
| |
− |
| |
− | While (posizione = 0) Or (durata > posizione)
| |
− | gst_element_query_duration(elem, GST_FORMAT_TIME, VarPtr(durata))
| |
− | gst_element_query_position(elem, GST_FORMAT_TIME, VarPtr(posizione))
| |
− | Write #File.Out, "\rDurata: " & Date(0, 0, 0, 0, 0, 0, durata / 1000000) & " Pos. " & Date(0, 0, 0, 0, 0, 0, posizione / 1000000)
| |
− | If stato <> 4 Then Break
| |
− | Wait 0.01
| |
− | Wend
| |
− |
| |
− | gst_object_unref(elem)
| |
− |
| |
− | Quit
| |
− |
| |
− | '''End'''
| |
− |
| |
− |
| |
− | '''Public''' Sub Application_Read()
| |
− |
| |
− | Dim s As String
| |
− |
| |
− | Input #File.In, s
| |
− |
| |
− | Select Case s
| |
− | Case "p" <FONT color=gray>' ''Pone in pausa la riproduzione del file Midi''</font>
| |
− | gst_element_set_state(elem, GST_STATE_PAUSED)
| |
− | Case "r"
| |
− | gst_element_set_state(elem, GST_STATE_PLAYING) <FONT color=gray>' ''Riprende la riproduzione del file Midi''</font>
| |
− | Case "s"
| |
− | stato = gst_element_set_state(elem, GST_STATE_NULL) <FONT color=gray>' ''Arresta la riproduzione del file Midi''</font>
| |
− | End Select
| |
− |
| |
− | '''End'''
| |
| | | |
| + | * [[Ottenere un file WAV da un file Midi con la funzione esterna ''gst parse launch()'' del API di GStreamer]] |
| | | |
| + | * [[Visualizzare un oscilloscopio di GStreamer mediante la funzione 'gst_parse_launch()' durante l'esecuzione di un file Midi]] |
| | | |
− | ==Esecuzione mediante una linea di pipeline con la funzione ''gst parse launch()''==
| + | * [[Visualizzare uno spettroscopio di GStreamer mediante la funzione 'gst_parse_launch()' durante l'esecuzione di un file Midi]] |
− | Un file Midi può essere eseguito anche mediante una linea di pipeline gestita dalla funzione ''gst parse launch()'', avendo l'accortezza di inserire alla fine della pipeline uno dei seguenti plugin: ''alsasink'', ''pulsesink'', ''openalsink''.
| |
− | | |
− | Mostriamo un esempio pratico:
| |
− | Private audio As Pointer
| |
− |
| |
− |
| |
− | Library "libgstreamer-1.0"
| |
− |
| |
− | Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING
| |
− | Private Const GST_FORMAT_TIME As Integer = 3
| |
− |
| |
− | <FONT Color=gray>' ''gst_init (int *argc, char **argv[])''
| |
− | ' ''Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.''</font>
| |
− | Private Extern gst_init(argc As Pointer, argv As Pointer)
| |
− |
| |
− | <FONT Color=gray>' ''GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error)''
| |
− | ' ''Create a new pipeline based on command line syntax.''</font>
| |
− | Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer
| |
− |
| |
− | <FONT Color=gray>' ''GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state)''
| |
− | ' ''Sets the state of the element.''</font>
| |
− | Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer
| |
− |
| |
− | <FONT Color=gray>' ''gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur)''
| |
− | ' ''Queries an element for the stream position in nanoseconds.''</font>
| |
− | Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean
| |
− |
| |
− | <FONT Color=gray>' ''void gst_object_unref(gpointer object)''
| |
− | ' ''Decrements the reference count on object.''</font>
| |
− | Private Extern gst_object_unref(gobject As Pointer)
| |
− |
| |
− |
| |
− | '''Public''' Sub Main()
| |
− |
| |
− | Dim tempus As Long
| |
− |
| |
− | gst_init(0, 0)
| |
− |
| |
− | audio = gst_parse_launch("filesrc location=<FONT Color=gray>''/percorso/del/file.mid''</font> ! decodebin ! audioconvert ! audioresample ! volume volume=7.0 ! <FONT Color=#B22222>alsasink</font>", 0)
| |
− |
| |
− | <FONT Color=gray>' ''Avviamo la riproduzione del file Midi:''</font>
| |
− | gst_element_set_state(audio, GST_STATE_PLAYING)
| |
− |
| |
− | While True
| |
− | gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(tempus))
| |
− | Write #File.Out, "\rTempo: " & Date(0, 0, 0, 0, 0, 0, tempus / 1000000)
| |
− | Wait 0.01
| |
− | Wend
| |
− |
| |
− | '''End'''
| |
− |
| |
− |
| |
− | '''Public''' Sub Application_Read()
| |
− |
| |
− | Dim s As String
| |
− |
| |
− | Input #File.In, s
| |
− |
| |
− | Select Case s
| |
− | Case "p"
| |
− | <FONT Color=gray>' ''Pone in pausa la riproduzione del file Midi''</font>
| |
− | gst_element_set_state(audio, GST_STATE_PAUSED)
| |
− | Case "r"
| |
− | <FONT Color=gray>' ''Riprende la riproduzione del file Midi''</font>
| |
− | gst_element_set_state(audio, GST_STATE_PLAYING)
| |
− | Case "s"
| |
− | <FONT Color=gray>' ''Arresta la riproduzione del file Midi''</font>
| |
− | gst_element_set_state(audio, GST_STATE_NULL)
| |
− | gst_object_unref(audio)
| |
− | Print "\nEsecuzione terminata."
| |
− | Quit
| |
− | End Select
| |
− |
| |
− | '''End'''
| |
− | | |
− | | |
− | Va precisato che la riga di comando afferente alla funzione esterna ''gst parse launch()'' può essere impostata più brevemente anche così:
| |
− | audio = gst_parse_launch("playbin uri=file://<FONT Color=gray>''/percorso/del/file.mid''</font>", 0)
| |
− | ma non sarà possibile utilizare il plugin per la gestione del volume.
| |
− | | |
− | | |
− | | |
− | | |
− | =Riferimenti=
| |
− | * http://docs.gstreamer.com/display/GstSDK/gst-launch
| |
− | * http://gstreamer.freedesktop.org/
| |
− | * http://gstreamer.com/
| |