Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions src/audio/drc/drc.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ void drc_reset_state(struct processing_module *mod, struct drc_state *state)
int drc_init_pre_delay_buffers(struct processing_module *mod,
struct drc_state *state,
size_t sample_bytes,
int channels)
unsigned int channels)
{
size_t bytes_per_channel = sample_bytes * CONFIG_DRC_MAX_PRE_DELAY_FRAMES;
size_t bytes_total = bytes_per_channel * channels;
int i;
unsigned int i;

/* Allocate pre-delay (lookahead) buffers */
state->pre_delay_buffers[0] = mod_alloc(mod, bytes_total);
Expand Down Expand Up @@ -122,17 +122,17 @@ int drc_set_pre_delay_time(struct drc_state *state,
}

/* Called from drc_process(), so cannot be __cold */
static int drc_setup(struct processing_module *mod, uint16_t channels, uint32_t rate)
static int drc_setup(struct processing_module *mod, unsigned int channels, uint32_t rate)
{
struct drc_comp_data *cd = module_get_private_data(mod);
uint32_t sample_bytes = get_sample_bytes(cd->source_format);
size_t sample_bytes = get_sample_bytes(cd->source_format);
int ret;

/* Reset any previous state */
drc_reset_state(mod, &cd->state);

/* Allocate pre-delay buffers */
ret = drc_init_pre_delay_buffers(mod, &cd->state, (size_t)sample_bytes, (int)channels);
ret = drc_init_pre_delay_buffers(mod, &cd->state, sample_bytes, channels);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -285,7 +285,7 @@ static int drc_process(struct processing_module *mod,
size_t sink_frame_bytes = sink_get_frame_bytes(sink);
size_t source_bytes, sink_bytes;
size_t source_buf_size, sink_buf_size;
uint32_t frames;
size_t frames;
int ret;

comp_dbg(dev, "entry");
Expand Down Expand Up @@ -360,10 +360,10 @@ static int drc_process(struct processing_module *mod,
}

#if CONFIG_IPC_MAJOR_4
static void drc_params(struct processing_module *mod)
static void drc_params(struct processing_module *mod, struct sof_source *source,
struct sof_sink *sink)
{
struct sof_ipc_stream_params *params = mod->stream_params;
struct comp_buffer *sinkb, *sourceb;
struct comp_dev *dev = mod->dev;

comp_dbg(dev, "entry");
Expand All @@ -372,12 +372,8 @@ static void drc_params(struct processing_module *mod)
component_set_nearest_period_frames(dev, params->rate);

/* The caller has verified, that sink and source buffers are connected */

sinkb = comp_dev_get_first_data_consumer(dev);
ipc4_update_buffer_format(sinkb, &mod->priv.cfg.base_cfg.audio_fmt);

sourceb = comp_dev_get_first_data_producer(dev);
ipc4_update_buffer_format(sourceb, &mod->priv.cfg.base_cfg.audio_fmt);
ipc4_update_sink_format(sink, &mod->priv.cfg.base_cfg.audio_fmt);
ipc4_update_source_format(source, &mod->priv.cfg.base_cfg.audio_fmt);
}
#endif /* CONFIG_IPC_MAJOR_4 */

Expand All @@ -386,30 +382,28 @@ static int drc_prepare(struct processing_module *mod,
struct sof_sink **sinks, int num_of_sinks)
{
struct drc_comp_data *cd = module_get_private_data(mod);
struct comp_buffer *sourceb, *sinkb;
struct comp_dev *dev = mod->dev;
int channels;
unsigned int channels;
int rate;
int ret;

comp_info(dev, "entry");

/* DRC component will only ever have 1 source and 1 sink buffer */
sourceb = comp_dev_get_first_data_producer(dev);
sinkb = comp_dev_get_first_data_consumer(dev);
if (!sourceb || !sinkb) {
comp_err(dev, "no source or sink buffer");
if (num_of_sources != 1 || num_of_sinks != 1) {
comp_err(dev, "expected 1 source and 1 sink, got %d sources and %d sinks",
num_of_sources, num_of_sinks);
return -ENOTCONN;
Comment on lines +393 to 396
}

#if CONFIG_IPC_MAJOR_4
drc_params(mod);
drc_params(mod, sources[0], sinks[0]);
#endif

/* get source data format */
cd->source_format = audio_stream_get_frm_fmt(&sourceb->stream);
channels = audio_stream_get_channels(&sinkb->stream);
rate = audio_stream_get_rate(&sinkb->stream);
cd->source_format = source_get_frm_fmt(sources[0]);
channels = sink_get_channels(sinks[0]);
rate = sink_get_rate(sinks[0]);
cd->channels = channels;

/* Initialize DRC */
Expand Down
6 changes: 3 additions & 3 deletions src/audio/drc/drc.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct drc_state {
typedef void (*drc_func)(struct processing_module *mod,
const struct cir_buf_source *source,
struct cir_buf_sink *sink,
uint32_t frames);
size_t frames);

/* DRC component private data */
struct drc_comp_data {
Expand All @@ -81,7 +81,7 @@ struct drc_comp_data {
bool enabled; /**< control processing via blob and switch */
bool enable_switch; /**< enable switch state */
enum sof_ipc_frame source_format; /**< source frame format */
int channels; /**< number of channels */
unsigned int channels; /**< number of channels */
drc_func drc_func; /**< processing function */
};

Expand All @@ -95,7 +95,7 @@ extern const size_t drc_proc_fncount;

void drc_default_pass(struct processing_module *mod,
const struct cir_buf_source *source,
struct cir_buf_sink *sink, uint32_t frames);
struct cir_buf_sink *sink, size_t frames);
/**
* \brief Returns DRC processing function.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/audio/drc/drc_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ void drc_reset_state(struct processing_module *mod, struct drc_state *state);
int drc_init_pre_delay_buffers(struct processing_module *mod,
struct drc_state *state,
size_t sample_bytes,
int channels);
unsigned int channels);
int drc_set_pre_delay_time(struct drc_state *state,
int32_t pre_delay_time,
int32_t rate);

/* drc process functions */
void drc_update_detector_average(struct drc_state *state,
const struct sof_drc_params *p,
int nbyte,
int nch);
size_t nbyte,
unsigned int nch);
void drc_update_envelope(struct drc_state *state, const struct sof_drc_params *p);
void drc_compress_output(struct drc_state *state,
const struct sof_drc_params *p,
int nbyte,
int nch);
size_t nbyte,
unsigned int nch);

#endif // __SOF_AUDIO_DRC_DRC_ALGORITHM_H__
74 changes: 39 additions & 35 deletions src/audio/drc/drc_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x)
/* Update detector_average from the last input division. */
void drc_update_detector_average(struct drc_state *state,
const struct sof_drc_params *p,
int nbyte,
int nch)
size_t nbyte,
unsigned int nch)
{
int32_t detector_average = state->detector_average; /* Q2.30 */
int32_t abs_input_array[DRC_DIVISION_FRAMES]; /* Q1.31 */
int div_start, i, ch;
int div_start, i;
unsigned int ch;
int16_t *sample16_p; /* for s16 format case */
int32_t *sample32_p; /* for s24 and s32 format cases */
int32_t sample;
Expand Down Expand Up @@ -264,8 +265,8 @@ void drc_update_envelope(struct drc_state *state, const struct sof_drc_params *p
* the next output division. */
void drc_compress_output(struct drc_state *state,
const struct sof_drc_params *p,
int nbyte,
int nch)
size_t nbyte,
unsigned int nch)
{
const int div_start = state->pre_delay_read_index;
int count = DRC_DIVISION_FRAMES >> 2;
Expand All @@ -275,7 +276,8 @@ void drc_compress_output(struct drc_state *state,
int32_t post_warp_compressor_gain;
int32_t total_gain;

int i, j, ch, inc;
int i, j, inc;
unsigned int ch;
int16_t *sample16_p; /* for s16 format case */
int32_t *sample32_p; /* for s24 and s32 format cases */
int32_t sample;
Expand Down Expand Up @@ -463,8 +465,8 @@ void drc_compress_output(struct drc_state *state,
*/
static void drc_process_one_division(struct drc_state *state,
const struct sof_drc_params *p,
int nbyte,
int nch)
size_t nbyte,
unsigned int nch)
{
drc_update_detector_average(state, p, nbyte, nch);
drc_update_envelope(state, p);
Expand All @@ -473,27 +475,26 @@ static void drc_process_one_division(struct drc_state *state,

void drc_default_pass(struct processing_module *mod,
const struct cir_buf_source *source,
struct cir_buf_sink *sink, uint32_t frames)
struct cir_buf_sink *sink, size_t frames)
{
struct drc_comp_data *cd = module_get_private_data(mod);
const int sample_bytes = get_sample_bytes(cd->source_format);
size_t bytes = (size_t)frames * cd->channels * sample_bytes;
const size_t sample_bytes = get_sample_bytes(cd->source_format);
size_t bytes = frames * cd->channels * sample_bytes;
const uint8_t *src = source->ptr;
uint8_t *dst = sink->ptr;
int n;
size_t n;

while (bytes) {
n = MIN((const uint8_t *)source->buf_end - src,
(uint8_t *)sink->buf_end - dst);
n = MIN(cir_buf_bytes_without_wrap(src, source->buf_end),
cir_buf_bytes_without_wrap(dst, sink->buf_end));
n = MIN(n, bytes);
if (!n) {
src = cir_buf_wrap(src, source->buf_start, source->buf_end);
src = source_cir_buf_wrap(src, source->buf_start, source->buf_end);
dst = cir_buf_wrap(dst, sink->buf_start, sink->buf_end);
continue;
}
memcpy_s(dst, n, src, n);
src = cir_buf_wrap((void *)(src + n), (void *)source->buf_start,
(void *)source->buf_end);
src = source_cir_buf_wrap(src + n, source->buf_start, source->buf_end);
dst = cir_buf_wrap(dst + n, sink->buf_start, sink->buf_end);
bytes -= n;
}
Expand All @@ -508,14 +509,15 @@ static inline void drc_pre_delay_index_inc(int *idx, int increment)
static void drc_delay_input_sample_s16(struct drc_state *state,
const struct cir_buf_source *source,
struct cir_buf_sink *sink,
const int16_t **x, int16_t **y, size_t samples, int nch)
const int16_t **x, int16_t **y, size_t samples,
unsigned int nch)
{
const int16_t *x1;
int16_t *y1;
int16_t *pd;
int pd_write_index, pd_read_index;
size_t nbuf, npcm, nfrm;
int ch;
unsigned int ch;
size_t i;
const int16_t *x0 = *x;
int16_t *y0 = *y;
Expand Down Expand Up @@ -556,12 +558,12 @@ static void drc_delay_input_sample_s16(struct drc_state *state,
static void drc_s16_default(struct processing_module *mod,
const struct cir_buf_source *source,
struct cir_buf_sink *sink,
uint32_t frames)
size_t frames)
{
struct drc_comp_data *cd = module_get_private_data(mod);
int nch = cd->channels;
const int16_t *x = (int16_t *)source->ptr;
int16_t *y = (int16_t *)sink->ptr;
const unsigned int nch = cd->channels;
const int16_t *x = source->ptr;
int16_t *y = sink->ptr;
size_t samples = frames * nch;
struct drc_state *state = &cd->state;
const struct sof_drc_params *p = &cd->config->params; /* Read-only */
Expand Down Expand Up @@ -602,14 +604,15 @@ static void drc_s16_default(struct processing_module *mod,
static void drc_delay_input_sample_s32(struct drc_state *state,
const struct cir_buf_source *source,
struct cir_buf_sink *sink,
const int32_t **x, int32_t **y, size_t samples, int nch)
const int32_t **x, int32_t **y, size_t samples,
unsigned int nch)
{
const int32_t *x1;
int32_t *y1;
int32_t *pd;
int pd_write_index, pd_read_index;
size_t nbuf, npcm, nfrm;
int ch;
unsigned int ch;
size_t i;
const int32_t *x0 = *x;
int32_t *y0 = *y;
Expand Down Expand Up @@ -652,14 +655,15 @@ static void drc_delay_input_sample_s32(struct drc_state *state,
static void drc_delay_input_sample_s24(struct drc_state *state,
const struct cir_buf_source *source,
struct cir_buf_sink *sink,
const int32_t **x, int32_t **y, size_t samples, int nch)
const int32_t **x, int32_t **y, size_t samples,
unsigned int nch)
{
const int32_t *x1;
int32_t *y1;
int32_t *pd;
int pd_write_index, pd_read_index;
size_t nbuf, npcm, nfrm;
int ch;
unsigned int ch;
size_t i;
const int32_t *x0 = *x;
int32_t *y0 = *y;
Expand Down Expand Up @@ -700,12 +704,12 @@ static void drc_delay_input_sample_s24(struct drc_state *state,
static void drc_s24_default(struct processing_module *mod,
const struct cir_buf_source *source,
struct cir_buf_sink *sink,
uint32_t frames)
size_t frames)
{
struct drc_comp_data *cd = module_get_private_data(mod);
int nch = cd->channels;
const int32_t *x = (int32_t *)source->ptr;
int32_t *y = (int32_t *)sink->ptr;
const unsigned int nch = cd->channels;
const int32_t *x = source->ptr;
int32_t *y = sink->ptr;
size_t samples = frames * nch;
struct drc_state *state = &cd->state;
const struct sof_drc_params *p = &cd->config->params; /* Read-only */
Expand Down Expand Up @@ -748,12 +752,12 @@ static void drc_s24_default(struct processing_module *mod,
static void drc_s32_default(struct processing_module *mod,
const struct cir_buf_source *source,
struct cir_buf_sink *sink,
uint32_t frames)
size_t frames)
{
struct drc_comp_data *cd = module_get_private_data(mod);
int nch = cd->channels;
const int32_t *x = (int32_t *)source->ptr;
int32_t *y = (int32_t *)sink->ptr;
const unsigned int nch = cd->channels;
const int32_t *x = source->ptr;
int32_t *y = sink->ptr;
size_t samples = frames * nch;
struct drc_state *state = &cd->state;
const struct sof_drc_params *p = &cd->config->params; /* Read-only */
Expand Down
14 changes: 8 additions & 6 deletions src/audio/drc/drc_hifi3.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x)
/* Update detector_average from the last input division. */
void drc_update_detector_average(struct drc_state *state,
const struct sof_drc_params *p,
int nbyte,
int nch)
size_t nbyte,
unsigned int nch)
{
ae_f32 detector_average = state->detector_average; /* Q2.30 */
int32_t abs_input_array[DRC_DIVISION_FRAMES]; /* Q1.31 */
int32_t *abs_input_array_p;
int div_start, i, ch;
int div_start, i;
unsigned int ch;
int16_t *sample16_p; /* for s16 format case */
int32_t *sample32_p; /* for s24 and s32 format cases */
int32_t sample;
Expand Down Expand Up @@ -292,8 +293,8 @@ void drc_update_envelope(struct drc_state *state, const struct sof_drc_params *p
*/
void drc_compress_output(struct drc_state *state,
const struct sof_drc_params *p,
int nbyte,
int nch)
size_t nbyte,
unsigned int nch)
{
const int div_start = state->pre_delay_read_index;
const int count = DRC_DIVISION_FRAMES >> 2;
Expand All @@ -304,7 +305,8 @@ void drc_compress_output(struct drc_state *state,
ae_f32 total_gain;
ae_f32 tmp;

int i, j, ch, inc;
int i, j, inc;
unsigned int ch;
int16_t *sample16_p; /* for s16 format case */
int32_t *sample32_p; /* for s24 and s32 format cases */
int32_t sample;
Expand Down
Loading
Loading