Skip to content

Commit

Permalink
Audio: Crossover: Avoid issue with __sparse_cache address spaces
Browse files Browse the repository at this point in the history
The issue with __sparse_cache in sinks[] array seems quite
complicated to change so avoiding it with further module API
conversion seems like better approach.

The processing functions in crossover_generic.c are changed to
use struct output_stream_buffer pointer array from module API.

The function crossover_assign_sinks() is changed to pick the
output stream buffers from module API in the order that is
defined in configuration blob.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
  • Loading branch information
singalsu authored and cujomalainey committed Aug 24, 2023
1 parent 6403e62 commit e887eb0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
16 changes: 9 additions & 7 deletions src/audio/crossover/crossover.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ static int crossover_get_stream_index(struct processing_module *mod,
* config->num_sinks if no errors were found.
*/
static int crossover_assign_sinks(struct processing_module *mod,
struct comp_buffer **sinks,
struct output_stream_buffer *output_buffers,
struct output_stream_buffer **assigned_obufs,
bool *enabled)
{
struct comp_data *cd = module_get_private_data(mod);
Expand Down Expand Up @@ -157,7 +158,7 @@ static int crossover_assign_sinks(struct processing_module *mod,

/* If no config is set, then assign the sinks in order */
if (!config) {
sinks[num_sinks++] = sink;
assigned_obufs[num_sinks++] = &output_buffers[j];
enabled[j++] = true;
continue;
}
Expand All @@ -174,14 +175,14 @@ static int crossover_assign_sinks(struct processing_module *mod,
break;
}

if (sinks[i]) {
if (assigned_obufs[i]) {
comp_err(dev,
"crossover_assign_sinks(), multiple sinks from pipeline %d are assigned",
sink_id);
break;
}

sinks[i] = sink;
assigned_obufs[i] = &output_buffers[j];
enabled[j++] = true;
num_sinks++;
}
Expand Down Expand Up @@ -618,7 +619,7 @@ static int crossover_process_audio_stream(struct processing_module *mod,
struct output_stream_buffer *output_buffers,
int num_output_buffers)
{
struct comp_buffer *sinks[SOF_CROSSOVER_MAX_STREAMS] = { NULL };
struct output_stream_buffer *assigned_obufs[SOF_CROSSOVER_MAX_STREAMS] = { NULL };
bool enabled_buffers[PLATFORM_MAX_STREAMS] = { false };
struct comp_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;
Expand Down Expand Up @@ -653,7 +654,8 @@ static int crossover_process_audio_stream(struct processing_module *mod,
* state than the component. Therefore not all sinks are guaranteed
* to be assigned: sink[i] can be NULL, 0 <= i <= config->num_sinks
*/
num_assigned_sinks = crossover_assign_sinks(mod, sinks, enabled_buffers);
num_assigned_sinks = crossover_assign_sinks(mod, output_buffers, assigned_obufs,
enabled_buffers);
if (cd->config && num_assigned_sinks != cd->config->num_sinks)
comp_dbg(dev, "crossover_copy(), number of assigned sinks (%i) does not match number of sinks in config (%i).",
num_assigned_sinks, cd->config->num_sinks);
Expand All @@ -670,7 +672,7 @@ static int crossover_process_audio_stream(struct processing_module *mod,
if (!frames)
return -ENODATA;

cd->crossover_process(cd, input_buffers, sinks, num_sinks, frames);
cd->crossover_process(cd, input_buffers, assigned_obufs, num_sinks, frames);

processed_bytes = frames * frame_bytes;
mod->input_buffers[0].consumed = processed_bytes;
Expand Down
36 changes: 21 additions & 15 deletions src/audio/crossover/crossover_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ static void crossover_generic_split_4way(int32_t in,
#if CONFIG_FORMAT_S16LE
static void crossover_s16_default_pass(struct comp_data *cd,
struct input_stream_buffer *bsource,
struct comp_buffer __sparse_cache *sinks[],
struct output_stream_buffer **bsinks,
int32_t num_sinks,
uint32_t frames)
{
const struct audio_stream __sparse_cache *sink_stream;
const struct audio_stream __sparse_cache *source_stream = bsource->data;
int16_t *x;
int32_t *y;
Expand All @@ -102,9 +103,11 @@ static void crossover_s16_default_pass(struct comp_data *cd,
for (i = 0; i < n; i++) {
x = audio_stream_read_frag_s16(source_stream, i);
for (j = 0; j < num_sinks; j++) {
if (!sinks[j])
if (!bsinks[j])
continue;
y = audio_stream_write_frag_s16((&sinks[j]->stream), i);

sink_stream = bsinks[j]->data;
y = audio_stream_write_frag_s16(sink_stream, i);
*y = *x;
}
}
Expand All @@ -114,10 +117,11 @@ static void crossover_s16_default_pass(struct comp_data *cd,
#if CONFIG_FORMAT_S24LE || CONFIG_FORMAT_S32LE
static void crossover_s32_default_pass(struct comp_data *cd,
struct input_stream_buffer *bsource,
struct comp_buffer __sparse_cache *sinks[],
struct output_stream_buffer **bsinks,
int32_t num_sinks,
uint32_t frames)
{
const struct audio_stream __sparse_cache *sink_stream;
const struct audio_stream __sparse_cache *source_stream = bsource->data;
int32_t *x, *y;
int i, j;
Expand All @@ -126,9 +130,11 @@ static void crossover_s32_default_pass(struct comp_data *cd,
for (i = 0; i < n; i++) {
x = audio_stream_read_frag_s32(source_stream, i);
for (j = 0; j < num_sinks; j++) {
if (!sinks[j])
if (!bsinks[j])
continue;
y = audio_stream_write_frag_s32((&sinks[j]->stream), i);

sink_stream = bsinks[j]->data;
y = audio_stream_write_frag_s32(sink_stream, i);
*y = *x;
}
}
Expand All @@ -138,7 +144,7 @@ static void crossover_s32_default_pass(struct comp_data *cd,
#if CONFIG_FORMAT_S16LE
static void crossover_s16_default(struct comp_data *cd,
struct input_stream_buffer *bsource,
struct comp_buffer __sparse_cache *sinks[],
struct output_stream_buffer **bsinks,
int32_t num_sinks,
uint32_t frames)
{
Expand All @@ -159,9 +165,9 @@ static void crossover_s16_default(struct comp_data *cd,
cd->crossover_split(*x << 16, out, state);

for (j = 0; j < num_sinks; j++) {
if (!sinks[j])
if (!bsinks[j])
continue;
sink_stream = &sinks[j]->stream;
sink_stream = bsinks[j]->data;
y = audio_stream_write_frag_s16(sink_stream,
idx);
*y = sat_int16(Q_SHIFT_RND(out[j], 31, 15));
Expand All @@ -176,7 +182,7 @@ static void crossover_s16_default(struct comp_data *cd,
#if CONFIG_FORMAT_S24LE
static void crossover_s24_default(struct comp_data *cd,
struct input_stream_buffer *bsource,
struct comp_buffer __sparse_cache *sinks[],
struct output_stream_buffer **bsinks,
int32_t num_sinks,
uint32_t frames)
{
Expand All @@ -197,9 +203,9 @@ static void crossover_s24_default(struct comp_data *cd,
cd->crossover_split(*x << 8, out, state);

for (j = 0; j < num_sinks; j++) {
if (!sinks[j])
if (!bsinks[j])
continue;
sink_stream = &sinks[j]->stream;
sink_stream = bsinks[j]->data;
y = audio_stream_write_frag_s32(sink_stream,
idx);
*y = sat_int24(Q_SHIFT_RND(out[j], 31, 23));
Expand All @@ -214,7 +220,7 @@ static void crossover_s24_default(struct comp_data *cd,
#if CONFIG_FORMAT_S32LE
static void crossover_s32_default(struct comp_data *cd,
struct input_stream_buffer *bsource,
struct comp_buffer __sparse_cache *sinks[],
struct output_stream_buffer **bsinks,
int32_t num_sinks,
uint32_t frames)
{
Expand All @@ -235,9 +241,9 @@ static void crossover_s32_default(struct comp_data *cd,
cd->crossover_split(*x, out, state);

for (j = 0; j < num_sinks; j++) {
if (!sinks[j])
if (!bsinks[j])
continue;
sink_stream = &sinks[j]->stream;
sink_stream = bsinks[j]->data;
y = audio_stream_write_frag_s32(sink_stream,
idx);
*y = out[j];
Expand Down
2 changes: 1 addition & 1 deletion src/include/sof/audio/crossover/crossover.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct comp_data;

typedef void (*crossover_process)(struct comp_data *cd,
struct input_stream_buffer *bsource,
struct comp_buffer __sparse_cache *sinks[],
struct output_stream_buffer *bsinks[],
int32_t num_sinks,
uint32_t frames);

Expand Down

0 comments on commit e887eb0

Please sign in to comment.