Start implementing new sound API
authorPhilip Chimento <philip.chimento@gmail.com>
Wed, 6 Jul 2011 20:57:15 +0000 (22:57 +0200)
committerPhilip Chimento <philip.chimento@gmail.com>
Wed, 6 Jul 2011 20:57:15 +0000 (22:57 +0200)
glk_schannel_create_ext()
glk_schannel_pause()
glk_schannel_unpause()

libchimara/schannel.c
libchimara/schannel.h

index 54324363ed3c208f8bbdf24b3c261bd53a4bca78..373a9afa65aa9aa3a3e54b7ea733b25dbe827817 100644 (file)
@@ -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&percnt;.
+ *
+ * [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
 
index 465e7dc51fe9b7095dbf870ffec104dd0a14bc2a..dd77f1a069cfd0268cf5ef7ed122293c70ddd48e 100644 (file)
@@ -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