[Sound-open-firmware] [PATCH 1/3] volume: add 24bit<==>32bit scaler and mapping
As we are using 32 bits data in internal buffer, we need 24bit<==>32bit volume scaler for host<==>processing<==>dai converting.
Signed-off-by: Keyon Jie yang.jie@linux.intel.com --- src/audio/volume.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/src/audio/volume.c b/src/audio/volume.c index d457632..e2badb8 100644 --- a/src/audio/volume.c +++ b/src/audio/volume.c @@ -191,6 +191,44 @@ static void vol_s24_to_s16(struct comp_dev *dev, struct comp_buffer *sink, sink->w_ptr = dest + i; }
+/* copy and scale volume from 32 bit source buffer to 24 bit on 32 bit boundary dest buffer */ +static void vol_s32_to_s24(struct comp_dev *dev, struct comp_buffer *sink, + struct comp_buffer *source, uint32_t frames) +{ + struct comp_data *cd = comp_get_drvdata(dev); + int32_t *src = (int32_t*) source->r_ptr; + int32_t i, *dest = (int32_t*) sink->w_ptr; + + /* buffer sizes are always divisible by period frames */ + for (i = 0; i < frames * 2; i += 2) { + dest[i] = ((int64_t)src[i] * cd->volume[0]) >> 24; + dest[i + 1] = ((int64_t)src[i + 1] * cd->volume[1]) >> 24; + } + + source->r_ptr = src + i; + sink->w_ptr = dest + i; +} + +/* copy and scale volume from 16 bit source buffer to 24 bit on 32 bit boundary dest buffer */ +static void vol_s24_to_s32(struct comp_dev *dev, struct comp_buffer *sink, + struct comp_buffer *source, uint32_t frames) +{ + struct comp_data *cd = comp_get_drvdata(dev); + int32_t i, *src = (int32_t*) source->r_ptr; + int32_t *dest = (int32_t*) sink->w_ptr; + + /* buffer sizes are always divisible by period frames */ + for (i = 0; i < frames * 2; i += 2) { + dest[i] = (int32_t)(((int64_t)src[i] * + cd->volume[0]) >> 8); + dest[i + 1] = (int32_t)(((int64_t)src[i + 1] * + cd->volume[1]) >> 8); + } + + source->r_ptr = src + i; + sink->w_ptr = dest + i; +} + /* map of source and sink buffer formats to volume function */ static const struct comp_func_map func_map[] = { {STREAM_FORMAT_S16_LE, STREAM_FORMAT_S16_LE, 2, vol_s16_to_s16}, @@ -199,6 +237,8 @@ static const struct comp_func_map func_map[] = { {STREAM_FORMAT_S32_LE, STREAM_FORMAT_S32_LE, 2, vol_s32_to_s32}, {STREAM_FORMAT_S16_LE, STREAM_FORMAT_S24_4LE, 2, vol_s16_to_s24}, {STREAM_FORMAT_S24_4LE, STREAM_FORMAT_S16_LE, 2, vol_s24_to_s16}, + {STREAM_FORMAT_S32_LE, STREAM_FORMAT_S24_4LE, 2, vol_s32_to_s24}, + {STREAM_FORMAT_S24_4LE, STREAM_FORMAT_S32_LE, 2, vol_s24_to_s32}, };
static void vol_update(struct comp_data *cd, uint32_t chan) @@ -447,7 +487,7 @@ static int volume_prepare(struct comp_dev *dev) /* TODO tmp hard coded for 24 bit - need fixed for capture*/ /* is sink a host or DAI ? */ if (sink->sink->is_host || sink->sink->is_dai) - sink_format = STREAM_FORMAT_S24_4LE;//sink->params.pcm.format; + sink_format = sink->params.pcm.format; else sink_format = STREAM_FORMAT_S32_LE;
As we have changed internal buffer to 32 bits, to avoid clamping, we need to change accumulator to 64 bits.
Signed-off-by: Keyon Jie yang.jie@linux.intel.com --- src/audio/mixer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/audio/mixer.c b/src/audio/mixer.c index d08bc30..b996dae 100644 --- a/src/audio/mixer.c +++ b/src/audio/mixer.c @@ -51,7 +51,8 @@ struct mixer_data { static void mix_n(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer **sources, uint32_t num_sources, uint32_t frames) { - int32_t *src, *dest = sink->w_ptr, val[2], count; + int32_t *src, *dest = sink->w_ptr, count; + int64_t val[2]; int i, j;
count = frames * sink->params.channels;
As the normal static pipeline can work fine after the 1.33->1ms buffer and 16->32 bits internal buffer transforming finished, let's change back to use normal static pipeline by default.
Signed-off-by: Keyon Jie yang.jie@linux.intel.com --- src/audio/pipeline_static.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/audio/pipeline_static.c b/src/audio/pipeline_static.c index cc80adf..33abbec 100644 --- a/src/audio/pipeline_static.c +++ b/src/audio/pipeline_static.c @@ -46,7 +46,7 @@ #include <reef/audio/pipeline.h>
/* simple debug pipeline */ -#define DEBUG_PIPE 1 +#define DEBUG_PIPE 0
/* convenience component UUIDs and descriptors */ #define SPIPE_MIXER {COMP_TYPE_MIXER, 0, 0}
On Tue, 2017-01-03 at 10:40 +0800, Keyon Jie wrote:
As we are using 32 bits data in internal buffer, we need 24bit<==>32bit volume scaler for host<==>processing<==>dai converting.
Signed-off-by: Keyon Jie yang.jie@linux.intel.com
All applied.
Thanks
Liam
participants (2)
-
Keyon Jie
-
Liam Girdwood