X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fschannel.c;h=10057789ed052d556f40e052c6b619c70b97125b;hb=f9bcaa3f421a0dc1f016b1de10d2f0871e73aefd;hp=54324363ed3c208f8bbdf24b3c261bd53a4bca78;hpb=cdd8964f54a340e947b8a992ce7a6bc6cb192de6;p=projects%2Fchimara%2Fchimara.git diff --git a/libchimara/schannel.c b/libchimara/schannel.c index 5432436..1005778 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); @@ -442,8 +463,9 @@ glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify) g_object_set(chan->source, "stream", stream, NULL); g_object_unref(stream); /* Now owned by GStreamer element */ - if(!gst_element_set_state(chan->pipeline, GST_STATE_PLAYING)) { - WARNING_S(_("Could not set GstElement state to"), "PLAYING"); + /* Play the sound; unless the channel is paused, then pause it instead */ + if(!gst_element_set_state(chan->pipeline, chan->paused? GST_STATE_PAUSED : GST_STATE_PLAYING)) { + WARNING_S(_("Could not set GstElement state to"), chan->paused? "PAUSED" : "PLAYING"); return 0; } return 1; @@ -454,11 +476,11 @@ glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify) /** * glk_schannel_play_multi: - * @chanarray: - * @chancount: - * @sndarray: - * @soundcount: - * @notify: + * @chanarray: Array of #schanid_t structures. + * @chancount: Length of @chanarray. + * @sndarray: Array of sound resource numbers. + * @soundcount: Length of @sndarray, must be equal to @chanarray. + * @notify: If nonzero, request a notification when each sound finishes. * * [DRAFT SPEC] * @@ -530,7 +552,24 @@ glk_schannel_pause(schanid_t chan) { VALID_SCHANNEL(chan, return); - /* Not implemented */ + if(chan->paused) + return; /* Silently do nothing */ + + /* Mark the channel as paused even if there is no sound playing yet */ + chan->paused = TRUE; + + 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; + } } /** @@ -547,7 +586,24 @@ glk_schannel_unpause(schanid_t chan) { VALID_SCHANNEL(chan, return); - /* Not implemented */ + if(!chan->paused) + return; /* Silently do nothing */ + + /* Mark the channel as not paused in any case */ + chan->paused = FALSE; + + 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; + } } /** @@ -619,7 +675,7 @@ glk_schannel_set_volume(schanid_t chan, glui32 vol) * volume change should be wherever the previous volume change was interrupted * (rather than the previous change's beginning or ending point). * - * Not all libraries support thse functions. You should test the appropriate + * Not all libraries support these functions. You should test the appropriate * gestalt selectors before you rely on them; see "Testing for Sound * Capabilities". */ @@ -631,7 +687,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