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
23 changes: 23 additions & 0 deletions lmdk/include/rtos/panic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2026 Intel Corporation. All rights reserved.
*
* Author: Piotr Hoppe <piotr.hoppe@intel.com>
*/

#ifndef __LMDK_RTOS_PANIC_H__
#define __LMDK_RTOS_PANIC_H__

#ifdef __cplusplus
extern "C" {
#endif

/* runtime assertion */
#define assert(x) do {if (!(x)) while (1);} while (0)

#ifdef __cplusplus
}
#endif

#endif /* __LMDK_RTOS_PANIC_H__ */

42 changes: 15 additions & 27 deletions src/audio/multiband_drc/multiband_drc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
// Author: Pin-chih Lin <johnylin@google.com>

#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/buffer.h>
#include <sof/audio/format.h>
#include <sof/audio/ipc-config.h>
#include <sof/audio/pipeline.h>
#include <sof/ipc/msg.h>
#include <sof/lib/memory.h>
#include <sof/lib/uuid.h>
Expand Down Expand Up @@ -301,38 +299,36 @@ __cold static int multiband_drc_get_config(struct processing_module *mod,
}

static int multiband_drc_process(struct processing_module *mod,
struct input_stream_buffer *input_buffers, int num_input_buffers,
struct output_stream_buffer *output_buffers,
int num_output_buffers)
struct sof_source **sources, int num_of_sources,
struct sof_sink **sinks, int num_of_sinks)
{
struct multiband_drc_comp_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;
struct audio_stream *source = input_buffers[0].data;
struct audio_stream *sink = output_buffers[0].data;
int frames = input_buffers[0].size;
int frames = source_get_data_frames_available(sources[0]);
int ret;
Comment on lines 301 to 308

comp_dbg(dev, "entry");

/* 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 = multiband_drc_setup(mod, (int16_t)audio_stream_get_channels(sink),
audio_stream_get_rate(sink));
ret = multiband_drc_setup(mod, (int16_t)sink_get_channels(sinks[0]),
sink_get_rate(sinks[0]));
if (ret < 0) {
comp_err(dev, "failed DRC setup");
return ret;
}
}

if (cd->process_enabled)
cd->multiband_drc_func(mod, source, sink, frames);
ret = cd->multiband_drc_func(mod, sources[0], sinks[0], frames);
else
multiband_drc_default_pass(mod, source, sink, frames);
ret = multiband_drc_default_pass(mod, sources[0], sinks[0], frames);

/* calc new free and available */
module_update_buffer_position(&input_buffers[0], &output_buffers[0], frames);
return 0;
if (ret < 0)
comp_err(dev, "processing failed: %d", ret);

return ret;
}

static int multiband_drc_prepare(struct processing_module *mod,
Expand All @@ -341,7 +337,6 @@ static int multiband_drc_prepare(struct processing_module *mod,
{
struct multiband_drc_comp_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;
struct comp_buffer *sourceb;
size_t data_size;
int channels;
int rate;
Expand All @@ -353,17 +348,10 @@ static int multiband_drc_prepare(struct processing_module *mod,
if (ret < 0)
return ret;

/* DRC component will only ever have 1 source and 1 sink buffer */
sourceb = comp_dev_get_first_data_producer(dev);
if (!sourceb) {
comp_err(dev, "no source buffer");
return -ENOTCONN;
}

/* get source data format */
cd->source_format = audio_stream_get_frm_fmt(&sourceb->stream);
channels = audio_stream_get_channels(&sourceb->stream);
rate = audio_stream_get_rate(&sourceb->stream);
cd->source_format = source_get_frm_fmt(sources[0]);
channels = (int16_t)source_get_channels(sources[0]);
rate = source_get_rate(sources[0]);

/* Initialize DRC */
comp_dbg(dev, "source_format=%d, sink_format=%d",
Expand Down Expand Up @@ -404,7 +392,7 @@ static int multiband_drc_reset(struct processing_module *mod)
static const struct module_interface multiband_drc_interface = {
.init = multiband_drc_init,
.prepare = multiband_drc_prepare,
.process_audio_stream = multiband_drc_process,
.process = multiband_drc_process,
.set_configuration = multiband_drc_set_config,
.get_configuration = multiband_drc_get_config,
.reset = multiband_drc_reset,
Expand Down
16 changes: 8 additions & 8 deletions src/audio/multiband_drc/multiband_drc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ struct multiband_drc_state {
struct iir_state_df1 deemphasis[PLATFORM_MAX_CHANNELS];
};

typedef void (*multiband_drc_func)(const struct processing_module *mod,
const struct audio_stream *source,
struct audio_stream *sink,
uint32_t frames);
typedef int (*multiband_drc_func)(const struct processing_module *mod,
struct sof_source *source,
struct sof_sink *sink,
uint32_t frames);

/* Multiband DRC component private data */
struct multiband_drc_comp_data {
Expand All @@ -54,10 +54,10 @@ extern const struct multiband_drc_proc_fnmap multiband_drc_proc_fnmap[];
extern const struct multiband_drc_proc_fnmap multiband_drc_proc_fnmap_pass[];
extern const size_t multiband_drc_proc_fncount;

void multiband_drc_default_pass(const struct processing_module *mod,
const struct audio_stream *source,
struct audio_stream *sink,
uint32_t frames);
int multiband_drc_default_pass(const struct processing_module *mod,
struct sof_source *source,
struct sof_sink *sink,
uint32_t frames);

/**
* \brief Returns Multiband DRC processing function.
Expand Down
131 changes: 93 additions & 38 deletions src/audio/multiband_drc/multiband_drc_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@

#include <stdint.h>
#include <sof/audio/format.h>
#include <sof/audio/sink_source_utils.h>
#include <sof/math/iir_df1.h>

#include "multiband_drc.h"
#include "../drc/drc_algorithm.h"

void multiband_drc_default_pass(const struct processing_module *mod,
const struct audio_stream *source,
struct audio_stream *sink,
uint32_t frames)
int multiband_drc_default_pass(const struct processing_module *mod,
struct sof_source *source,
struct sof_sink *sink,
uint32_t frames)
{
audio_stream_copy(source, 0, sink, 0, audio_stream_get_channels(source) * frames);
return source_to_sink_copy(source, sink, true, frames * source_get_frame_bytes(source));
}

static void multiband_drc_process_emp_crossover(struct multiband_drc_state *state,
Expand Down Expand Up @@ -203,10 +204,10 @@ static void multiband_drc_process_deemp(struct multiband_drc_state *state,
* :buf_drc_src[nch*nband] :buf_sink[nch]
*/
#if CONFIG_FORMAT_S16LE
static void multiband_drc_s16_default(const struct processing_module *mod,
const struct audio_stream *source,
struct audio_stream *sink,
uint32_t frames)
static int multiband_drc_s16_default(const struct processing_module *mod,
struct sof_source *source,
struct sof_sink *sink,
uint32_t frames)
{
struct multiband_drc_comp_data *cd = module_get_private_data(mod);
struct multiband_drc_state *state = &cd->state;
Expand All @@ -216,22 +217,35 @@ static void multiband_drc_s16_default(const struct processing_module *mod,
int32_t buf_drc_sink[PLATFORM_MAX_CHANNELS * SOF_MULTIBAND_DRC_MAX_BANDS];
int32_t *band_buf_drc_src;
int32_t *band_buf_drc_sink;
int16_t *x = audio_stream_get_rptr(source);
int16_t *y = audio_stream_get_wptr(sink);
const int16_t *x, *buf_x_start;
int16_t *y, *buf_y_start;
int buf_x_samples, buf_y_samples;
size_t n_bytes = frames * source_get_frame_bytes(source);
int band;
int nbuf;
int npcm;
int ret;
int ch;
int i;
int nch = audio_stream_get_channels(source);
int nch = source_get_channels(source);
int nband = cd->config->num_bands;
int enable_emp_deemp = cd->config->enable_emp_deemp;
int samples = frames * nch;

ret = source_get_data_s16(source, n_bytes, &x, &buf_x_start, &buf_x_samples);
if (ret)
return ret;

ret = sink_get_buffer_s16(sink, n_bytes, &y, &buf_y_start, &buf_y_samples);
if (ret) {
source_release_data(source, 0);
return ret;
}

while (samples) {
nbuf = audio_stream_samples_without_wrap_s16(source, x);
nbuf = cir_buf_samples_to_wrap_s16(x, buf_x_start, buf_x_samples);
npcm = MIN(samples, nbuf);
nbuf = audio_stream_samples_without_wrap_s16(sink, y);
nbuf = cir_buf_samples_to_wrap_s16(y, buf_y_start, buf_y_samples);
npcm = MIN(npcm, nbuf);
for (i = 0; i < npcm; i += nch) {
for (ch = 0; ch < nch; ch++) {
Expand Down Expand Up @@ -263,17 +277,22 @@ static void multiband_drc_s16_default(const struct processing_module *mod,
}
}
samples -= npcm;
x = audio_stream_wrap(source, x);
y = audio_stream_wrap(sink, y);
if (x >= buf_x_start + buf_x_samples)
x = buf_x_start;
if (y >= buf_y_start + buf_y_samples)
y = buf_y_start;
}
source_release_data(source, n_bytes);
sink_commit_buffer(sink, n_bytes);
return 0;
}
#endif /* CONFIG_FORMAT_S16LE */

#if CONFIG_FORMAT_S24LE
static void multiband_drc_s24_default(const struct processing_module *mod,
const struct audio_stream *source,
struct audio_stream *sink,
uint32_t frames)
static int multiband_drc_s24_default(const struct processing_module *mod,
struct sof_source *source,
struct sof_sink *sink,
uint32_t frames)
{
struct multiband_drc_comp_data *cd = module_get_private_data(mod);
struct multiband_drc_state *state = &cd->state;
Expand All @@ -283,22 +302,35 @@ static void multiband_drc_s24_default(const struct processing_module *mod,
int32_t buf_drc_sink[PLATFORM_MAX_CHANNELS * SOF_MULTIBAND_DRC_MAX_BANDS];
int32_t *band_buf_drc_src;
int32_t *band_buf_drc_sink;
int32_t *x = audio_stream_get_rptr(source);
int32_t *y = audio_stream_get_wptr(sink);
const int32_t *x, *buf_x_start;
int32_t *y, *buf_y_start;
int buf_x_samples, buf_y_samples;
size_t n_bytes = frames * source_get_frame_bytes(source);
int band;
int nbuf;
int npcm;
int ret;
int ch;
int i;
int nch = audio_stream_get_channels(source);
int nch = source_get_channels(source);
int nband = cd->config->num_bands;
int enable_emp_deemp = cd->config->enable_emp_deemp;
int samples = frames * nch;

ret = source_get_data_s32(source, n_bytes, &x, &buf_x_start, &buf_x_samples);
if (ret)
return ret;

ret = sink_get_buffer_s32(sink, n_bytes, &y, &buf_y_start, &buf_y_samples);
if (ret) {
source_release_data(source, 0);
return ret;
}

while (samples) {
nbuf = audio_stream_samples_without_wrap_s24(source, x);
nbuf = cir_buf_samples_to_wrap_s32(x, buf_x_start, buf_x_samples);
npcm = MIN(samples, nbuf);
nbuf = audio_stream_samples_without_wrap_s24(sink, y);
nbuf = cir_buf_samples_to_wrap_s32(y, buf_y_start, buf_y_samples);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@singalsu FYI, I think this is pattern we need for multiple modules

npcm = MIN(npcm, nbuf);
for (i = 0; i < npcm; i += nch) {
for (ch = 0; ch < nch; ch++) {
Expand Down Expand Up @@ -330,17 +362,22 @@ static void multiband_drc_s24_default(const struct processing_module *mod,
}
}
samples -= npcm;
x = audio_stream_wrap(source, x);
y = audio_stream_wrap(sink, y);
if (x >= buf_x_start + buf_x_samples)
x = buf_x_start;
if (y >= buf_y_start + buf_y_samples)
y = buf_y_start;
}
source_release_data(source, n_bytes);
sink_commit_buffer(sink, n_bytes);
return 0;
}
#endif /* CONFIG_FORMAT_S24LE */

#if CONFIG_FORMAT_S32LE
static void multiband_drc_s32_default(const struct processing_module *mod,
const struct audio_stream *source,
struct audio_stream *sink,
uint32_t frames)
static int multiband_drc_s32_default(const struct processing_module *mod,
struct sof_source *source,
struct sof_sink *sink,
uint32_t frames)
{
struct multiband_drc_comp_data *cd = module_get_private_data(mod);
struct multiband_drc_state *state = &cd->state;
Expand All @@ -350,22 +387,35 @@ static void multiband_drc_s32_default(const struct processing_module *mod,
int32_t buf_drc_sink[PLATFORM_MAX_CHANNELS * SOF_MULTIBAND_DRC_MAX_BANDS];
int32_t *band_buf_drc_src;
int32_t *band_buf_drc_sink;
int32_t *x = audio_stream_get_rptr(source);
int32_t *y = audio_stream_get_wptr(sink);
const int32_t *x, *buf_x_start;
int32_t *y, *buf_y_start;
int buf_x_samples, buf_y_samples;
size_t n_bytes = frames * source_get_frame_bytes(source);
int band;
int nbuf;
int npcm;
int ret;
int ch;
int i;
int nch = audio_stream_get_channels(source);
int nch = source_get_channels(source);
int nband = cd->config->num_bands;
int enable_emp_deemp = cd->config->enable_emp_deemp;
int samples = frames * nch;

ret = source_get_data_s32(source, n_bytes, &x, &buf_x_start, &buf_x_samples);
if (ret)
return ret;

ret = sink_get_buffer_s32(sink, n_bytes, &y, &buf_y_start, &buf_y_samples);
if (ret) {
source_release_data(source, 0);
return ret;
}

while (samples) {
nbuf = audio_stream_samples_without_wrap_s32(source, x);
nbuf = cir_buf_samples_to_wrap_s32(x, buf_x_start, buf_x_samples);
npcm = MIN(samples, nbuf);
nbuf = audio_stream_samples_without_wrap_s32(sink, y);
nbuf = cir_buf_samples_to_wrap_s32(y, buf_y_start, buf_y_samples);
npcm = MIN(npcm, nbuf);
for (i = 0; i < npcm; i += nch) {
for (ch = 0; ch < nch; ch++) {
Expand Down Expand Up @@ -397,9 +447,14 @@ static void multiband_drc_s32_default(const struct processing_module *mod,
}
}
samples -= npcm;
x = audio_stream_wrap(source, x);
y = audio_stream_wrap(sink, y);
if (x >= buf_x_start + buf_x_samples)
x = buf_x_start;
if (y >= buf_y_start + buf_y_samples)
y = buf_y_start;
}
source_release_data(source, n_bytes);
sink_commit_buffer(sink, n_bytes);
return 0;
}
#endif /* CONFIG_FORMAT_S32LE */

Expand Down
Loading
Loading