eq_fir: fix buffer acquisition

Instead of acquiring and releasing buffers locally multiple times,
do that once for .copy() and .prepare() methods.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
This commit is contained in:
Guennadi Liakhovetski 2022-04-06 15:01:53 +02:00 committed by Liam Girdwood
parent c9127207ca
commit 7b6729ea24
5 changed files with 84 additions and 78 deletions

View File

@ -53,8 +53,8 @@ struct comp_data {
int32_t *fir_delay; /**< pointer to allocated RAM */
size_t fir_delay_size; /**< allocated size */
void (*eq_fir_func)(struct fir_state_32x16 fir[],
const struct audio_stream *source,
struct audio_stream *sink,
const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink,
int frames, int nch);
};
@ -105,15 +105,11 @@ static inline void set_s32_fir(struct comp_data *cd)
#endif /* CONFIG_FORMAT_S32LE */
#endif
static inline int set_fir_func(struct comp_dev *dev)
static inline int set_fir_func(struct comp_dev *dev, enum sof_ipc_frame fmt)
{
struct comp_data *cd = comp_get_drvdata(dev);
struct comp_buffer *sourceb;
sourceb = list_first_item(&dev->bsource_list, struct comp_buffer,
sink_list);
switch (sourceb->stream.frame_fmt) {
switch (fmt) {
#if CONFIG_FORMAT_S16LE
case SOF_IPC_FRAME_S16_LE:
comp_info(dev, "set_fir_func(), SOF_IPC_FRAME_S16_LE");
@ -144,8 +140,8 @@ static inline int set_fir_func(struct comp_dev *dev)
*/
static void eq_fir_passthrough(struct fir_state_32x16 fir[],
const struct audio_stream *source,
struct audio_stream *sink,
const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink,
int frames, int nch)
{
audio_stream_copy(source, 0, sink, 0, frames * nch);
@ -473,8 +469,8 @@ static int eq_fir_trigger(struct comp_dev *dev, int cmd)
return comp_set_state(dev, cmd);
}
static void eq_fir_process(struct comp_dev *dev, struct comp_buffer *source,
struct comp_buffer *sink, int frames,
static void eq_fir_process(struct comp_dev *dev, struct comp_buffer __sparse_cache *source,
struct comp_buffer __sparse_cache *sink, int frames,
uint32_t source_bytes, uint32_t sink_bytes)
{
struct comp_data *cd = comp_get_drvdata(dev);
@ -487,16 +483,16 @@ static void eq_fir_process(struct comp_dev *dev, struct comp_buffer *source,
buffer_stream_writeback(sink, sink_bytes);
/* calc new free and available */
comp_update_buffer_consume(source, source_bytes);
comp_update_buffer_produce(sink, sink_bytes);
comp_update_buffer_cached_consume(source, source_bytes);
comp_update_buffer_cached_produce(sink, sink_bytes);
}
/* copy and process stream data from source to sink buffers */
static int eq_fir_copy(struct comp_dev *dev)
{
struct comp_copy_limits cl;
struct comp_buffer *sourceb;
struct comp_buffer *sinkb;
struct comp_buffer *sourceb, *sinkb;
struct comp_buffer __sparse_cache *source_c, *sink_c;
struct comp_data *cd = comp_get_drvdata(dev);
int ret;
int n;
@ -505,22 +501,26 @@ static int eq_fir_copy(struct comp_dev *dev)
sourceb = list_first_item(&dev->bsource_list, struct comp_buffer,
sink_list);
source_c = buffer_acquire(sourceb);
/* Check for changed configuration */
if (comp_is_new_data_blob_available(cd->model_handler)) {
cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL);
ret = eq_fir_setup(cd, sourceb->stream.channels);
ret = eq_fir_setup(cd, source_c->stream.channels);
if (ret < 0) {
comp_err(dev, "eq_fir_copy(), failed FIR setup");
buffer_release(source_c);
return ret;
}
}
sinkb = list_first_item(&dev->bsink_list, struct comp_buffer,
source_list);
sink_c = buffer_acquire(sinkb);
/* Get source, sink, number of frames etc. to process. */
comp_get_copy_limits_with_lock(sourceb, sinkb, &cl);
comp_get_copy_limits(source_c, sink_c, &cl);
/*
* Process only even number of frames with the FIR function. The
@ -534,19 +534,22 @@ static int eq_fir_copy(struct comp_dev *dev)
n = (cl.frames >> 1) << 1;
/* Run EQ function */
eq_fir_process(dev, sourceb, sinkb, n,
eq_fir_process(dev, source_c, sink_c, n,
n * cl.source_frame_bytes,
n * cl.sink_frame_bytes);
}
buffer_release(source_c);
buffer_release(sink_c);
return 0;
}
static int eq_fir_prepare(struct comp_dev *dev)
{
struct comp_data *cd = comp_get_drvdata(dev);
struct comp_buffer *sourceb;
struct comp_buffer *sinkb;
struct comp_buffer *sourceb, *sinkb;
struct comp_buffer __sparse_cache *source_c, *sink_c;
uint32_t sink_period_bytes;
int ret;
@ -565,35 +568,38 @@ static int eq_fir_prepare(struct comp_dev *dev)
sinkb = list_first_item(&dev->bsink_list,
struct comp_buffer, source_list);
sink_period_bytes = audio_stream_period_bytes(&sinkb->stream,
source_c = buffer_acquire(sourceb);
sink_c = buffer_acquire(sinkb);
sink_period_bytes = audio_stream_period_bytes(&sink_c->stream,
dev->frames);
if (sinkb->stream.size < sink_period_bytes) {
if (sink_c->stream.size < sink_period_bytes) {
comp_err(dev, "eq_fir_prepare(): sink buffer size %d is insufficient < %d",
sinkb->stream.size, sink_period_bytes);
sink_c->stream.size, sink_period_bytes);
ret = -ENOMEM;
goto err;
goto out;
}
cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL);
if (cd->config) {
ret = eq_fir_setup(cd, sourceb->stream.channels);
if (ret < 0) {
ret = eq_fir_setup(cd, source_c->stream.channels);
if (ret < 0)
comp_err(dev, "eq_fir_prepare(): eq_fir_setup failed.");
goto err;
}
ret = set_fir_func(dev);
return ret;
}
else
ret = set_fir_func(dev, source_c->stream.frame_fmt);
} else {
cd->eq_fir_func = eq_fir_passthrough;
}
return ret;
err:
out:
if (ret < 0)
comp_set_state(dev, COMP_TRIGGER_RESET);
buffer_release(sink_c);
buffer_release(source_c);
return ret;
}

View File

@ -19,8 +19,8 @@
LOG_MODULE_DECLARE(eq_fir, CONFIG_SOF_LOG_LEVEL);
#if CONFIG_FORMAT_S16LE
void eq_fir_s16(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_s16(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *filter;
int32_t z;
@ -54,8 +54,8 @@ void eq_fir_s16(struct fir_state_32x16 fir[], const struct audio_stream *source,
#endif /* CONFIG_FORMAT_S16LE */
#if CONFIG_FORMAT_S24LE
void eq_fir_s24(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_s24(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *filter;
int32_t z;
@ -89,8 +89,8 @@ void eq_fir_s24(struct fir_state_32x16 fir[], const struct audio_stream *source,
#endif /* CONFIG_FORMAT_S24LE */
#if CONFIG_FORMAT_S32LE
void eq_fir_s32(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_s32(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *filter;
int32_t *x0, *y0;

View File

@ -24,8 +24,8 @@ LOG_MODULE_DECLARE(eq_fir, CONFIG_SOF_LOG_LEVEL);
/* For even frame lengths use FIR filter that processes two sequential
* sample per call.
*/
void eq_fir_2x_s32(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_2x_s32(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *f;
int32_t *src = (int32_t *)source->r_ptr;
@ -64,8 +64,8 @@ void eq_fir_2x_s32(struct fir_state_32x16 fir[], const struct audio_stream *sour
}
/* FIR for any number of frames */
void eq_fir_s32(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_s32(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *f;
int32_t *src = (int32_t *)source->r_ptr;
@ -99,8 +99,8 @@ void eq_fir_s32(struct fir_state_32x16 fir[], const struct audio_stream *source,
#endif /* CONFIG_FORMAT_S32LE */
#if CONFIG_FORMAT_S24LE
void eq_fir_2x_s24(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_2x_s24(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *f;
int32_t *src = (int32_t *)source->r_ptr;
@ -143,8 +143,8 @@ void eq_fir_2x_s24(struct fir_state_32x16 fir[], const struct audio_stream *sour
}
/* FIR for any number of frames */
void eq_fir_s24(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_s24(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *f;
int32_t *src = (int32_t *)source->r_ptr;
@ -180,8 +180,8 @@ void eq_fir_s24(struct fir_state_32x16 fir[], const struct audio_stream *source,
#endif /* CONFIG_FORMAT_S24LE */
#if CONFIG_FORMAT_S16LE
void eq_fir_2x_s16(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_2x_s16(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *f;
int16_t *src = (int16_t *)source->r_ptr;
@ -224,8 +224,8 @@ void eq_fir_2x_s16(struct fir_state_32x16 fir[], const struct audio_stream *sour
}
/* FIR for any number of frames */
void eq_fir_s16(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_s16(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *f;
int16_t *src = (int16_t *)source->r_ptr;

View File

@ -23,8 +23,8 @@ LOG_MODULE_DECLARE(eq_fir, CONFIG_SOF_LOG_LEVEL);
/* For even frame lengths use FIR filter that processes two sequential
* sample per call.
*/
void eq_fir_2x_s32(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_2x_s32(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *f;
ae_int32x2 d0 = 0;
@ -82,8 +82,8 @@ void eq_fir_2x_s32(struct fir_state_32x16 fir[], const struct audio_stream *sour
}
/* FIR for any number of frames */
void eq_fir_s32(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_s32(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *f;
ae_int32x2 in = 0;
@ -139,8 +139,8 @@ void eq_fir_s32(struct fir_state_32x16 fir[], const struct audio_stream *source,
#endif /* CONFIG_FORMAT_S32LE */
#if CONFIG_FORMAT_S24LE
void eq_fir_2x_s24(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_2x_s24(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *f;
ae_int32x2 d0 = 0;
@ -203,8 +203,8 @@ void eq_fir_2x_s24(struct fir_state_32x16 fir[], const struct audio_stream *sour
}
}
void eq_fir_s24(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_s24(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *f;
ae_int32 in;
@ -265,8 +265,8 @@ void eq_fir_s24(struct fir_state_32x16 fir[], const struct audio_stream *source,
#endif /* CONFIG_FORMAT_S24LE */
#if CONFIG_FORMAT_S16LE
void eq_fir_2x_s16(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_2x_s16(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *f;
ae_int16x4 d0 = AE_ZERO16();
@ -333,8 +333,8 @@ void eq_fir_2x_s16(struct fir_state_32x16 fir[], const struct audio_stream *sour
}
}
void eq_fir_s16(struct fir_state_32x16 fir[], const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch)
void eq_fir_s16(struct fir_state_32x16 fir[], const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch)
{
struct fir_state_32x16 *f;
ae_f16x4 d = AE_ZERO16();

View File

@ -28,27 +28,27 @@
#define EQ_FIR_BYTES_TO_S32_SAMPLES(b) ((b) >> 2)
#if CONFIG_FORMAT_S16LE
void eq_fir_s16(struct fir_state_32x16 *fir, const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch);
void eq_fir_s16(struct fir_state_32x16 *fir, const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch);
void eq_fir_2x_s16(struct fir_state_32x16 *fir, const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch);
void eq_fir_2x_s16(struct fir_state_32x16 *fir, const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch);
#endif /* CONFIG_FORMAT_S16LE */
#if CONFIG_FORMAT_S24LE
void eq_fir_s24(struct fir_state_32x16 *fir, const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch);
void eq_fir_s24(struct fir_state_32x16 *fir, const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch);
void eq_fir_2x_s24(struct fir_state_32x16 *fir, const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch);
void eq_fir_2x_s24(struct fir_state_32x16 *fir, const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch);
#endif /* CONFIG_FORMAT_S24LE */
#if CONFIG_FORMAT_S32LE
void eq_fir_s32(struct fir_state_32x16 *fir, const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch);
void eq_fir_s32(struct fir_state_32x16 *fir, const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch);
void eq_fir_2x_s32(struct fir_state_32x16 *fir, const struct audio_stream *source,
struct audio_stream *sink, int frames, int nch);
void eq_fir_2x_s32(struct fir_state_32x16 *fir, const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink, int frames, int nch);
#endif /* CONFIG_FORMAT_S32LE */
#endif /* __SOF_AUDIO_EQ_FIR_EQ_FIR_H__ */