title: How to modify playback speed of audio stream in Gstreamer?
body: <p>Hi everyone I am trying to change the playback speed of an audio file using the gstreamer library in c. I've followed most of the tutorials on the gstreamer website but the only thing that is not working is the playback speed. </p>
  
  <p>The way it is set up right now, the speed should be doubled when a '.' is encountered but nothing happens. Can any experienced gstreamer users provide some insight?  </p>
  
  <pre><code>typedef struct bindata {
      GMainLoop *loop;
      GstElement *pipeline, *source, *mp3decoder, *volume, *pulseout;
      gboolean playing;
  } bindata;
  
  static bindata data;
  
  static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer *misc){
      //GMainLoop *loop = (GMainLoop *) misc;
      switch (GST_MESSAGE_TYPE(msg)){
          case GST_MESSAGE_EOS: {
              g_message("End of stream.\n");
              g_main_loop_quit(data.loop);
              break;
          }
          case GST_MESSAGE_ERROR:{
              GError *error;
              gst_message_parse_error(msg, &amp;error, NULL);
              g_printerr("%s\n", error-&gt;message);
              g_error_free(error);
  
              g_main_loop_quit(data.loop);
              break;
          }
          default: break;
      }
      return TRUE;
  }
  
  static gboolean keypress (GIOChannel *src, GIOCondition cond, bindata *data){
      int c;
      gdouble vol;
      GstFormat format = GST_FORMAT_TIME;
  
      //if(g_io_channel_read_unichar(src, str, NULL) != G_IO_STATUS_NORMAL){
      if((c = getchar()) == EOF ){ 
          return TRUE;
      }
  
      switch(c){
          case '+':
             g_object_get(data-&gt;volume, "volume", &amp;vol,NULL);
             if (vol &gt;= 10) break;
             g_object_set (data-&gt;volume, "volume", vol + 0.1, NULL);
             break;
          case '-':
             g_object_get(data-&gt;volume, "volume", &amp;vol, NULL);
             if (vol &lt;= 0.1) break;
             g_object_set (data-&gt;volume, "volume", vol - 0.1, NULL);
             break;
          case '.':
             g_print("speed up \n");
             gst_element_send_event(data-&gt;pulseout, gst_event_new_step(format, 20, 2.0, TRUE, FALSE));
             break;
          case ',':
             g_print("speed down \n");
             break;
          case ' ':
             data-&gt;playing = !data-&gt;playing;
             gst_element_set_state (data-&gt;pipeline, data-&gt;playing ? GST_STATE_PLAYING : GST_STATE_PAUSED);
             break;
          default: 
             break;
      }
      return TRUE;
  }
  
  int main(int argc, char *argv[]){
      GstBus *bus;
      guint bus_watch_id;
      GIOChannel *io_stdin;
  
      gst_init(&amp;argc, &amp;argv);
      memset (&amp;data, 0, sizeof(data));
      data.loop = g_main_loop_new(NULL, false);
  
      if(argc != 2){
         g_printerr("Usage: ./play &lt;URI: mp3 file&gt;");
         return -1;
      }
  
      io_stdin = g_io_channel_unix_new (fileno (stdin));
      g_io_add_watch (io_stdin, G_IO_IN, (GIOFunc) keypress, &amp;data);
  
      data.pipeline   = gst_pipeline_new ("audio-player");
      data.source     = gst_element_factory_make ("filesrc", "file source");
      data.mp3decoder = gst_element_factory_make ("mad", "mad mp3");
      data.volume     = gst_element_factory_make ("volume", "volume");
      data.pulseout   = gst_element_factory_make ("pulsesink", "pulse audio");
  
      if(!data.pipeline || !data.source || !data.mp3decoder || !data.pulseout || !data.volume) {
         g_printerr("Some element(s) could not be created. Exiting. \n");
         return -1;
      }
  
      g_object_set (G_OBJECT (data.source), "location", argv[1], NULL);
      g_object_set (G_OBJECT(data.volume), "volume", 0.01, NULL); 
  
      bus = gst_pipeline_get_bus(GST_PIPELINE(data.pipeline));
      bus_watch_id = gst_bus_add_watch(bus, bus_call, NULL);
      gst_object_unref(bus);
  
      gst_bin_add_many(GST_BIN (data.pipeline), data.source, data.mp3decoder, data.volume, data.pulseout, NULL);
      gst_element_link_many (data.source, data.mp3decoder, data.volume, data.pulseout, NULL);
  
      gst_element_set_state(data.pipeline, GST_STATE_PLAYING);
      data.playing = TRUE;
      g_print ("Running...\n");
      g_main_loop_run(data.loop);
      g_print ("ended. \n");
      gst_element_set_state(data.pipeline, GST_STATE_NULL);
      gst_object_unref(GST_OBJECT(data.pipeline));
      g_source_remove (bus_watch_id);
      g_main_loop_unref (data.loop);
  
      return 0;
  }
  </code></pre>