asdfuser pushed a commit to branch master.

commit 4d318ba913d868a289b2ad06f66d3808ae269470
Author: Daniel Willmann <[email protected]>
Date:   Mon Mar 18 16:05:03 2013 +0000

    ecore_audio: Implement speed get/set functions
    
    You can now change the playback speed of an input
    
    Signed-off-by: Daniel Willmann <[email protected]>
---
 src/lib/ecore_audio/Ecore_Audio.h         | 21 +++++++++++++++++++++
 src/lib/ecore_audio/ecore_audio.c         | 27 +++++++++++++++++++++++++++
 src/lib/ecore_audio/ecore_audio_private.h |  1 +
 src/lib/ecore_audio/ecore_audio_pulse.c   |  6 +++---
 4 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/src/lib/ecore_audio/Ecore_Audio.h 
b/src/lib/ecore_audio/Ecore_Audio.h
index 765353d..68968f3 100644
--- a/src/lib/ecore_audio/Ecore_Audio.h
+++ b/src/lib/ecore_audio/Ecore_Audio.h
@@ -356,6 +356,27 @@ EAPI int 
ecore_audio_input_samplerate_get(Ecore_Audio_Object *input);
 EAPI void ecore_audio_input_samplerate_set(Ecore_Audio_Object *input, int 
samplerate);
 
 /**
+ * @brief Get the speed the input is played back at
+ *
+ * @param input The input
+ *
+ * @return The speed
+ *
+ * @since 1.8
+ */
+EAPI double ecore_audio_input_speed_get(Ecore_Audio_Object *input);
+
+/**
+ * @brief Set the speed the input is played back at
+ *
+ * @param input The input
+ * @param samplerate The speed (1.0 is normal speed)
+ *
+ * @since 1.8
+ */
+EAPI void ecore_audio_input_speed_set(Ecore_Audio_Object *input, double speed);
+
+/**
  * @brief Get the channels of the input
  *
  * @param input The input
diff --git a/src/lib/ecore_audio/ecore_audio.c 
b/src/lib/ecore_audio/ecore_audio.c
index f59f9e4..c00c67b 100644
--- a/src/lib/ecore_audio/ecore_audio.c
+++ b/src/lib/ecore_audio/ecore_audio.c
@@ -348,6 +348,7 @@ ecore_audio_input_add(Ecore_Audio_Type type)
    in->module = module;
    in->output = NULL;
    in->paused = EINA_FALSE;
+   in->speed = 1.0;
 
    return module->in_ops->input_new((Ecore_Audio_Object *)in);
 }
@@ -427,6 +428,32 @@ EAPI void 
ecore_audio_input_samplerate_set(Ecore_Audio_Object *input, int sample
      }
 }
 
+EAPI double ecore_audio_input_speed_get(Ecore_Audio_Object *input)
+{
+   Ecore_Audio_Input* in = (Ecore_Audio_Input *)input;
+   EINA_SAFETY_ON_NULL_RETURN_VAL(in, 0);
+
+   return in->speed;
+}
+
+EAPI void ecore_audio_input_speed_set(Ecore_Audio_Object *input, double speed)
+{
+   Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
+   EINA_SAFETY_ON_NULL_RETURN(input);
+   Ecore_Audio_Module *outmod;
+
+   if ((in->speed == speed) || (speed < 0.2) || (speed > 5.0))
+     return;
+
+   in->speed = speed;
+
+   if (in->output)
+     {
+        outmod = in->output->module;
+        outmod->out_ops->output_update_input_format((Ecore_Audio_Object 
*)in->output, input);
+     }
+}
+
 EAPI int ecore_audio_input_channels_get(Ecore_Audio_Object *input)
 {
    Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
diff --git a/src/lib/ecore_audio/ecore_audio_private.h 
b/src/lib/ecore_audio/ecore_audio_private.h
index 2f96499..9c0011e 100644
--- a/src/lib/ecore_audio/ecore_audio_private.h
+++ b/src/lib/ecore_audio/ecore_audio_private.h
@@ -283,6 +283,7 @@ struct _Ecore_Audio_Input
    int                 samplerate;
    int                 channels;
    Eina_Bool           looped; /**< Loop the sound */
+   double              speed;
    double              length; /**< Length of the sound */
    Eina_Bool           preloaded;
    Eina_Bool           ended;
diff --git a/src/lib/ecore_audio/ecore_audio_pulse.c 
b/src/lib/ecore_audio/ecore_audio_pulse.c
index ce326c2..0db00cc 100644
--- a/src/lib/ecore_audio/ecore_audio_pulse.c
+++ b/src/lib/ecore_audio/ecore_audio_pulse.c
@@ -402,7 +402,7 @@ _pulse_output_add_input(Ecore_Audio_Object *output, 
Ecore_Audio_Object *input)
 
    pa_sample_spec ss = {
       .format = PA_SAMPLE_FLOAT32LE,
-      .rate = in->samplerate,
+      .rate = in->samplerate * in->speed,
       .channels = in->channels,
    };
 
@@ -416,7 +416,7 @@ _pulse_output_add_input(Ecore_Audio_Object *output, 
Ecore_Audio_Object *input)
    in->obj_data = stream;
 
    pa_stream_set_write_callback(stream, _pulse_output_write_cb, in);
-   pa_stream_connect_playback(stream, NULL, NULL, PA_STREAM_NOFLAGS, NULL, 
NULL);
+   pa_stream_connect_playback(stream, NULL, NULL, PA_STREAM_VARIABLE_RATE, 
NULL, NULL);
 
    return EINA_TRUE;
 }
@@ -449,7 +449,7 @@ _pulse_output_update_input_format(Ecore_Audio_Object 
*output EINA_UNUSED, Ecore_
   Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
   pa_stream *stream = (pa_stream *)in->obj_data;
 
-  pa_operation_unref(pa_stream_update_sample_rate(stream, in->samplerate, 
NULL, NULL));
+  pa_operation_unref(pa_stream_update_sample_rate(stream, in->samplerate * 
in->speed, NULL, NULL));
 }
 
 static int

-- 

------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html

Reply via email to