Implement glk_schannel_set_volume()
authorPhilip Chimento <philip.chimento@gmail.com>
Wed, 5 Jan 2011 21:55:52 +0000 (16:55 -0500)
committerPhilip Chimento <philip.chimento@gmail.com>
Wed, 5 Jan 2011 21:55:52 +0000 (16:55 -0500)
Implement setting volume on sound channels using the GStreamer "volume"
element.

libchimara/gestalt.c
libchimara/schannel.c

index 749bc43271aa2349d6b083be09ef9224eb9c8fc4..06154591117d7d8d6ede5204e1141761e6ffd3c7 100644 (file)
@@ -127,6 +127,7 @@ glk_gestalt_ext(glui32 sel, glui32 val, glui32 *arr, glui32 arrlen)
                        return 1;
 
                case gestalt_Sound:
+               case gestalt_SoundVolume:
 #ifdef GSTREAMER_SOUND
                        return 1;
 #else
@@ -134,7 +135,6 @@ glk_gestalt_ext(glui32 sel, glui32 val, glui32 *arr, glui32 arrlen)
 #endif
                        
                /* Unsupported capabilities */
-               case gestalt_SoundVolume:
                case gestalt_SoundNotify:
                case gestalt_SoundMusic:
                /* Selector not supported */    
index d93101f1ef543fe082e968cd805cf14286188573..730e03328188290d2b161d45b84ece7ad7fa385d 100644 (file)
@@ -45,7 +45,7 @@ glk_schannel_create(glui32 rock)
 
        /* Create GStreamer elements to put in the pipeline */
        s->source = gst_element_factory_make("filesrc", NULL);
-       s->filter = gst_element_factory_make("identity", NULL);
+       s->filter = gst_element_factory_make("volume", NULL);
        s->sink = gst_element_factory_make("autoaudiosink", NULL);
        if(!s->source || !s->filter || !s->sink) {
                WARNING("Could not create one or more GStreamer elements");
@@ -266,12 +266,20 @@ glk_schannel_stop(schanid_t chan)
  * linkend="chimara-Testing-for-Sound-Capabilities">Testing for Sound
  * Capabilities</link>.
  *
- * <warning><para>This function is not implemented yet.</para></warning>
+ * <note><title>Chimara</title>
+ *   <para>Chimara supports volumes from 0 to 1000&percnt;, that is, values of
+ *   @vol up to 0xA0000.</para>
+ * </note>
  */
 void 
 glk_schannel_set_volume(schanid_t chan, glui32 vol)
 {
        VALID_SCHANNEL(chan, return);
+#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
 }
 
 /**