From: Philip Chimento Date: Wed, 6 Jul 2011 20:57:15 +0000 (+0200) Subject: Start implementing new sound API X-Git-Tag: v0.9~47^2~12 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=88bd3ce92004750c2689537cf1fa9a8211ad9189;p=projects%2Fchimara%2Fchimara.git Start implementing new sound API glk_schannel_create_ext() glk_schannel_pause() glk_schannel_unpause() --- diff --git a/libchimara/schannel.c b/libchimara/schannel.c index 5432436..373a9af 100644 --- a/libchimara/schannel.c +++ b/libchimara/schannel.c @@ -174,6 +174,24 @@ finally: */ schanid_t glk_schannel_create(glui32 rock) +{ + return glk_schannel_create_ext(rock, 0x10000); +} + +/** + * glk_schannel_create_ext: + * @rock: The rock value to give the new sound channel. + * @volume: Integer representing the volume; 0x10000 is 100%. + * + * [DRAFT SPEC] + * + * The glk_schannel_create_ext() call lets you create a channel with the volume + * already set at a given level. + * + * Returns: A new sound channel, or %NULL. + */ +schanid_t +glk_schannel_create_ext(glui32 rock, glui32 volume) { #ifdef GSTREAMER_SOUND ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); @@ -213,6 +231,9 @@ glk_schannel_create(glui32 rock) goto fail; } + /* Set the initial volume */ + glk_schannel_set_volume(s, volume); + /* Put the elements in the pipeline and link as many together as we can without knowing the type of the audio stream */ gst_bin_add_many(GST_BIN(s->pipeline), s->source, s->typefind, s->convert, s->filter, s->sink, NULL); @@ -530,7 +551,21 @@ glk_schannel_pause(schanid_t chan) { VALID_SCHANNEL(chan, return); - /* Not implemented */ + if(chan->paused) + return; /* Silently do nothing */ + GstState state; + if(gst_element_get_state(chan->pipeline, &state, NULL, GST_CLOCK_TIME_NONE) != GST_STATE_CHANGE_SUCCESS) { + WARNING(_("Could not get GstElement state")); + return; + } + if(state != GST_STATE_PLAYING) + return; /* Silently do nothing if no sound is playing */ + + if(!gst_element_set_state(chan->pipeline, GST_STATE_PAUSED)) { + WARNING_S(_("Could not set GstElement state to"), "PAUSED"); + return; + } + chan->paused = TRUE; } /** @@ -547,7 +582,22 @@ glk_schannel_unpause(schanid_t chan) { VALID_SCHANNEL(chan, return); - /* Not implemented */ + if(!chan->paused) + return; /* Silently do nothing */ + + GstState state; + if(gst_element_get_state(chan->pipeline, &state, NULL, GST_CLOCK_TIME_NONE) != GST_STATE_CHANGE_SUCCESS) { + WARNING(_("Could not get GstElement state")); + return; + } + if(state != GST_STATE_PAUSED) + return; /* Silently do nothing */ + + if(!gst_element_set_state(chan->pipeline, GST_STATE_PLAYING)) { + WARNING_S(_("Could not set GstElement state to"), "PLAYING"); + return; + } + chan->paused = FALSE; } /** @@ -631,7 +681,6 @@ glk_schannel_set_volume_ext(schanid_t chan, glui32 vol, glui32 duration, glui32 #ifdef GSTREAMER_SOUND gdouble volume_gst = (gdouble)vol / 0x10000; - g_printerr("Volume set to: %f\n", volume_gst); g_object_set(chan->filter, "volume", CLAMP(volume_gst, 0.0, 10.0), NULL); #endif diff --git a/libchimara/schannel.h b/libchimara/schannel.h index 465e7dc..dd77f1a 100644 --- a/libchimara/schannel.h +++ b/libchimara/schannel.h @@ -25,6 +25,8 @@ struct glk_schannel_struct glui32 resource, notify; /* How many times to repeat the last sound played (-1 = forever) */ glui32 repeats; + /* Whether channel is paused */ + gboolean paused; #ifdef GSTREAMER_SOUND /* Each sound channel is represented as a GStreamer pipeline. */ @@ -32,4 +34,4 @@ struct glk_schannel_struct #endif }; -#endif \ No newline at end of file +#endif