Skip to content

Commit

Permalink
smart_amp: remove buffer_acquire from smart_amp
Browse files Browse the repository at this point in the history
remove buffer ops from smart_amp module

this is a continuation of changes
from commit 4a03699

Signed-off-by: Tobiasz Dryjanski <[email protected]>
  • Loading branch information
tobonex committed Sep 18, 2023
1 parent 7c68489 commit 3d232d9
Showing 1 changed file with 33 additions and 57 deletions.
90 changes: 33 additions & 57 deletions src/audio/smart_amp/smart_amp.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,7 @@ static int smart_amp_trigger(struct comp_dev *dev, int cmd)
case COMP_TRIGGER_START:
case COMP_TRIGGER_RELEASE:
if (sad->feedback_buf) {
struct comp_buffer *buf = buffer_acquire(sad->feedback_buf);
buffer_zero(buf);
buffer_release(buf);
buffer_zero(sad->feedback_buf);
}
break;
case COMP_TRIGGER_PAUSE:
Expand Down Expand Up @@ -558,10 +556,7 @@ static int smart_amp_process(struct comp_dev *dev,
static smart_amp_proc get_smart_amp_process(struct comp_dev *dev)
{
struct smart_amp_data *sad = comp_get_drvdata(dev);
struct comp_buffer *source_buf = buffer_acquire(sad->source_buf);
enum sof_ipc_frame fmt = audio_stream_get_frm_fmt(&source_buf->stream);

buffer_release(source_buf);
enum sof_ipc_frame fmt = audio_stream_get_frm_fmt(&sad->source_buf->stream);

switch (fmt) {
case SOF_IPC_FRAME_S16_LE:
Expand All @@ -577,8 +572,6 @@ static smart_amp_proc get_smart_amp_process(struct comp_dev *dev)
static int smart_amp_copy(struct comp_dev *dev)
{
struct smart_amp_data *sad = comp_get_drvdata(dev);
struct comp_buffer *source_buf = buffer_acquire(sad->source_buf);
struct comp_buffer *sink_buf = buffer_acquire(sad->sink_buf);
uint32_t avail_passthrough_frames;
uint32_t avail_feedback_frames;
uint32_t avail_frames;
Expand All @@ -589,56 +582,49 @@ static int smart_amp_copy(struct comp_dev *dev)
comp_dbg(dev, "smart_amp_copy()");

/* available bytes and samples calculation */
avail_passthrough_frames = audio_stream_avail_frames(&source_buf->stream,
&sink_buf->stream);
avail_passthrough_frames = audio_stream_avail_frames(&sad->source_buf->stream,
&sad->sink_buf->stream);

avail_frames = avail_passthrough_frames;

if (sad->feedback_buf) {
struct comp_buffer *feedback_buf = buffer_acquire(sad->feedback_buf);

if (comp_get_state(dev, feedback_buf->source) == dev->state) {
if (comp_get_state(dev, sad->feedback_buf->source) == dev->state) {
/* feedback */
avail_feedback_frames =
audio_stream_get_avail_frames(&feedback_buf->stream);
audio_stream_get_avail_frames(&sad->feedback_buf->stream);

avail_feedback_frames = MIN(avail_passthrough_frames,
avail_feedback_frames);

feedback_bytes = avail_feedback_frames *
audio_stream_frame_bytes(&feedback_buf->stream);
audio_stream_frame_bytes(&sad->feedback_buf->stream);

comp_dbg(dev, "smart_amp_copy(): processing %d feedback frames (avail_passthrough_frames: %d)",
avail_feedback_frames, avail_passthrough_frames);

/* perform buffer writeback after source_buf process */
buffer_stream_invalidate(feedback_buf, feedback_bytes);
sad->process(dev, &feedback_buf->stream,
&sink_buf->stream, avail_feedback_frames,
buffer_stream_invalidate(sad->feedback_buf, feedback_bytes);
sad->process(dev, &sad->feedback_buf->stream,
&sad->sink_buf->stream, avail_feedback_frames,
sad->config.feedback_ch_map, true);

comp_update_buffer_consume(feedback_buf, feedback_bytes);
comp_update_buffer_consume(sad->feedback_buf, feedback_bytes);
}

buffer_release(feedback_buf);
}

/* bytes calculation */
source_bytes = avail_frames * audio_stream_frame_bytes(&source_buf->stream);
sink_bytes = avail_frames * audio_stream_frame_bytes(&sink_buf->stream);
source_bytes = avail_frames * audio_stream_frame_bytes(&sad->source_buf->stream);
sink_bytes = avail_frames * audio_stream_frame_bytes(&sad->sink_buf->stream);

/* process data */
buffer_stream_invalidate(source_buf, source_bytes);
sad->process(dev, &source_buf->stream, &sink_buf->stream,
buffer_stream_invalidate(sad->source_buf, source_bytes);
sad->process(dev, &sad->source_buf->stream, &sad->sink_buf->stream,
avail_frames, sad->config.source_ch_map, false);
buffer_stream_writeback(sink_buf, sink_bytes);
buffer_stream_writeback(sad->sink_buf, sink_bytes);

/* source/sink buffer pointers update */
comp_update_buffer_consume(source_buf, source_bytes);
comp_update_buffer_produce(sink_buf, sink_bytes);

buffer_release(sink_buf);
buffer_release(source_buf);
comp_update_buffer_consume(sad->source_buf, source_bytes);
comp_update_buffer_produce(sad->sink_buf, sink_bytes);

return 0;
}
Expand All @@ -661,7 +647,6 @@ static int smart_amp_reset(struct comp_dev *dev)
static int smart_amp_prepare(struct comp_dev *dev)
{
struct smart_amp_data *sad = comp_get_drvdata(dev);
struct comp_buffer *source_c, *buf_c;
struct list_item *blist;
int ret;
int bitwidth;
Expand All @@ -676,45 +661,38 @@ static int smart_amp_prepare(struct comp_dev *dev)
list_for_item(blist, &dev->bsource_list) {
struct comp_buffer *source_buffer = container_of(blist, struct comp_buffer,
sink_list);
source_c = buffer_acquire(source_buffer);

if (source_c->source->ipc_config.type == SOF_COMP_DEMUX) {
if (source_buffer->source->ipc_config.type == SOF_COMP_DEMUX) {
sad->feedback_buf = source_buffer;
} else {
sad->source_buf = source_buffer;
sad->in_channels = audio_stream_get_channels(&source_c->stream);
sad->in_channels = audio_stream_get_channels(&source_buffer->stream);
}

buffer_release(source_c);
}

sad->sink_buf = list_first_item(&dev->bsink_list, struct comp_buffer,
source_list);

buf_c = buffer_acquire(sad->sink_buf);
sad->out_channels = audio_stream_get_channels(&buf_c->stream);
buffer_release(buf_c);

source_c = buffer_acquire(sad->source_buf);
sad->out_channels = audio_stream_get_channels(&sad->sink_buf->stream);

if (sad->feedback_buf) {
buf_c = buffer_acquire(sad->feedback_buf);

audio_stream_set_channels(&buf_c->stream, sad->config.feedback_channels);
audio_stream_set_rate(&buf_c->stream, audio_stream_get_rate(&source_c->stream));
buffer_release(buf_c);

ret = smart_amp_check_audio_fmt(audio_stream_get_rate(&source_c->stream),
audio_stream_get_channels(&source_c->stream));
audio_stream_set_channels(&sad->feedback_buf->stream,
sad->config.feedback_channels);
audio_stream_set_rate(&sad->feedback_buf->stream,
audio_stream_get_rate(&sad->source_buf->stream));

ret = smart_amp_check_audio_fmt(audio_stream_get_rate(&sad->source_buf->stream),
audio_stream_get_channels
(&sad->source_buf->stream));
if (ret) {
comp_err(dev, "[DSM] Format not supported, sample rate: %d, ch: %d",
audio_stream_get_rate(&source_c->stream),
audio_stream_get_channels(&source_c->stream));
audio_stream_get_rate(&sad->source_buf->stream),
audio_stream_get_channels(&sad->source_buf->stream));
goto error;
}
}

switch (audio_stream_get_frm_fmt(&source_c->stream)) {
switch (audio_stream_get_frm_fmt(&sad->source_buf->stream)) {
case SOF_IPC_FRAME_S16_LE:
bitwidth = 16;
break;
Expand All @@ -726,7 +704,7 @@ static int smart_amp_prepare(struct comp_dev *dev)
break;
default:
comp_err(dev, "[DSM] smart_amp_process() error: not supported frame format %d",
audio_stream_get_frm_fmt(&source_c->stream));
audio_stream_get_frm_fmt(&sad->source_buf->stream));
goto error;
}

Expand All @@ -751,8 +729,6 @@ static int smart_amp_prepare(struct comp_dev *dev)
}

error:
buffer_release(source_c);

smart_amp_flush(sad->mod_handle, dev);
return ret;
}
Expand Down

0 comments on commit 3d232d9

Please sign in to comment.