Skip to content

Commit

Permalink
Audio: Optimize sink checks in crossover_s32_default
Browse files Browse the repository at this point in the history
Optimize crossover_s32_default by pre-determining the active
sinks before processing frames. This check-in reduces redundant
null checks for each frame and channel, leading to performance
improvements in processing audio streams with multiple sinks.

Signed-off-by: Shriram Shastry <[email protected]>
  • Loading branch information
ShriramShastry committed May 31, 2024
1 parent 8af48c0 commit f32aebb
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/audio/crossover/crossover_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,32 +225,38 @@ static void crossover_s32_default(struct comp_data *cd,
int32_t num_sinks,
uint32_t frames)
{
struct crossover_state *state;
const struct audio_stream *source_stream = bsource->data;
struct audio_stream *sink_stream;
int32_t *x, *y;
int ch, i, j;
int idx;
int nch = audio_stream_get_channels(source_stream);
int32_t out[num_sinks];
/* Array to hold active sink streams; initialized to null */
struct audio_stream *sink_stream[SOF_CROSSOVER_MAX_STREAMS] = { NULL };
int active_sinks = 0; /* Counter for active sink streams */
int ch, i, j; /* Indices for channels, frames, sinks */
struct crossover_state *state; /* Current crossover channel state */
const struct audio_stream *source_stream = bsource->data; /* Source stream */
int32_t *x, *y; /* Source and sink frame pointers */
int nch = audio_stream_get_channels(source_stream); /* Channel count */
int32_t out[num_sinks]; /* Frame output for sinks */

/* Identify active sinks, avoid processing null sinks later */
for (j = 0; j < num_sinks; j++) {
if (bsinks[j])
sink_stream[active_sinks++] = bsinks[j]->data;
}

/* Process for each channel */
for (ch = 0; ch < nch; ch++) {
idx = ch;
state = &cd->state[ch];
state = &cd->state[ch]; /* Set current crossover state */
/* Iterate over frames */
for (i = 0; i < frames; i++) {
x = audio_stream_read_frag_s32(source_stream, idx);
/* Read source */
x = audio_stream_read_frag_s32(source_stream, ch + i * nch);
/* Apply crossover split */
cd->crossover_split(*x, out, state);

for (j = 0; j < num_sinks; j++) {
if (!bsinks[j])
continue;
sink_stream = bsinks[j]->data;
y = audio_stream_write_frag_s32(sink_stream,
idx);
/* Write output to active sinks */
for (j = 0; j < active_sinks; j++) {
y = audio_stream_write_frag_s32(sink_stream[j], ch + i * nch);
/* Copy processed data to sink */
*y = out[j];
}

idx += nch;
}
}
}
}
Expand Down

0 comments on commit f32aebb

Please sign in to comment.