[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.19-281-g0fcdc3d
Lennart Poettering
gitmailer-noreply at 0pointer.de
Sun Nov 22 20:45:07 PST 2009
This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.
The master branch has been updated
from c815441ba19e92f88395de8763df4a1e57950f7b (commit)
- Log -----------------------------------------------------------------
0fcdc3d Merge branch 'master' of ssh://rootserver/home/lennart/git/public/pulseaudio
675957b Merge branch 'master' of ssh://rootserver/home/lennart/git/public/pulseaudio
9708ecd Merge branch 'master' of ssh://rootserver/home/lennart/git/public/pulseaudio
f202af1 ramping: minor cleanups
4d62f15 Merge remote branch 'origin/merge-queue'
897ef86 Add volume ramping feature - sink modification
5318eb3 Add volume ramping feature - sink-input modification
8eaa40b Add volume ramping feature - envelop fix
-----------------------------------------------------------------------
Summary of changes:
src/pulsecore/envelope.c | 335 +++++++++++++++++++++++++++++++--------
src/pulsecore/envelope.h | 3 +
src/pulsecore/sink-input.c | 383 +++++++++++++++++++++++++++++++++++---------
src/pulsecore/sink-input.h | 21 +++
src/pulsecore/sink.c | 6 +-
5 files changed, 608 insertions(+), 140 deletions(-)
-----------------------------------------------------------------------
commit 8eaa40b6f4cae749610770c85ba500f326d59b50
Author: zbt <huan.zheng at intel.com>
Date: Thu Jul 16 10:41:07 2009 +0800
Add volume ramping feature - envelop fix
diff --git a/src/pulsecore/envelope.c b/src/pulsecore/envelope.c
index fd6a948..0eca811 100644
--- a/src/pulsecore/envelope.c
+++ b/src/pulsecore/envelope.c
@@ -177,7 +177,7 @@ static int32_t item_get_int(pa_envelope_item *i, pa_usec_t x) {
pa_assert(i->j > 0);
pa_assert(i->def->points_x[i->j-1] <= x);
- pa_assert(x < i->def->points_x[i->j]);
+ pa_assert(x <= i->def->points_x[i->j]);
return linear_interpolate_int(i->def->points_x[i->j-1], i->def->points_y.i[i->j-1],
i->def->points_x[i->j], i->def->points_y.i[i->j], x);
@@ -200,7 +200,7 @@ static float item_get_float(pa_envelope_item *i, pa_usec_t x) {
pa_assert(i->j > 0);
pa_assert(i->def->points_x[i->j-1] <= x);
- pa_assert(x < i->def->points_x[i->j]);
+ pa_assert(x <= i->def->points_x[i->j]);
return linear_interpolate_float(i->def->points_x[i->j-1], i->def->points_y.f[i->j-1],
i->def->points_x[i->j], i->def->points_y.f[i->j], x);
@@ -550,7 +550,7 @@ static int32_t linear_get_int(pa_envelope *e, int v) {
e->points[v].cached_valid = TRUE;
}
- return e->points[v].y.i[e->points[v].n_current] + (e->points[v].cached_dy_i * (int32_t) (e->x - e->points[v].x[e->points[v].n_current])) / (int32_t) e->points[v].cached_dx;
+ return e->points[v].y.i[e->points[v].n_current] + ((float)e->points[v].cached_dy_i * (int32_t) (e->x - e->points[v].x[e->points[v].n_current])) / (int32_t) e->points[v].cached_dx;
}
static float linear_get_float(pa_envelope *e, int v) {
@@ -597,34 +597,60 @@ void pa_envelope_apply(pa_envelope *e, pa_memchunk *chunk) {
fs = pa_frame_size(&e->sample_spec);
n = chunk->length;
+ pa_log_debug("Envelop position %d applying factor %d=%f, sample spec is %d, chunk's length is %d, fs is %d\n", e->x, linear_get_int(e, v), ((float) linear_get_int(e,v))/0x10000, e->sample_spec.format, n, fs);
+
switch (e->sample_spec.format) {
case PA_SAMPLE_U8: {
- uint8_t *t;
+ uint8_t *d, *s;
+ unsigned channel;
+ int32_t factor = linear_get_int(e, v);
- for (t = p; n > 0; n -= fs) {
- int32_t factor = linear_get_int(e, v);
- unsigned c;
- e->x += fs;
+ s = (uint8_t*) p + n;
- for (c = 0; c < e->sample_spec.channels; c++, t++)
- *t = (uint8_t) (((factor * ((int16_t) *t - 0x80)) / 0x10000) + 0x80);
+ for (channel = 0, d = p; d < s; d++) {
+ int32_t t, hi, lo;
+
+ hi = factor >> 16;
+ lo = factor & 0xFFFF;
+
+ t = (int32_t) *d - 0x80;
+ t = ((t * lo) >> 16) + (t * hi);
+ t = PA_CLAMP_UNLIKELY(t, -0x80, 0x7F);
+ *d = (uint8_t) (t + 0x80);
+
+ if (PA_UNLIKELY(++channel >= e->sample_spec.channels)) {
+ channel = 0;
+ e->x += fs;
+ factor = linear_get_int(e, v);
+ }
}
break;
}
case PA_SAMPLE_ULAW: {
- uint8_t *t;
+ uint8_t *d, *s;
+ unsigned channel;
+ int32_t factor = linear_get_int(e, v);
- for (t = p; n > 0; n -= fs) {
- int32_t factor = linear_get_int(e, v);
- unsigned c;
- e->x += fs;
+ s = (uint8_t*) p + n;
- for (c = 0; c < e->sample_spec.channels; c++, t++) {
- int16_t k = st_ulaw2linear16(*t);
- *t = (uint8_t) st_14linear2ulaw((int16_t) (((factor * k) / 0x10000) >> 2));
+ for (channel = 0, d = p; d < s; d++) {
+ int32_t t, hi, lo;
+
+ hi = factor >> 16;
+ lo = factor & 0xFFFF;
+
+ t = (int32_t) st_ulaw2linear16(*d);
+ t = ((t * lo) >> 16) + (t * hi);
+ t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
+ *d = (uint8_t) st_14linear2ulaw((int16_t) t >> 2);
+
+ if (PA_UNLIKELY(++channel >= e->sample_spec.channels)) {
+ channel = 0;
+ e->x += fs;
+ factor = linear_get_int(e, v);
}
}
@@ -632,16 +658,27 @@ void pa_envelope_apply(pa_envelope *e, pa_memchunk *chunk) {
}
case PA_SAMPLE_ALAW: {
- uint8_t *t;
+ uint8_t *d, *s;
+ unsigned channel;
+ int32_t factor = linear_get_int(e, v);
- for (t = p; n > 0; n -= fs) {
- int32_t factor = linear_get_int(e, v);
- unsigned c;
- e->x += fs;
+ s = (uint8_t*) p + n;
- for (c = 0; c < e->sample_spec.channels; c++, t++) {
- int16_t k = st_alaw2linear16(*t);
- *t = (uint8_t) st_13linear2alaw((int16_t) (((factor * k) / 0x10000) >> 3));
+ for (channel = 0, d = p; d < s; d++) {
+ int32_t t, hi, lo;
+
+ hi = factor >> 16;
+ lo = factor & 0xFFFF;
+
+ t = (int32_t) st_alaw2linear16(*d);
+ t = ((t * lo) >> 16) + (t * hi);
+ t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
+ *d = (uint8_t) st_13linear2alaw((int16_t) t >> 3);
+
+ if (PA_UNLIKELY(++channel >= e->sample_spec.channels)) {
+ channel = 0;
+ e->x += fs;
+ factor = linear_get_int(e, v);
}
}
@@ -649,31 +686,55 @@ void pa_envelope_apply(pa_envelope *e, pa_memchunk *chunk) {
}
case PA_SAMPLE_S16NE: {
- int16_t *t;
+ int16_t *d, *s;
+ unsigned channel;
+ int32_t factor = linear_get_int(e, v);
- for (t = p; n > 0; n -= fs) {
- int32_t factor = linear_get_int(e, v);
- unsigned c;
- e->x += fs;
+ s = (int16_t*) p + n/sizeof(int16_t);
- for (c = 0; c < e->sample_spec.channels; c++, t++)
- *t = (int16_t) ((factor * *t) / 0x10000);
+ for (channel = 0, d = p; d < s; d++) {
+ int32_t t, hi, lo;
+
+ hi = factor >> 16;
+ lo = factor & 0xFFFF;
+
+ t = (int32_t)(*d);
+ t = ((t * lo) >> 16) + (t * hi);
+ t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
+ *d = (int16_t) t;
+
+ if (PA_UNLIKELY(++channel >= e->sample_spec.channels)) {
+ channel = 0;
+ e->x += fs;
+ factor = linear_get_int(e, v);
+ }
}
break;
}
case PA_SAMPLE_S16RE: {
- int16_t *t;
+ int16_t *d, *s;
+ unsigned channel;
+ int32_t factor = linear_get_int(e, v);
- for (t = p; n > 0; n -= fs) {
- int32_t factor = linear_get_int(e, v);
- unsigned c;
- e->x += fs;
+ s = (int16_t*) p + n/sizeof(int16_t);
- for (c = 0; c < e->sample_spec.channels; c++, t++) {
- int16_t r = (int16_t) ((factor * PA_INT16_SWAP(*t)) / 0x10000);
- *t = PA_INT16_SWAP(r);
+ for (channel = 0, d = p; d < s; d++) {
+ int32_t t, hi, lo;
+
+ hi = factor >> 16;
+ lo = factor & 0xFFFF;
+
+ t = (int32_t) PA_INT16_SWAP(*d);
+ t = ((t * lo) >> 16) + (t * hi);
+ t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
+ *d = PA_INT16_SWAP((int16_t) t);
+
+ if (PA_UNLIKELY(++channel >= e->sample_spec.channels)) {
+ channel = 0;
+ e->x += fs;
+ factor = linear_get_int(e, v);
}
}
@@ -681,31 +742,49 @@ void pa_envelope_apply(pa_envelope *e, pa_memchunk *chunk) {
}
case PA_SAMPLE_S32NE: {
- int32_t *t;
+ int32_t *d, *s;
+ unsigned channel;
+ int32_t factor = linear_get_int(e, v);
- for (t = p; n > 0; n -= fs) {
- int32_t factor = linear_get_int(e, v);
- unsigned c;
- e->x += fs;
+ s = (int32_t*) p + n/sizeof(int32_t);
- for (c = 0; c < e->sample_spec.channels; c++, t++)
- *t = (int32_t) (((int64_t) factor * (int64_t) *t) / 0x10000);
+ for (channel = 0, d = p; d < s; d++) {
+ int64_t t;
+
+ t = (int64_t)(*d);
+ t = (t * factor) >> 16;
+ t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL);
+ *d = (int32_t) t;
+
+ if (PA_UNLIKELY(++channel >= e->sample_spec.channels)) {
+ channel = 0;
+ e->x += fs;
+ factor = linear_get_int(e, v);
+ }
}
break;
}
case PA_SAMPLE_S32RE: {
- int32_t *t;
+ int32_t *d, *s;
+ unsigned channel;
+ int32_t factor = linear_get_int(e, v);
- for (t = p; n > 0; n -= fs) {
- int32_t factor = linear_get_int(e, v);
- unsigned c;
- e->x += fs;
+ s = (int32_t*) p + n/sizeof(int32_t);
- for (c = 0; c < e->sample_spec.channels; c++, t++) {
- int32_t r = (int32_t) (((int64_t) factor * (int64_t) PA_INT32_SWAP(*t)) / 0x10000);
- *t = PA_INT32_SWAP(r);
+ for (channel = 0, d = p; d < s; d++) {
+ int64_t t;
+
+ t = (int64_t) PA_INT32_SWAP(*d);
+ t = (t * factor) >> 16;
+ t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL);
+ *d = PA_INT32_SWAP((int32_t) t);
+
+ if (PA_UNLIKELY(++channel >= e->sample_spec.channels)) {
+ channel = 0;
+ e->x += fs;
+ factor = linear_get_int(e, v);
}
}
@@ -713,6 +792,7 @@ void pa_envelope_apply(pa_envelope *e, pa_memchunk *chunk) {
}
case PA_SAMPLE_FLOAT32NE: {
+ /*Seems the FLOAT32NE part of pa_volume_memchunk not right, do not reuse here*/
float *t;
for (t = p; n > 0; n -= fs) {
@@ -728,6 +808,7 @@ void pa_envelope_apply(pa_envelope *e, pa_memchunk *chunk) {
}
case PA_SAMPLE_FLOAT32RE: {
+ /*Seems the FLOAT32RE part of pa_volume_memchunk not right, do not reuse here*/
float *t;
for (t = p; n > 0; n -= fs) {
@@ -744,10 +825,101 @@ void pa_envelope_apply(pa_envelope *e, pa_memchunk *chunk) {
break;
}
- case PA_SAMPLE_S24LE:
- case PA_SAMPLE_S24BE:
- case PA_SAMPLE_S24_32LE:
- case PA_SAMPLE_S24_32BE:
+ case PA_SAMPLE_S24NE: {
+ uint8_t *d, *s;
+ unsigned channel;
+ int32_t factor = linear_get_int(e, v);
+
+ s = (uint8_t*) p + n/3;
+
+ for (channel = 0, d = p; d < s; d++) {
+ int64_t t;
+
+ t = (int64_t)((int32_t) (PA_READ24NE(d) << 8));
+ t = (t * factor) >> 16;
+ t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL);
+ PA_WRITE24NE(d, ((uint32_t) (int32_t) t) >> 8);
+
+ if (PA_UNLIKELY(++channel >= e->sample_spec.channels)) {
+ channel = 0;
+ e->x += fs;
+ factor = linear_get_int(e, v);
+ }
+ }
+
+ break;
+ }
+ case PA_SAMPLE_S24RE: {
+ uint8_t *d, *s;
+ unsigned channel;
+ int32_t factor = linear_get_int(e, v);
+
+ s = (uint8_t*) p + n/3;
+
+ for (channel = 0, d = p; d < s; d++) {
+ int64_t t;
+
+ t = (int64_t)((int32_t) (PA_READ24RE(d) << 8));
+ t = (t * factor) >> 16;
+ t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL);
+ PA_WRITE24RE(d, ((uint32_t) (int32_t) t) >> 8);
+
+ if (PA_UNLIKELY(++channel >= e->sample_spec.channels)) {
+ channel = 0;
+ e->x += fs;
+ factor = linear_get_int(e, v);
+ }
+ }
+
+ break;
+ }
+ case PA_SAMPLE_S24_32NE: {
+ uint32_t *d, *s;
+ unsigned channel;
+ int32_t factor = linear_get_int(e, v);
+
+ s = (uint32_t*) p + n/sizeof(uint32_t);
+
+ for (channel = 0, d = p; d < s; d++) {
+ int64_t t;
+
+ t = (int64_t) ((int32_t) (*d << 8));
+ t = (t * factor) >> 16;
+ t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL);
+ *d = ((uint32_t) ((int32_t) t)) >> 8;
+
+ if (PA_UNLIKELY(++channel >= e->sample_spec.channels)) {
+ channel = 0;
+ e->x += fs;
+ factor = linear_get_int(e, v);
+ }
+ }
+
+ break;
+ }
+ case PA_SAMPLE_S24_32RE: {
+ uint32_t *d, *s;
+ unsigned channel;
+ int32_t factor = linear_get_int(e, v);
+
+ s = (uint32_t*) p + n/sizeof(uint32_t);
+
+ for (channel = 0, d = p; d < s; d++) {
+ int64_t t;
+
+ t = (int64_t) ((int32_t) (PA_UINT32_SWAP(*d) << 8));
+ t = (t * factor) >> 16;
+ t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL);
+ *d = PA_UINT32_SWAP(((uint32_t) ((int32_t) t)) >> 8);
+
+ if (PA_UNLIKELY(++channel >= e->sample_spec.channels)) {
+ channel = 0;
+ e->x += fs;
+ factor = linear_get_int(e, v);
+ }
+ }
+ break;
+ }
/* FIXME */
pa_assert_not_reached();
@@ -757,8 +929,6 @@ void pa_envelope_apply(pa_envelope *e, pa_memchunk *chunk) {
}
pa_memblock_release(chunk->memblock);
-
- e->x += chunk->length;
} else {
/* When we have no envelope to apply we reset our origin */
e->x = 0;
@@ -774,13 +944,48 @@ void pa_envelope_rewind(pa_envelope *e, size_t n_bytes) {
envelope_begin_read(e, &v);
- if (n_bytes < e->x)
- e->x -= n_bytes;
+ if (e->x - n_bytes <= e->points[v].x[0])
+ e->x = e->points[v].x[0];
else
- e->x = 0;
+ e->x -= n_bytes;
e->points[v].n_current = 0;
e->points[v].cached_valid = FALSE;
envelope_commit_read(e, v);
}
+
+void pa_envelope_restart(pa_envelope* e) {
+ int v;
+ pa_assert(e);
+
+ envelope_begin_read(e, &v);
+ e->x = e->points[v].x[0];
+ envelope_commit_read(e, v);
+}
+
+pa_bool_t pa_envelope_is_finished(pa_envelope* e) {
+ pa_assert(e);
+
+ int v;
+ pa_bool_t finished;
+
+ envelope_begin_read(e, &v);
+ finished = (e->x >= e->points[v].x[e->points[v].n_points-1]);
+ envelope_commit_read(e, v);
+
+ return finished;
+}
+
+int32_t pa_envelope_length(pa_envelope *e) {
+ pa_assert(e);
+
+ int v;
+ size_t size;
+
+ envelope_begin_read(e, &v);
+ size = e->points[v].x[e->points[v].n_points-1] - e->points[v].x[0];
+ envelope_commit_read(e, v);
+
+ return size;
+}
diff --git a/src/pulsecore/envelope.h b/src/pulsecore/envelope.h
index 5296415..4fa3657 100644
--- a/src/pulsecore/envelope.h
+++ b/src/pulsecore/envelope.h
@@ -49,5 +49,8 @@ pa_envelope_item *pa_envelope_replace(pa_envelope *e, pa_envelope_item *i, const
void pa_envelope_remove(pa_envelope *e, pa_envelope_item *i);
void pa_envelope_apply(pa_envelope *e, pa_memchunk *chunk);
void pa_envelope_rewind(pa_envelope *e, size_t n_bytes);
+void pa_envelope_restart(pa_envelope* e);
+pa_bool_t pa_envelope_is_finished(pa_envelope* e);
+int32_t pa_envelope_length(pa_envelope *e);
#endif
commit 5318eb35ef3f91836084382a4f3d5ef08d322554
Author: zbt <huan.zheng at intel.com>
Date: Thu Jul 16 10:41:34 2009 +0800
Add volume ramping feature - sink-input modification
diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index a5f9635..2acaa08 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -38,6 +38,7 @@
#include <pulsecore/play-memblockq.h>
#include <pulsecore/namereg.h>
#include <pulsecore/core-util.h>
+#include <pulse/timeval.h>
#include "sink-input.h"
@@ -47,6 +48,11 @@
static PA_DEFINE_CHECK_TYPE(pa_sink_input, pa_msgobject);
static void sink_input_free(pa_object *o);
+static void sink_input_set_ramping_info(pa_sink_input* i, pa_volume_t pre_virtual_volume, pa_volume_t target_virtual_volume, pa_usec_t t);
+static void sink_input_set_ramping_info_for_mute(pa_sink_input* i, pa_bool_t mute, pa_usec_t t);
+static void sink_input_volume_ramping(pa_sink_input* i, pa_memchunk* chunk);
+static void sink_input_rewind_ramp_info(pa_sink_input *i, size_t nbytes);
+static void sink_input_release_envelope(pa_sink_input *i);
pa_sink_input_new_data* pa_sink_input_new_data_init(pa_sink_input_new_data *data) {
pa_assert(data);
@@ -301,6 +307,16 @@ int pa_sink_input_new(
reset_callbacks(i);
i->userdata = NULL;
+ /* Set Ramping info */
+ i->thread_info.ramp_info.is_ramping = FALSE;
+ i->thread_info.ramp_info.envelope_dead = TRUE;
+ i->thread_info.ramp_info.envelope = NULL;
+ i->thread_info.ramp_info.item = NULL;
+ i->thread_info.ramp_info.envelope_dying = 0;
+
+ pa_atomic_store(&i->before_ramping_v, 0);
+ pa_atomic_store(&i->before_ramping_m, 0);
+
i->thread_info.state = i->state;
i->thread_info.attached = FALSE;
pa_atomic_store(&i->thread_info.drained, 1);
@@ -480,6 +496,12 @@ static void sink_input_free(pa_object *o) {
pa_assert(!i->thread_info.attached);
+ if (i->thread_info.ramp_info.envelope) {
+ pa_log_debug ("Freeing envelope\n");
+ pa_envelope_free(i->thread_info.ramp_info.envelope);
+ i->thread_info.ramp_info.envelope = NULL;
+ }
+
if (i->thread_info.render_memblockq)
pa_memblockq_free(i->thread_info.render_memblockq);
@@ -565,6 +587,7 @@ pa_usec_t pa_sink_input_get_latency(pa_sink_input *i, pa_usec_t *sink_latency) {
void pa_sink_input_peek(pa_sink_input *i, size_t slength /* in sink frames */, pa_memchunk *chunk, pa_cvolume *volume) {
pa_bool_t do_volume_adj_here;
pa_bool_t volume_is_norm;
+ pa_bool_t ramping;
size_t block_size_max_sink, block_size_max_sink_input;
size_t ilength;
@@ -608,7 +631,7 @@ void pa_sink_input_peek(pa_sink_input *i, size_t slength /* in sink frames */, p
* to adjust the volume *before* we resample. Otherwise we can do
* it after and leave it for the sink code */
- do_volume_adj_here = !pa_channel_map_equal(&i->channel_map, &i->sink->channel_map);
+ do_volume_adj_here = !pa_channel_map_equal(&i->channel_map, &i->sink->channel_map) || i->thread_info.ramp_info.is_ramping;
volume_is_norm = pa_cvolume_is_norm(&i->thread_info.soft_volume) && !i->thread_info.muted;
while (!pa_memblockq_is_readable(i->thread_info.render_memblockq)) {
@@ -649,7 +672,7 @@ void pa_sink_input_peek(pa_sink_input *i, size_t slength /* in sink frames */, p
wchunk.length = block_size_max_sink_input;
/* It might be necessary to adjust the volume here */
- if (do_volume_adj_here && !volume_is_norm) {
+ if (do_volume_adj_here && !volume_is_norm && !i->thread_info.ramp_info.is_ramping) {
pa_memchunk_make_writable(&wchunk, 0);
if (i->thread_info.muted)
@@ -691,6 +714,23 @@ void pa_sink_input_peek(pa_sink_input *i, size_t slength /* in sink frames */, p
if (chunk->length > block_size_max_sink)
chunk->length = block_size_max_sink;
+ ramping = i->thread_info.ramp_info.is_ramping;
+ if (ramping)
+ sink_input_volume_ramping(i, chunk);
+
+ if (!i->thread_info.ramp_info.envelope_dead) {
+ i->thread_info.ramp_info.envelope_dying += chunk->length;
+ pa_log_debug("Envelope dying is %d, chunk length is %d, dead thresholder is %d\n", i->thread_info.ramp_info.envelope_dying,
+ chunk->length,
+ i->sink->thread_info.max_rewind + pa_envelope_length(i->thread_info.ramp_info.envelope));
+
+ if (i->thread_info.ramp_info.envelope_dying >= (i->sink->thread_info.max_rewind + pa_envelope_length(i->thread_info.ramp_info.envelope))) {
+ pa_log_debug("RELEASE Envelop");
+ i->thread_info.ramp_info.envelope_dead = TRUE;
+ sink_input_release_envelope(i);
+ }
+ }
+
/* Let's see if we had to apply the volume adjustment ourselves,
* or if this can be done by the sink for us */
@@ -733,6 +773,7 @@ void pa_sink_input_process_rewind(pa_sink_input *i, size_t nbytes /* in sink sam
if (nbytes > 0 && !i->thread_info.dont_rewind_render) {
pa_log_debug("Have to rewind %lu bytes on render memblockq.", (unsigned long) nbytes);
pa_memblockq_rewind(i->thread_info.render_memblockq, nbytes);
+ sink_input_rewind_ramp_info(i, nbytes);
}
if (i->thread_info.rewrite_nbytes == (size_t) -1) {
@@ -873,50 +914,8 @@ pa_usec_t pa_sink_input_get_requested_latency(pa_sink_input *i) {
/* Called from main context */
void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute) {
- pa_cvolume v;
-
- pa_sink_input_assert_ref(i);
- pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
- pa_assert(volume);
- pa_assert(pa_cvolume_valid(volume));
- pa_assert(pa_cvolume_compatible(volume, &i->sample_spec));
-
- if ((i->sink->flags & PA_SINK_FLAT_VOLUME) && !absolute) {
- v = i->sink->reference_volume;
- pa_cvolume_remap(&v, &i->sink->channel_map, &i->channel_map);
- volume = pa_sw_cvolume_multiply(&v, &v, volume);
- }
-
- if (pa_cvolume_equal(volume, &i->virtual_volume))
- return;
-
- i->virtual_volume = *volume;
- i->save_volume = save;
-
- if (i->sink->flags & PA_SINK_FLAT_VOLUME) {
- pa_cvolume new_volume;
-
- /* We are in flat volume mode, so let's update all sink input
- * volumes and update the flat volume of the sink */
-
- pa_sink_update_flat_volume(i->sink, &new_volume);
- pa_sink_set_volume(i->sink, &new_volume, FALSE, TRUE, FALSE, FALSE);
-
- } else {
-
- /* OK, we are in normal volume mode. The volume only affects
- * ourselves */
- pa_sink_input_set_relative_volume(i, volume);
-
- /* Hooks have the ability to play games with i->soft_volume */
- pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_SET_VOLUME], i);
-
- /* Copy the new soft_volume to the thread_info struct */
- pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0);
- }
-
- /* The virtual volume changed, let's tell people so */
- pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
+ /* test ramping -> return pa_sink_input_set_volume_with_ramping(i, volume, save, absolute, 2000 * PA_USEC_PER_MSEC); */
+ return pa_sink_input_set_volume_with_ramping(i, volume, save, absolute, 0);
}
/* Called from main context */
@@ -985,18 +984,8 @@ void pa_sink_input_set_relative_volume(pa_sink_input *i, const pa_cvolume *v) {
/* Called from main context */
void pa_sink_input_set_mute(pa_sink_input *i, pa_bool_t mute, pa_bool_t save) {
- pa_assert(i);
- pa_sink_input_assert_ref(i);
- pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
-
- if (!i->muted == !mute)
- return;
-
- i->muted = mute;
- i->save_muted = save;
-
- pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_MUTE, NULL, 0, NULL) == 0);
- pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
+ /* test ramping -> return pa_sink_input_set_mute_with_ramping(i, mute, save, 2000 * PA_USEC_PER_MSEC); */
+ return pa_sink_input_set_mute_with_ramping(i, mute, save, 0);
}
/* Called from main context */
@@ -1347,15 +1336,23 @@ int pa_sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t
switch (code) {
case PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME:
+ if (pa_atomic_load(&i->before_ramping_v))
+ i->thread_info.future_soft_volume = i->soft_volume;
+
if (!pa_cvolume_equal(&i->thread_info.soft_volume, &i->soft_volume)) {
- i->thread_info.soft_volume = i->soft_volume;
+ if (!pa_atomic_load(&i->before_ramping_v))
+ i->thread_info.soft_volume = i->soft_volume;
pa_sink_input_request_rewind(i, 0, TRUE, FALSE, FALSE);
}
return 0;
case PA_SINK_INPUT_MESSAGE_SET_SOFT_MUTE:
+ if (pa_atomic_load(&i->before_ramping_m))
+ i->thread_info.future_muted = i->muted;
+
if (i->thread_info.muted != i->muted) {
- i->thread_info.muted = i->muted;
+ if (!pa_atomic_load(&i->before_ramping_m))
+ i->thread_info.muted = i->muted;
pa_sink_input_request_rewind(i, 0, TRUE, FALSE, FALSE);
}
return 0;
@@ -1403,6 +1400,26 @@ int pa_sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t
*r = i->thread_info.requested_sink_latency;
return 0;
}
+
+ case PA_SINK_INPUT_MESSAGE_SET_ENVELOPE: {
+ if (!i->thread_info.ramp_info.envelope)
+ i->thread_info.ramp_info.envelope = pa_envelope_new(&i->sink->sample_spec);
+
+ if (i->thread_info.ramp_info.envelope && i->thread_info.ramp_info.item) {
+ pa_envelope_remove(i->thread_info.ramp_info.envelope, i->thread_info.ramp_info.item);
+ i->thread_info.ramp_info.item = NULL;
+ }
+
+ i->thread_info.ramp_info.item = pa_envelope_add(i->thread_info.ramp_info.envelope, &i->using_def);
+ i->thread_info.ramp_info.is_ramping = TRUE;
+ i->thread_info.ramp_info.envelope_dead = FALSE;
+ i->thread_info.ramp_info.envelope_dying = 0;
+
+ if (i->thread_info.ramp_info.envelope)
+ pa_envelope_restart(i->thread_info.ramp_info.envelope);
+
+ return 0;
+ }
}
return -PA_ERR_NOTIMPLEMENTED;
@@ -1550,3 +1567,217 @@ finish:
if (pl)
pa_proplist_free(pl);
}
+
+/* Called from IO context */
+static void sink_input_volume_ramping(pa_sink_input* i, pa_memchunk* chunk) {
+ pa_assert(i);
+ pa_assert(chunk);
+ pa_assert(chunk->memblock);
+ pa_assert(i->thread_info.ramp_info.is_ramping);
+
+ /* Volume is adjusted with ramping effect here */
+ pa_envelope_apply(i->thread_info.ramp_info.envelope, chunk);
+
+ if (pa_envelope_is_finished(i->thread_info.ramp_info.envelope)) {
+ i->thread_info.ramp_info.is_ramping = FALSE;
+ if (pa_atomic_load(&i->before_ramping_v)) {
+ i->thread_info.soft_volume = i->thread_info.future_soft_volume;
+ pa_atomic_store(&i->before_ramping_v, 0);
+ }
+ else if (pa_atomic_load(&i->before_ramping_m)) {
+ i->thread_info.muted = i->thread_info.future_muted;
+ pa_atomic_store(&i->before_ramping_m, 0);
+ }
+ }
+}
+
+/*
+ * Called from main context
+ * This function should be called inside pa_sink_input_set_volume_with_ramping
+ * should be called after soft_volume of sink_input and sink are all adjusted
+ */
+static void sink_input_set_ramping_info(pa_sink_input* i, pa_volume_t pre_virtual_volume, pa_volume_t target_virtual_volume, pa_usec_t t) {
+
+ int32_t target_abs_vol, target_apply_vol, pre_apply_vol;
+ pa_assert(i);
+
+ pa_log_debug("Sink input's soft volume is %d= %f ", pa_cvolume_avg(&i->soft_volume), pa_sw_volume_to_linear(pa_cvolume_avg(&i->soft_volume)));
+
+ /* Calculation formula are target_abs_vol := i->soft_volume
+ * target_apply_vol := lrint(pa_sw_volume_to_linear(target_abs_vol) * 0x10000)
+ * pre_apply_vol := ( previous_virtual_volume / target_virtual_volume ) * target_apply_vol
+ *
+ * Will do volume adjustment inside pa_sink_input_peek
+ */
+ target_abs_vol = pa_cvolume_avg(&i->soft_volume);
+ target_apply_vol = (int32_t) lrint(pa_sw_volume_to_linear(target_abs_vol) * 0x10000);
+ pre_apply_vol = (int32_t) ((pa_sw_volume_to_linear(pre_virtual_volume) / pa_sw_volume_to_linear(target_virtual_volume)) * target_apply_vol);
+
+ i->using_def.n_points = 2;
+ i->using_def.points_x[0] = 0;
+ i->using_def.points_x[1] = t;
+ i->using_def.points_y.i[0] = pre_apply_vol;
+ i->using_def.points_y.i[1] = target_apply_vol;
+ i->using_def.points_y.f[0] = ((float) i->using_def.points_y.i[0]) /0x10000;
+ i->using_def.points_y.f[1] = ((float) i->using_def.points_y.i[1]) /0x10000;
+
+ pa_log_debug("Volume Ramping: Point 1 is %d=%f, Point 2 is %d=%f\n", i->using_def.points_y.i[0], i->using_def.points_y.f[0],
+ i->using_def.points_y.i[1], i->using_def.points_y.f[1]);
+
+ pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_ENVELOPE, NULL, 0, NULL) == 0);
+}
+
+/* Called from main context */
+static void sink_input_set_ramping_info_for_mute(pa_sink_input* i, pa_bool_t mute, pa_usec_t t) {
+
+ int32_t cur_vol;
+ pa_assert(i);
+
+ i->using_def.n_points = 2;
+ i->using_def.points_x[0] = 0;
+ i->using_def.points_x[1] = t;
+ cur_vol = (int32_t) lrint( pa_sw_volume_to_linear(pa_cvolume_avg(&i->soft_volume)) * 0x10000);
+
+ if (mute) {
+ i->using_def.points_y.i[0] = cur_vol;
+ i->using_def.points_y.i[1] = 0;
+ } else {
+ i->using_def.points_y.i[0] = 0;
+ i->using_def.points_y.i[1] = cur_vol;
+ }
+
+ i->using_def.points_y.f[0] = ((float) i->using_def.points_y.i[0]) /0x10000;
+ i->using_def.points_y.f[1] = ((float) i->using_def.points_y.i[1]) /0x10000;
+
+ pa_log_debug("Mute Ramping: Point 1 is %d=%f, Point 2 is %d=%f\n", i->using_def.points_y.i[0], i->using_def.points_y.f[0],
+ i->using_def.points_y.i[1], i->using_def.points_y.f[1]);
+
+ pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_ENVELOPE, NULL, 0, NULL) == 0);
+}
+
+/* Called from IO context */
+static void sink_input_release_envelope(pa_sink_input *i) {
+ pa_assert(i);
+ pa_assert(!i->thread_info.ramp_info.is_ramping);
+ pa_assert(i->thread_info.ramp_info.envelope_dead);
+
+ pa_envelope_free(i->thread_info.ramp_info.envelope);
+ i->thread_info.ramp_info.envelope = NULL;
+ i->thread_info.ramp_info.item = NULL;
+}
+
+/* Called from IO context */
+static void sink_input_rewind_ramp_info(pa_sink_input *i, size_t nbytes) {
+ pa_assert(i);
+
+ if (!i->thread_info.ramp_info.envelope_dead) {
+ pa_assert(i->thread_info.ramp_info.envelope);
+
+ int32_t envelope_length = pa_envelope_length(i->thread_info.ramp_info.envelope);
+
+ if (i->thread_info.ramp_info.envelope_dying > envelope_length) {
+ if ((i->thread_info.ramp_info.envelope_dying - nbytes) < envelope_length) {
+ pa_log_debug("Envelope Become Alive");
+ pa_envelope_rewind(i->thread_info.ramp_info.envelope, envelope_length - (i->thread_info.ramp_info.envelope_dying - nbytes));
+ i->thread_info.ramp_info.is_ramping = TRUE;
+ }
+ } else if (i->thread_info.ramp_info.envelope_dying < envelope_length) {
+ if ((i->thread_info.ramp_info.envelope_dying - nbytes) <= 0) {
+ pa_log_debug("Envelope Restart");
+ pa_envelope_restart(i->thread_info.ramp_info.envelope);
+ }
+ else {
+ pa_log_debug("Envelope Simple Rewind");
+ pa_envelope_rewind(i->thread_info.ramp_info.envelope, nbytes);
+ }
+ }
+
+ i->thread_info.ramp_info.envelope_dying -= nbytes;
+ if (i->thread_info.ramp_info.envelope_dying <= 0)
+ i->thread_info.ramp_info.envelope_dying = 0;
+ }
+}
+
+void pa_sink_input_set_volume_with_ramping(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute, pa_usec_t t){
+ pa_cvolume v;
+ pa_volume_t previous_virtual_volume, target_virtual_volume;
+ pa_sink_input_assert_ref(i);
+
+ pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
+ pa_assert(volume);
+ pa_assert(pa_cvolume_valid(volume));
+ pa_assert(pa_cvolume_compatible(volume, &i->sample_spec));
+
+ if ((i->sink->flags & PA_SINK_FLAT_VOLUME) && !absolute) {
+ v = i->sink->reference_volume;
+ pa_cvolume_remap(&v, &i->sink->channel_map, &i->channel_map);
+ volume = pa_sw_cvolume_multiply(&v, &v, volume);
+ }
+
+ if (pa_cvolume_equal(volume, &i->virtual_volume))
+ return;
+
+ previous_virtual_volume = pa_cvolume_avg(&i->virtual_volume);
+ target_virtual_volume = pa_cvolume_avg(volume);
+ if (t > 0 && target_virtual_volume > 0)
+ pa_log_debug("SetVolumeWithRamping: Virtual Volume From %u=%f to %u=%f\n", previous_virtual_volume, pa_sw_volume_to_linear(previous_virtual_volume),
+ target_virtual_volume, pa_sw_volume_to_linear(target_virtual_volume));
+
+ i->virtual_volume = *volume;
+ i->save_volume = save;
+
+ /* Set this flag before the following code modify i->thread_info.soft_volume */
+ if (t > 0 && target_virtual_volume > 0)
+ pa_atomic_store(&i->before_ramping_v, 1);
+
+ if (i->sink->flags & PA_SINK_FLAT_VOLUME) {
+ pa_cvolume new_volume;
+
+ /* We are in flat volume mode, so let's update all sink input
+ * volumes and update the flat volume of the sink */
+
+ pa_sink_update_flat_volume(i->sink, &new_volume);
+ pa_sink_set_volume(i->sink, &new_volume, FALSE, TRUE, FALSE, FALSE);
+
+ } else {
+
+ /* OK, we are in normal volume mode. The volume only affects
+ * ourselves */
+ pa_sink_input_set_relative_volume(i, volume);
+
+ /* Hooks have the ability to play games with i->soft_volume */
+ pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_SET_VOLUME], i);
+
+ /* Copy the new soft_volume to the thread_info struct */
+ pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0);
+ }
+
+ if (t > 0 && target_virtual_volume > 0)
+ sink_input_set_ramping_info(i, previous_virtual_volume, target_virtual_volume, t);
+
+ /* The virtual volume changed, let's tell people so */
+ pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
+}
+
+void pa_sink_input_set_mute_with_ramping(pa_sink_input *i, pa_bool_t mute, pa_bool_t save, pa_usec_t t){
+
+ pa_assert(i);
+ pa_sink_input_assert_ref(i);
+ pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
+
+ if (!i->muted == !mute)
+ return;
+
+ i->muted = mute;
+ i->save_muted = save;
+ /* Set this flag before the following code modify i->thread_info.muted, otherwise distortion will be heard */
+ if (t > 0)
+ pa_atomic_store(&i->before_ramping_m, 1);
+
+ pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_MUTE, NULL, 0, NULL) == 0);
+
+ if (t > 0)
+ sink_input_set_ramping_info_for_mute(i, mute, t);
+
+ pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
+}
diff --git a/src/pulsecore/sink-input.h b/src/pulsecore/sink-input.h
index 98144d4..036806f 100644
--- a/src/pulsecore/sink-input.h
+++ b/src/pulsecore/sink-input.h
@@ -35,6 +35,7 @@ typedef struct pa_sink_input pa_sink_input;
#include <pulsecore/client.h>
#include <pulsecore/sink.h>
#include <pulsecore/core.h>
+#include <pulsecore/envelope.h>
typedef enum pa_sink_input_state {
PA_SINK_INPUT_INIT, /*< The stream is not active yet, because pa_sink_put() has not been called yet */
@@ -212,8 +213,23 @@ struct pa_sink_input {
pa_usec_t requested_sink_latency;
pa_hashmap *direct_outputs;
+
+ struct {
+ pa_bool_t is_ramping:1;
+ pa_bool_t envelope_dead:1;
+ int32_t envelope_dying; /* Increasing while envelop is not dead. Reduce it while process_rewind. */
+ pa_envelope *envelope;
+ pa_envelope_item *item;
+ } ramp_info;
+ pa_cvolume future_soft_volume;
+ pa_bool_t future_muted;
+
} thread_info;
+ pa_atomic_t before_ramping_v; /* Indicates future volume */
+ pa_atomic_t before_ramping_m; /* Indicates future mute */
+ pa_envelope_def using_def;
+
void *userdata;
};
@@ -228,6 +244,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_ENVELOPE,
PA_SINK_INPUT_MESSAGE_MAX
};
@@ -359,4 +376,8 @@ pa_memchunk* pa_sink_input_get_silence(pa_sink_input *i, pa_memchunk *ret);
/* To be used by sink.c only */
void pa_sink_input_set_relative_volume(pa_sink_input *i, const pa_cvolume *v);
+/* Volume ramping*/
+void pa_sink_input_set_volume_with_ramping(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute, pa_usec_t t);
+void pa_sink_input_set_mute_with_ramping(pa_sink_input *i, pa_bool_t mute, pa_bool_t save, pa_usec_t t);
+
#endif
commit 897ef86b7fbb87ef17d30c584e6cd93abfc342bc
Author: zbt <huan.zheng at intel.com>
Date: Thu Jul 16 10:41:58 2009 +0800
Add volume ramping feature - sink modification
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index d8f3c7d..2950071 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -1599,10 +1599,14 @@ static void sync_input_volumes_within_thread(pa_sink *s) {
pa_sink_assert_ref(s);
while ((i = PA_SINK_INPUT(pa_hashmap_iterate(s->thread_info.inputs, &state, NULL)))) {
+ if (pa_atomic_load(&i->before_ramping_v))
+ i->thread_info.future_soft_volume = i->soft_volume;
+
if (pa_cvolume_equal(&i->thread_info.soft_volume, &i->soft_volume))
continue;
- i->thread_info.soft_volume = i->soft_volume;
+ if (!pa_atomic_load(&i->before_ramping_v))
+ i->thread_info.soft_volume = i->soft_volume;
pa_sink_input_request_rewind(i, 0, TRUE, FALSE, FALSE);
}
}
commit 4d62f159a74c6e5b46be5823483a7dedd5691b45
Merge: 721e32b 897ef86
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Nov 5 22:54:42 2009 +0100
Merge remote branch 'origin/merge-queue'
Conflicts:
src/pulsecore/sink-input.c
src/pulsecore/sink.c
diff --cc src/pulsecore/sink-input.c
index 1af2823,2acaa08..216edd4
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@@ -44,10 -45,14 +45,15 @@@
#define MEMBLOCKQ_MAXLENGTH (32*1024*1024)
#define CONVERT_BUFFER_LENGTH (PA_PAGE_SIZE)
-static PA_DEFINE_CHECK_TYPE(pa_sink_input, pa_msgobject);
+PA_DEFINE_PUBLIC_CLASS(pa_sink_input, pa_msgobject);
static void sink_input_free(pa_object *o);
+static void set_real_ratio(pa_sink_input *i, const pa_cvolume *v);
+ static void sink_input_set_ramping_info(pa_sink_input* i, pa_volume_t pre_virtual_volume, pa_volume_t target_virtual_volume, pa_usec_t t);
+ static void sink_input_set_ramping_info_for_mute(pa_sink_input* i, pa_bool_t mute, pa_usec_t t);
+ static void sink_input_volume_ramping(pa_sink_input* i, pa_memchunk* chunk);
+ static void sink_input_rewind_ramp_info(pa_sink_input *i, size_t nbytes);
+ static void sink_input_release_envelope(pa_sink_input *i);
pa_sink_input_new_data* pa_sink_input_new_data_init(pa_sink_input_new_data *data) {
pa_assert(data);
@@@ -505,11 -494,14 +521,17 @@@ static void sink_input_free(pa_object *
pa_log_info("Freeing input %u \"%s\"", i->index, pa_strnull(pa_proplist_gets(i->proplist, PA_PROP_MEDIA_NAME)));
- pa_assert(!i->thread_info.attached);
+ /* Side note: this function must be able to destruct properly any
+ * kind of sink input in any state, even those which are
+ * "half-moved" or are connected to sinks that have no asyncmsgq
+ * and are hence half-destructed themselves! */
+ if (i->thread_info.ramp_info.envelope) {
+ pa_log_debug ("Freeing envelope\n");
+ pa_envelope_free(i->thread_info.ramp_info.envelope);
+ i->thread_info.ramp_info.envelope = NULL;
+ }
+
if (i->thread_info.render_memblockq)
pa_memblockq_free(i->thread_info.render_memblockq);
@@@ -595,8 -585,9 +617,9 @@@ pa_usec_t pa_sink_input_get_latency(pa_
/* Called from thread context */
void pa_sink_input_peek(pa_sink_input *i, size_t slength /* in sink frames */, pa_memchunk *chunk, pa_cvolume *volume) {
- pa_bool_t do_volume_adj_here;
+ pa_bool_t do_volume_adj_here, need_volume_factor_sink;
pa_bool_t volume_is_norm;
+ pa_bool_t ramping;
size_t block_size_max_sink, block_size_max_sink_input;
size_t ilength;
@@@ -641,9 -631,8 +664,9 @@@
* to adjust the volume *before* we resample. Otherwise we can do
* it after and leave it for the sink code */
- do_volume_adj_here = !pa_channel_map_equal(&i->channel_map, &i->sink->channel_map);
+ do_volume_adj_here = !pa_channel_map_equal(&i->channel_map, &i->sink->channel_map) || i->thread_info.ramp_info.is_ramping;
volume_is_norm = pa_cvolume_is_norm(&i->thread_info.soft_volume) && !i->thread_info.muted;
+ need_volume_factor_sink = !pa_cvolume_is_norm(&i->volume_factor_sink);
while (!pa_memblockq_is_readable(i->thread_info.render_memblockq)) {
pa_memchunk tchunk;
@@@ -684,24 -672,12 +707,24 @@@
wchunk.length = block_size_max_sink_input;
/* It might be necessary to adjust the volume here */
- if (do_volume_adj_here && !volume_is_norm) {
+ if (do_volume_adj_here && !volume_is_norm && !i->thread_info.ramp_info.is_ramping) {
pa_memchunk_make_writable(&wchunk, 0);
- if (i->thread_info.muted)
+ if (i->thread_info.muted) {
pa_silence_memchunk(&wchunk, &i->thread_info.sample_spec);
- else
+ nvfs = FALSE;
+
+ } else if (!i->thread_info.resampler && nvfs) {
+ pa_cvolume v;
+
+ /* If we don't need a resampler we can merge the
+ * post and the pre volume adjustment into one */
+
+ pa_sw_cvolume_multiply(&v, &i->thread_info.soft_volume, &i->volume_factor_sink);
+ pa_volume_memchunk(&wchunk, &i->thread_info.sample_spec, &v);
+ nvfs = FALSE;
+
+ } else
pa_volume_memchunk(&wchunk, &i->thread_info.sample_spec, &i->thread_info.soft_volume);
}
@@@ -977,60 -934,22 +1018,9 @@@ static void set_real_ratio(pa_sink_inpu
}
/* Called from main context */
-pa_cvolume *pa_sink_input_get_relative_volume(pa_sink_input *i, pa_cvolume *v) {
- unsigned c;
-
- pa_sink_input_assert_ref(i);
- pa_assert(v);
- pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
-
- /* This always returns the relative volume. Converts the float
- * version into a pa_cvolume */
-
- v->channels = i->sample_spec.channels;
-
- for (c = 0; c < v->channels; c++)
- v->values[c] = pa_sw_volume_from_linear(i->relative_volume[c]);
-
- return v;
+void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute) {
- pa_cvolume v;
-
- pa_sink_input_assert_ref(i);
- pa_assert_ctl_context();
- pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
- pa_assert(volume);
- pa_assert(pa_cvolume_valid(volume));
- pa_assert(volume->channels == 1 || pa_cvolume_compatible(volume, &i->sample_spec));
-
- if ((i->sink->flags & PA_SINK_FLAT_VOLUME) && !absolute) {
- v = i->sink->reference_volume;
- pa_cvolume_remap(&v, &i->sink->channel_map, &i->channel_map);
-
- if (pa_cvolume_compatible(volume, &i->sample_spec))
- volume = pa_sw_cvolume_multiply(&v, &v, volume);
- else
- volume = pa_sw_cvolume_multiply_scalar(&v, &v, pa_cvolume_max(volume));
- } else {
-
- if (!pa_cvolume_compatible(volume, &i->sample_spec)) {
- v = i->volume;
- volume = pa_cvolume_scale(&v, pa_cvolume_max(volume));
- }
- }
-
- if (pa_cvolume_equal(volume, &i->volume)) {
- i->save_volume = i->save_volume || save;
- return;
- }
-
- i->volume = *volume;
- i->save_volume = save;
-
- if (i->sink->flags & PA_SINK_FLAT_VOLUME)
- /* We are in flat volume mode, so let's update all sink input
- * volumes and update the flat volume of the sink */
-
- pa_sink_set_volume(i->sink, NULL, TRUE, save);
-
- else {
- /* OK, we are in normal volume mode. The volume only affects
- * ourselves */
- set_real_ratio(i, volume);
-
- /* Copy the new soft_volume to the thread_info struct */
- pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0);
- }
-
- /* The volume changed, let's tell people so */
- if (i->volume_changed)
- i->volume_changed(i);
-
- pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
++ /* test ramping -> return pa_sink_input_set_volume_with_ramping(i, volume, save, absolute, 2000 * PA_USEC_PER_MSEC); */
++ return pa_sink_input_set_volume_with_ramping(i, volume, save, absolute, 0);
}
/* Called from main context */
@@@ -1659,3 -1567,217 +1662,227 @@@ finish
if (pl)
pa_proplist_free(pl);
}
+
+ /* Called from IO context */
+ static void sink_input_volume_ramping(pa_sink_input* i, pa_memchunk* chunk) {
+ pa_assert(i);
+ pa_assert(chunk);
+ pa_assert(chunk->memblock);
+ pa_assert(i->thread_info.ramp_info.is_ramping);
+
+ /* Volume is adjusted with ramping effect here */
+ pa_envelope_apply(i->thread_info.ramp_info.envelope, chunk);
+
+ if (pa_envelope_is_finished(i->thread_info.ramp_info.envelope)) {
+ i->thread_info.ramp_info.is_ramping = FALSE;
+ if (pa_atomic_load(&i->before_ramping_v)) {
+ i->thread_info.soft_volume = i->thread_info.future_soft_volume;
+ pa_atomic_store(&i->before_ramping_v, 0);
+ }
+ else if (pa_atomic_load(&i->before_ramping_m)) {
+ i->thread_info.muted = i->thread_info.future_muted;
+ pa_atomic_store(&i->before_ramping_m, 0);
+ }
+ }
+ }
+
+ /*
+ * Called from main context
+ * This function should be called inside pa_sink_input_set_volume_with_ramping
+ * should be called after soft_volume of sink_input and sink are all adjusted
+ */
+ static void sink_input_set_ramping_info(pa_sink_input* i, pa_volume_t pre_virtual_volume, pa_volume_t target_virtual_volume, pa_usec_t t) {
+
+ int32_t target_abs_vol, target_apply_vol, pre_apply_vol;
+ pa_assert(i);
+
+ pa_log_debug("Sink input's soft volume is %d= %f ", pa_cvolume_avg(&i->soft_volume), pa_sw_volume_to_linear(pa_cvolume_avg(&i->soft_volume)));
+
+ /* Calculation formula are target_abs_vol := i->soft_volume
+ * target_apply_vol := lrint(pa_sw_volume_to_linear(target_abs_vol) * 0x10000)
+ * pre_apply_vol := ( previous_virtual_volume / target_virtual_volume ) * target_apply_vol
+ *
+ * Will do volume adjustment inside pa_sink_input_peek
+ */
+ target_abs_vol = pa_cvolume_avg(&i->soft_volume);
+ target_apply_vol = (int32_t) lrint(pa_sw_volume_to_linear(target_abs_vol) * 0x10000);
+ pre_apply_vol = (int32_t) ((pa_sw_volume_to_linear(pre_virtual_volume) / pa_sw_volume_to_linear(target_virtual_volume)) * target_apply_vol);
+
+ i->using_def.n_points = 2;
+ i->using_def.points_x[0] = 0;
+ i->using_def.points_x[1] = t;
+ i->using_def.points_y.i[0] = pre_apply_vol;
+ i->using_def.points_y.i[1] = target_apply_vol;
+ i->using_def.points_y.f[0] = ((float) i->using_def.points_y.i[0]) /0x10000;
+ i->using_def.points_y.f[1] = ((float) i->using_def.points_y.i[1]) /0x10000;
+
+ pa_log_debug("Volume Ramping: Point 1 is %d=%f, Point 2 is %d=%f\n", i->using_def.points_y.i[0], i->using_def.points_y.f[0],
+ i->using_def.points_y.i[1], i->using_def.points_y.f[1]);
+
+ pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_ENVELOPE, NULL, 0, NULL) == 0);
+ }
+
+ /* Called from main context */
+ static void sink_input_set_ramping_info_for_mute(pa_sink_input* i, pa_bool_t mute, pa_usec_t t) {
+
+ int32_t cur_vol;
+ pa_assert(i);
+
+ i->using_def.n_points = 2;
+ i->using_def.points_x[0] = 0;
+ i->using_def.points_x[1] = t;
+ cur_vol = (int32_t) lrint( pa_sw_volume_to_linear(pa_cvolume_avg(&i->soft_volume)) * 0x10000);
+
+ if (mute) {
+ i->using_def.points_y.i[0] = cur_vol;
+ i->using_def.points_y.i[1] = 0;
+ } else {
+ i->using_def.points_y.i[0] = 0;
+ i->using_def.points_y.i[1] = cur_vol;
+ }
+
+ i->using_def.points_y.f[0] = ((float) i->using_def.points_y.i[0]) /0x10000;
+ i->using_def.points_y.f[1] = ((float) i->using_def.points_y.i[1]) /0x10000;
+
+ pa_log_debug("Mute Ramping: Point 1 is %d=%f, Point 2 is %d=%f\n", i->using_def.points_y.i[0], i->using_def.points_y.f[0],
+ i->using_def.points_y.i[1], i->using_def.points_y.f[1]);
+
+ pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_ENVELOPE, NULL, 0, NULL) == 0);
+ }
+
+ /* Called from IO context */
+ static void sink_input_release_envelope(pa_sink_input *i) {
+ pa_assert(i);
+ pa_assert(!i->thread_info.ramp_info.is_ramping);
+ pa_assert(i->thread_info.ramp_info.envelope_dead);
+
+ pa_envelope_free(i->thread_info.ramp_info.envelope);
+ i->thread_info.ramp_info.envelope = NULL;
+ i->thread_info.ramp_info.item = NULL;
+ }
+
+ /* Called from IO context */
+ static void sink_input_rewind_ramp_info(pa_sink_input *i, size_t nbytes) {
+ pa_assert(i);
+
+ if (!i->thread_info.ramp_info.envelope_dead) {
+ pa_assert(i->thread_info.ramp_info.envelope);
+
+ int32_t envelope_length = pa_envelope_length(i->thread_info.ramp_info.envelope);
+
+ if (i->thread_info.ramp_info.envelope_dying > envelope_length) {
+ if ((i->thread_info.ramp_info.envelope_dying - nbytes) < envelope_length) {
+ pa_log_debug("Envelope Become Alive");
+ pa_envelope_rewind(i->thread_info.ramp_info.envelope, envelope_length - (i->thread_info.ramp_info.envelope_dying - nbytes));
+ i->thread_info.ramp_info.is_ramping = TRUE;
+ }
+ } else if (i->thread_info.ramp_info.envelope_dying < envelope_length) {
+ if ((i->thread_info.ramp_info.envelope_dying - nbytes) <= 0) {
+ pa_log_debug("Envelope Restart");
+ pa_envelope_restart(i->thread_info.ramp_info.envelope);
+ }
+ else {
+ pa_log_debug("Envelope Simple Rewind");
+ pa_envelope_rewind(i->thread_info.ramp_info.envelope, nbytes);
+ }
+ }
+
+ i->thread_info.ramp_info.envelope_dying -= nbytes;
+ if (i->thread_info.ramp_info.envelope_dying <= 0)
+ i->thread_info.ramp_info.envelope_dying = 0;
+ }
+ }
+
+ void pa_sink_input_set_volume_with_ramping(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute, pa_usec_t t){
+ pa_cvolume v;
+ pa_volume_t previous_virtual_volume, target_virtual_volume;
- pa_sink_input_assert_ref(i);
+
++ pa_sink_input_assert_ref(i);
++ pa_assert_ctl_context();
+ pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
+ pa_assert(volume);
+ pa_assert(pa_cvolume_valid(volume));
- pa_assert(pa_cvolume_compatible(volume, &i->sample_spec));
++ pa_assert(volume->channels == 1 || pa_cvolume_compatible(volume, &i->sample_spec));
+
+ if ((i->sink->flags & PA_SINK_FLAT_VOLUME) && !absolute) {
+ v = i->sink->reference_volume;
+ pa_cvolume_remap(&v, &i->sink->channel_map, &i->channel_map);
- volume = pa_sw_cvolume_multiply(&v, &v, volume);
++
++ if (pa_cvolume_compatible(volume, &i->sample_spec))
++ volume = pa_sw_cvolume_multiply(&v, &v, volume);
++ else
++ volume = pa_sw_cvolume_multiply_scalar(&v, &v, pa_cvolume_max(volume));
++ } else {
++ if (!pa_cvolume_compatible(volume, &i->sample_spec)) {
++ v = i->volume;
++ volume = pa_cvolume_scale(&v, pa_cvolume_max(volume));
++ }
+ }
+
- if (pa_cvolume_equal(volume, &i->virtual_volume))
++ if (pa_cvolume_equal(volume, &i->volume)) {
++ i->save_volume = i->save_volume || save;
+ return;
++ }
+
- previous_virtual_volume = pa_cvolume_avg(&i->virtual_volume);
++ previous_virtual_volume = pa_cvolume_avg(&i->volume);
+ target_virtual_volume = pa_cvolume_avg(volume);
++
+ if (t > 0 && target_virtual_volume > 0)
+ pa_log_debug("SetVolumeWithRamping: Virtual Volume From %u=%f to %u=%f\n", previous_virtual_volume, pa_sw_volume_to_linear(previous_virtual_volume),
+ target_virtual_volume, pa_sw_volume_to_linear(target_virtual_volume));
+
- i->virtual_volume = *volume;
++ i->volume = *volume;
+ i->save_volume = save;
+
+ /* Set this flag before the following code modify i->thread_info.soft_volume */
+ if (t > 0 && target_virtual_volume > 0)
+ pa_atomic_store(&i->before_ramping_v, 1);
+
+ if (i->sink->flags & PA_SINK_FLAT_VOLUME) {
- pa_cvolume new_volume;
-
+ /* We are in flat volume mode, so let's update all sink input
+ * volumes and update the flat volume of the sink */
+
- pa_sink_update_flat_volume(i->sink, &new_volume);
- pa_sink_set_volume(i->sink, &new_volume, FALSE, TRUE, FALSE, FALSE);
++ pa_sink_set_volume(i->sink, NULL, TRUE, save);
+
+ } else {
-
+ /* OK, we are in normal volume mode. The volume only affects
+ * ourselves */
- pa_sink_input_set_relative_volume(i, volume);
-
- /* Hooks have the ability to play games with i->soft_volume */
- pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_SET_VOLUME], i);
++ set_real_ratio(i, volume);
+
+ /* Copy the new soft_volume to the thread_info struct */
+ pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0);
+ }
+
+ if (t > 0 && target_virtual_volume > 0)
+ sink_input_set_ramping_info(i, previous_virtual_volume, target_virtual_volume, t);
+
++ /* The volume changed, let's tell people so */
++ if (i->volume_changed)
++ i->volume_changed(i);
++
+ /* The virtual volume changed, let's tell people so */
+ pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
+ }
+
+ void pa_sink_input_set_mute_with_ramping(pa_sink_input *i, pa_bool_t mute, pa_bool_t save, pa_usec_t t){
+
+ pa_assert(i);
+ pa_sink_input_assert_ref(i);
+ pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
+
+ if (!i->muted == !mute)
+ return;
+
+ i->muted = mute;
+ i->save_muted = save;
+ /* Set this flag before the following code modify i->thread_info.muted, otherwise distortion will be heard */
+ if (t > 0)
+ pa_atomic_store(&i->before_ramping_m, 1);
+
+ pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_MUTE, NULL, 0, NULL) == 0);
+
+ if (t > 0)
+ sink_input_set_ramping_info_for_mute(i, mute, t);
+
+ pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
+ }
diff --cc src/pulsecore/sink-input.h
index 415a801,036806f..56ac3d6
--- a/src/pulsecore/sink-input.h
+++ b/src/pulsecore/sink-input.h
@@@ -381,7 -373,11 +398,11 @@@ pa_bool_t pa_sink_input_safe_to_remove(
pa_memchunk* pa_sink_input_get_silence(pa_sink_input *i, pa_memchunk *ret);
-/* To be used by sink.c only */
-void pa_sink_input_set_relative_volume(pa_sink_input *i, const pa_cvolume *v);
+#define pa_sink_input_assert_io_context(s) \
+ pa_assert(pa_thread_mq_get() || !PA_SINK_INPUT_IS_LINKED((s)->state))
+ /* Volume ramping*/
+ void pa_sink_input_set_volume_with_ramping(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute, pa_usec_t t);
+ void pa_sink_input_set_mute_with_ramping(pa_sink_input *i, pa_bool_t mute, pa_bool_t save, pa_usec_t t);
+
#endif
diff --cc src/pulsecore/sink.c
index 971436d,2950071..24fad34
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@@ -1728,9 -1597,11 +1728,12 @@@ static void sync_input_volumes_within_t
void *state = NULL;
pa_sink_assert_ref(s);
+ pa_sink_assert_io_context(s);
- while ((i = PA_SINK_INPUT(pa_hashmap_iterate(s->thread_info.inputs, &state, NULL)))) {
+ PA_HASHMAP_FOREACH(i, s->thread_info.inputs, state) {
+ if (pa_atomic_load(&i->before_ramping_v))
+ i->thread_info.future_soft_volume = i->soft_volume;
+
if (pa_cvolume_equal(&i->thread_info.soft_volume, &i->soft_volume))
continue;
commit f202af17b717f5b383ac072f80a6c1327bc3143b
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Nov 5 22:55:14 2009 +0100
ramping: minor cleanups
diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index 216edd4..177d330 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -1813,6 +1813,7 @@ void pa_sink_input_set_volume_with_ramping(pa_sink_input *i, const pa_cvolume *v
else
volume = pa_sw_cvolume_multiply_scalar(&v, &v, pa_cvolume_max(volume));
} else {
+
if (!pa_cvolume_compatible(volume, &i->sample_spec)) {
v = i->volume;
volume = pa_cvolume_scale(&v, pa_cvolume_max(volume));
@@ -1866,15 +1867,18 @@ void pa_sink_input_set_volume_with_ramping(pa_sink_input *i, const pa_cvolume *v
void pa_sink_input_set_mute_with_ramping(pa_sink_input *i, pa_bool_t mute, pa_bool_t save, pa_usec_t t){
- pa_assert(i);
pa_sink_input_assert_ref(i);
+ pa_assert_ctl_context();
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
- if (!i->muted == !mute)
+ if (!i->muted == !mute) {
+ i->save_muted = i->save_muted || mute;
return;
+ }
i->muted = mute;
i->save_muted = save;
+
/* Set this flag before the following code modify i->thread_info.muted, otherwise distortion will be heard */
if (t > 0)
pa_atomic_store(&i->before_ramping_m, 1);
@@ -1884,5 +1888,9 @@ void pa_sink_input_set_mute_with_ramping(pa_sink_input *i, pa_bool_t mute, pa_bo
if (t > 0)
sink_input_set_ramping_info_for_mute(i, mute, t);
+ /* The mute status changed, let's tell people so */
+ if (i->mute_changed)
+ i->mute_changed(i);
+
pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
}
commit 9708ecd6483ac9037c82a2a2a935e97d027f6b1b
Merge: f202af1 9033140
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Nov 20 01:02:01 2009 +0100
Merge branch 'master' of ssh://rootserver/home/lennart/git/public/pulseaudio
commit 675957b9e41d5a92d8cbff3d4fcbcec4965806da
Merge: 9708ecd 5aa5c6c
Author: Lennart Poettering <lennart at poettering.net>
Date: Sun Nov 22 21:40:15 2009 +0100
Merge branch 'master' of ssh://rootserver/home/lennart/git/public/pulseaudio
commit 0fcdc3d15d759e576ba3d71cc874c1036dcd36a0
Merge: 675957b c815441
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Nov 23 05:45:33 2009 +0100
Merge branch 'master' of ssh://rootserver/home/lennart/git/public/pulseaudio
--
hooks/post-receive
PulseAudio Sound Server
More information about the pulseaudio-commits
mailing list