[pulseaudio-commits] r2393 - /branches/glitch-free/src/modules/module-sine.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Fri May 9 16:15:08 PDT 2008
Author: lennart
Date: Sat May 10 01:15:06 2008
New Revision: 2393
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2393&root=pulseaudio&view=rev
Log:
fix module-sine for glitch-free
Modified:
branches/glitch-free/src/modules/module-sine.c
Modified: branches/glitch-free/src/modules/module-sine.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/glitch-free/src/modules/module-sine.c?rev=2393&root=pulseaudio&r1=2392&r2=2393&view=diff
==============================================================================
--- branches/glitch-free/src/modules/module-sine.c (original)
+++ branches/glitch-free/src/modules/module-sine.c Sat May 10 01:15:06 2008
@@ -67,10 +67,28 @@
pa_assert(chunk);
chunk->memblock = pa_memblock_ref(u->memblock);
- chunk->length = pa_memblock_get_length(chunk->memblock);
- chunk->index = 0;
+ chunk->length = pa_memblock_get_length(u->memblock) - u->peek_index;
+ chunk->index = u->peek_index;
+
+ u->peek_index = 0;
return 0;
+}
+
+static void sink_input_process_rewind_cb(pa_sink_input *i, size_t nbytes) {
+ size_t l;
+ struct userdata *u;
+
+ pa_sink_input_assert_ref(i);
+ pa_assert_se(u = i->userdata);
+
+ l = pa_memblock_get_length(u->memblock);
+ nbytes %= l;
+
+ if (u->peek_index >= nbytes)
+ u->peek_index -= nbytes;
+ else
+ u->peek_index = l + u->peek_index - nbytes;
}
static void sink_input_kill_cb(pa_sink_input *i) {
@@ -86,6 +104,20 @@
pa_module_unload_request(u->module);
}
+/* Called from IO thread context */
+static void sink_input_state_change_cb(pa_sink_input *i, pa_sink_input_state_t state) {
+ struct userdata *u;
+
+ pa_sink_input_assert_ref(i);
+ pa_assert_se(u = i->userdata);
+
+ /* If we are added for the first time, ask for a rewinding so that
+ * we are heard right-away. */
+ if (PA_SINK_INPUT_IS_LINKED(state) &&
+ i->thread_info.state == PA_SINK_INPUT_INIT)
+ pa_sink_input_request_rewind(i, 0, FALSE, TRUE);
+}
+
static void calc_sine(float *f, size_t l, float freq) {
size_t i;
@@ -101,7 +133,6 @@
pa_sink *sink;
pa_sample_spec ss;
uint32_t frequency;
- char t[256];
void *p;
pa_sink_input_new_data data;
@@ -137,13 +168,12 @@
calc_sine(p, pa_memblock_get_length(u->memblock), frequency);
pa_memblock_release(u->memblock);
- pa_snprintf(t, sizeof(t), "%u Hz Sine", frequency);
-
pa_sink_input_new_data_init(&data);
data.sink = sink;
data.driver = __FILE__;
- pa_proplist_sets(data.proplist, PA_PROP_MEDIA_NAME, t);
+ pa_proplist_setf(data.proplist, PA_PROP_MEDIA_NAME, "%u Hz Sine", frequency);
pa_proplist_sets(data.proplist, PA_PROP_MEDIA_ROLE, "abstract");
+ pa_proplist_setf(data.proplist, "sine.hz", "%u", frequency);
pa_sink_input_new_data_set_sample_spec(&data, &ss);
data.module = m;
@@ -154,7 +184,9 @@
goto fail;
u->sink_input->pop = sink_input_pop_cb;
+ u->sink_input->process_rewind = sink_input_process_rewind_cb;
u->sink_input->kill = sink_input_kill_cb;
+ u->sink_input->state_change = sink_input_state_change_cb;
u->sink_input->userdata = u;
pa_sink_input_put(u->sink_input);
More information about the pulseaudio-commits
mailing list