diff options
author | Jaska Uimonen <jaska.uimonen@helsinki.fi> | 2012-08-08 11:14:38 +0300 |
---|---|---|
committer | Jaska Uimonen <jaska.uimonen@intel.com> | 2013-01-24 14:28:39 +0200 |
commit | 953e7273fa696e19edfaeefe92d421a749d58f77 (patch) | |
tree | d8c260e2a69691f9a18fb76e569909739d264407 | |
parent | 7c03c5f6ff5aa1ef3185c6fec544ab14847e2ee1 (diff) | |
download | pulseaudio-panda-953e7273fa696e19edfaeefe92d421a749d58f77.tar.gz pulseaudio-panda-953e7273fa696e19edfaeefe92d421a749d58f77.tar.bz2 pulseaudio-panda-953e7273fa696e19edfaeefe92d421a749d58f77.zip |
volume ramp: adding volume ramping to sink-input
-rw-r--r-- | src/pulsecore/sink-input.c | 60 | ||||
-rw-r--r-- | src/pulsecore/sink-input.h | 11 |
2 files changed, 70 insertions, 1 deletions
diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c index f6f93b88..58a4f20a 100644 --- a/src/pulsecore/sink-input.c +++ b/src/pulsecore/sink-input.c @@ -477,6 +477,11 @@ int pa_sink_input_new( reset_callbacks(i); i->userdata = NULL; + if (data->flags & PA_SINK_INPUT_START_RAMP_MUTED) + pa_cvolume_ramp_int_init(&i->ramp, PA_VOLUME_MUTED, data->sample_spec.channels); + else + pa_cvolume_ramp_int_init(&i->ramp, PA_VOLUME_NORM, data->sample_spec.channels); + i->thread_info.state = i->state; i->thread_info.attached = FALSE; pa_atomic_store(&i->thread_info.drained, 1); @@ -492,6 +497,8 @@ int pa_sink_input_new( i->thread_info.playing_for = 0; i->thread_info.direct_outputs = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); + i->thread_info.ramp = i->ramp; + pa_assert_se(pa_idxset_put(core->sink_inputs, i, &i->index) == 0); pa_assert_se(pa_idxset_put(i->sink->inputs, pa_sink_input_ref(i), NULL) == 0); @@ -858,6 +865,8 @@ void pa_sink_input_peek(pa_sink_input *i, size_t slength /* in sink frames */, p while (tchunk.length > 0) { pa_memchunk wchunk; pa_bool_t nvfs = need_volume_factor_sink; + pa_cvolume target; + pa_bool_t tmp; wchunk = tchunk; pa_memblock_ref(wchunk.memblock); @@ -894,6 +903,16 @@ void pa_sink_input_peek(pa_sink_input *i, size_t slength /* in sink frames */, p pa_volume_memchunk(&wchunk, &i->sink->sample_spec, &i->volume_factor_sink); } + /* check for possible volume ramp */ + if (pa_cvolume_ramp_active(&i->thread_info.ramp)) { + pa_memchunk_make_writable(&wchunk, 0); + pa_volume_ramp_memchunk(&wchunk, &i->sink->sample_spec, &(i->thread_info.ramp)); + } else if ((tmp = pa_cvolume_ramp_target_active(&(i->thread_info.ramp)))) { + pa_memchunk_make_writable(&wchunk, 0); + pa_cvolume_ramp_get_targets(&i->thread_info.ramp, &target); + pa_volume_memchunk(&wchunk, &i->sink->sample_spec, &target); + } + pa_memblockq_push_align(i->thread_info.render_memblockq, &wchunk); } else { pa_memchunk rchunk; @@ -910,6 +929,16 @@ void pa_sink_input_peek(pa_sink_input *i, size_t slength /* in sink frames */, p pa_volume_memchunk(&rchunk, &i->sink->sample_spec, &i->volume_factor_sink); } + /* check for possible volume ramp */ + if (pa_cvolume_ramp_active(&(i->thread_info.ramp))) { + pa_memchunk_make_writable(&rchunk, 0); + pa_volume_ramp_memchunk(&rchunk, &i->sink->sample_spec, &(i->thread_info.ramp)); + } else if (pa_cvolume_ramp_target_active(&(i->thread_info.ramp))) { + pa_memchunk_make_writable(&rchunk, 0); + pa_cvolume_ramp_get_targets(&i->thread_info.ramp, &target); + pa_volume_memchunk(&rchunk, &i->sink->sample_spec, &target); + } + pa_memblockq_push_align(i->thread_info.render_memblockq, &rchunk); pa_memblock_unref(rchunk.memblock); } @@ -1204,6 +1233,31 @@ void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, pa_boo pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index); } +/* Called from main thread */ +void pa_sink_input_set_volume_ramp( + pa_sink_input *i, + const pa_cvolume_ramp *ramp, + pa_bool_t send_msg, + pa_bool_t save) { + + pa_sink_input_assert_ref(i); + pa_assert_ctl_context(); + pa_assert(PA_SINK_INPUT_IS_LINKED(i->state)); + pa_assert(ramp); + + pa_cvolume_ramp_convert(ramp, &i->ramp, i->sample_spec.rate); + + pa_log_debug("setting volume ramp with target vol:%d and length:%ld", + i->ramp.ramps[0].target, + i->ramp.ramps[0].length); + + + /* This tells the sink that volume ramp changed */ + if (send_msg) + pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_VOLUME_RAMP, + NULL, 0, NULL) == 0); +} + /* Called from main context */ static void set_real_ratio(pa_sink_input *i, const pa_cvolume *v) { pa_sink_input_assert_ref(i); @@ -1811,6 +1865,12 @@ int pa_sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t } return 0; + case PA_SINK_INPUT_MESSAGE_SET_VOLUME_RAMP: + /* we have ongoing ramp where we take current start values */ + pa_cvolume_ramp_start_from(&i->thread_info.ramp, &i->ramp); + i->thread_info.ramp = i->ramp; + return 0; + case PA_SINK_INPUT_MESSAGE_SET_SOFT_MUTE: if (i->thread_info.muted != i->muted) { i->thread_info.muted = i->muted; diff --git a/src/pulsecore/sink-input.h b/src/pulsecore/sink-input.h index af2177a2..b7686bed 100644 --- a/src/pulsecore/sink-input.h +++ b/src/pulsecore/sink-input.h @@ -61,7 +61,8 @@ typedef enum pa_sink_input_flags { PA_SINK_INPUT_DONT_INHIBIT_AUTO_SUSPEND = 256, PA_SINK_INPUT_NO_CREATE_ON_SUSPEND = 512, PA_SINK_INPUT_KILL_ON_SUSPEND = 1024, - PA_SINK_INPUT_PASSTHROUGH = 2048 + PA_SINK_INPUT_PASSTHROUGH = 2048, + PA_SINK_INPUT_START_RAMP_MUTED = 4096, } pa_sink_input_flags_t; struct pa_sink_input { @@ -115,6 +116,9 @@ struct pa_sink_input { * this.*/ pa_bool_t save_sink:1, save_volume:1, save_muted:1; + /* for volume ramps */ + pa_cvolume_ramp_int ramp; + pa_resample_method_t requested_resample_method, actual_resample_method; /* Returns the chunk of audio data and drops it from the @@ -237,6 +241,8 @@ struct pa_sink_input { pa_usec_t requested_sink_latency; pa_hashmap *direct_outputs; + + pa_cvolume_ramp_int ramp; } thread_info; void *userdata; @@ -253,6 +259,7 @@ enum { PA_SINK_INPUT_MESSAGE_SET_STATE, PA_SINK_INPUT_MESSAGE_SET_REQUESTED_LATENCY, PA_SINK_INPUT_MESSAGE_GET_REQUESTED_LATENCY, + PA_SINK_INPUT_MESSAGE_SET_VOLUME_RAMP, PA_SINK_INPUT_MESSAGE_MAX }; @@ -359,6 +366,8 @@ pa_cvolume *pa_sink_input_get_volume(pa_sink_input *i, pa_cvolume *volume, pa_bo void pa_sink_input_set_mute(pa_sink_input *i, pa_bool_t mute, pa_bool_t save); pa_bool_t pa_sink_input_get_mute(pa_sink_input *i); +void pa_sink_input_set_volume_ramp(pa_sink_input *i, const pa_cvolume_ramp *ramp, pa_bool_t send_msg, pa_bool_t save); + void pa_sink_input_update_proplist(pa_sink_input *i, pa_update_mode_t mode, pa_proplist *p); pa_resample_method_t pa_sink_input_get_resample_method(pa_sink_input *i); |