mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-02 09:01:46 -05:00
fix module-sine for glitch-free
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/glitch-free@2393 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
df92b23fa6
commit
f124445f89
1 changed files with 38 additions and 6 deletions
|
|
@ -67,12 +67,30 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk
|
|||
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) {
|
||||
struct userdata *u;
|
||||
|
||||
|
|
@ -86,6 +104,20 @@ static void sink_input_kill_cb(pa_sink_input *i) {
|
|||
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 @@ int pa__init(pa_module*m) {
|
|||
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 @@ int pa__init(pa_module*m) {
|
|||
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 @@ int pa__init(pa_module*m) {
|
|||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue