From e58baafb34804fdbc54b6773ce5d44b9bbe4229c Mon Sep 17 00:00:00 2001 From: Ming Jen Tai Date: Fri, 20 May 2022 14:13:36 +0800 Subject: [PATCH 1/4] rtnr: passthrough audio by stream copy This commit passthrough multi channels audio from microphone using stream copy outside RTNR, instead of using the bypass function provided by RTNR. Signed-off-by: Ming Jen Tai (cherry picked from commit 605c6662712655adc2ca417b639c1a1523468920) --- src/audio/rtnr/rtnr.c | 95 ++++++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 37 deletions(-) diff --git a/src/audio/rtnr/rtnr.c b/src/audio/rtnr/rtnr.c index 780dfb281652..1dbf54962cbe 100644 --- a/src/audio/rtnr/rtnr.c +++ b/src/audio/rtnr/rtnr.c @@ -342,8 +342,8 @@ static int rtnr_params(struct comp_dev *dev, struct sof_ipc_stream_params *param return -EINVAL; } - if (sourceb->stream.channels != 2 || sinkb->stream.channels != 2) { - comp_err(dev, "rtnr_params(), source/sink stream must be 2 channels"); + if (sourceb->stream.channels != sinkb->stream.channels) { + comp_err(dev, "rtnr_params(), source/sink stream must have same channels"); return -EINVAL; } @@ -435,8 +435,13 @@ static int32_t rtnr_set_value(struct comp_dev *dev, struct sof_ipc_ctrl_data *cd comp_info(dev, "rtnr_set_value(), value = %u", val); } - cd->process_enable = !val; - RTKMA_API_Bypass(cd->rtk_agl, !val); + if (val) { + comp_info(dev, "rtnr_set_value(): enabled"); + cd->process_enable = true; + } else { + comp_info(dev, "rtnr_set_value(): passthrough"); + cd->process_enable = false; + } return 0; } @@ -529,66 +534,82 @@ static int rtnr_copy(struct comp_dev *dev) int frames; int sink_bytes; int source_bytes; + struct comp_copy_limits cl; struct comp_data *cd = comp_get_drvdata(dev); struct audio_stream_rtnr *sources_stream[RTNR_MAX_SOURCES]; struct audio_stream_rtnr *sink_stream = &cd->sink_stream; int32_t i; - comp_dbg(dev, "rtnr_copy()"); - for (i = 0; i < RTNR_MAX_SOURCES; ++i) sources_stream[i] = &cd->sources_stream[i]; + comp_dbg(dev, "rtnr_copy()"); + source = list_first_item(&dev->bsource_list, struct comp_buffer, sink_list); /* put empty data into output queue*/ RTKMA_API_First_Copy(cd->rtk_agl, cd->source_rate, source->stream.channels); sink = list_first_item(&dev->bsink_list, struct comp_buffer, source_list); - frames = audio_stream_avail_frames(&source->stream, &sink->stream); - /* Process integer multiple of RTNR internal block length */ - frames = frames & ~RTNR_BLK_LENGTH_MASK; + if (cd->process_enable) { + frames = audio_stream_avail_frames(&source->stream, &sink->stream); - comp_dbg(dev, "rtnr_copy() source->id: %d, frames = %d", source->id, frames); + /* Process integer multiple of RTNR internal block length */ + frames = frames & ~RTNR_BLK_LENGTH_MASK; - if (frames) { - source_bytes = frames * audio_stream_frame_bytes(&source->stream); - sink_bytes = frames * audio_stream_frame_bytes(&sink->stream); + comp_dbg(dev, "rtnr_copy() source->id: %d, frames = %d", source->id, frames); - buffer_stream_invalidate(source, source_bytes); + if (frames) { + source_bytes = frames * audio_stream_frame_bytes(&source->stream); + sink_bytes = frames * audio_stream_frame_bytes(&sink->stream); - /* Run processing function */ + buffer_stream_invalidate(source, source_bytes); - /* - * Processing function uses an array of pointers to source streams - * as parameter. - */ + /* Run processing function */ - /* copy required data from sof audio stream to RTNR audio stream */ - rtnr_copy_from_sof_stream(sources_stream[0], &source->stream); - rtnr_copy_from_sof_stream(sink_stream, &sink->stream); + /* copy required data from sof audio stream to RTNR audio stream */ + rtnr_copy_from_sof_stream(sources_stream[0], &source->stream); + rtnr_copy_from_sof_stream(sink_stream, &sink->stream); - cd->rtnr_func(dev, (struct audio_stream_rtnr **)&sources_stream, sink_stream, - frames); + /* + * Processing function uses an array of pointers to source streams + * as parameter. + */ + cd->rtnr_func(dev, (struct audio_stream_rtnr **)&sources_stream, + sink_stream, frames); - /* - * real process function of rtnr, consume/produce data from internal queue - * instead of component buffer - */ - RTKMA_API_Process(cd->rtk_agl, 0, cd->source_rate, MicNum); + /* + * real process function of rtnr, consume/produce data from internal queue + * instead of component buffer + */ + RTKMA_API_Process(cd->rtk_agl, 0, cd->source_rate, MicNum); - /* copy required data from RTNR audio stream to sof audio stream */ - rtnr_copy_to_sof_stream(&source->stream, sources_stream[0]); - rtnr_copy_to_sof_stream(&sink->stream, sink_stream); + /* copy required data from RTNR audio stream to sof audio stream */ + rtnr_copy_to_sof_stream(&source->stream, sources_stream[0]); + rtnr_copy_to_sof_stream(&sink->stream, sink_stream); - buffer_stream_writeback(sink, sink_bytes); + buffer_stream_writeback(sink, sink_bytes); - /* Track consume and produce */ - comp_update_buffer_consume(source, source_bytes); - comp_update_buffer_produce(sink, sink_bytes); - } + /* Track consume and produce */ + comp_update_buffer_consume(source, source_bytes); + comp_update_buffer_produce(sink, sink_bytes); + } + } else { + comp_dbg(dev, "rtnr_copy() passthrough"); + + /* Get source, sink, number of frames etc. to process. */ + comp_get_copy_limits_with_lock(source, sink, &cl); + buffer_stream_invalidate(source, cl.source_bytes); + + audio_stream_copy(&source->stream, 0, &sink->stream, 0, + source->stream.channels * cl.frames); + + buffer_stream_writeback(sink, cl.sink_bytes); + comp_update_buffer_consume(source, cl.source_bytes); + comp_update_buffer_produce(sink, cl.sink_bytes); + } return 0; } From 24041660244700f70fbbafdd2582b74631f9166d Mon Sep 17 00:00:00 2001 From: Curtis Malainey Date: Fri, 1 Apr 2022 15:34:39 -0700 Subject: [PATCH 2/4] m4: add RO bytecontrol Sometimes we want to load a binary block of data without letting userspace interact with the underlying control. An RO control will do this exactly by loading the data and providing no write access. Signed-off-by: Curtis Malainey (cherry picked from commit 9cf8e0c777e6b4f4073bff5591bde51640eeb148) --- tools/topology/topology1/m4/bytecontrol.m4 | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/topology/topology1/m4/bytecontrol.m4 b/tools/topology/topology1/m4/bytecontrol.m4 index 1e5972086611..56014f19b8bb 100644 --- a/tools/topology/topology1/m4/bytecontrol.m4 +++ b/tools/topology/topology1/m4/bytecontrol.m4 @@ -79,6 +79,33 @@ define(`C_CONTROLBYTES', ` ]' `}') +dnl C_CONTROLBYTES_READONLY(name, index, ops, base, num_regs, mask, max, tlv, priv) +define(`C_CONTROLBYTES_READONLY', +`SectionControlBytes.STR($1) {' +`' +` # control belongs to this index group' +` index STR($2)' +`' +` # control uses bespoke driver get/put/info ID for io ops' +` $3' +` # control uses bespoke driver get/put/info ID for ext ops' +` $4' +`' +` # default base/num_regs/mask to avoid NULL STR' +` ifelse($5, `', base STR(XX), base STR($5))' +` ifelse($6, `', num_regs STR(XX), num_regs STR($6)`')' +` ifelse($7, `', mask STR(XX), mask STR($7)`')' +` $8' +` $9' +` access [' +` tlv_read' +` tlv_callback' +` ]' +` data [' +` $10' +` ]' +`}') + # Readonly byte control to read the actual value from DSP dnl C_CONTROLBYTES_VOLATILE_READONLY(name, index, ops, base, num_regs, mask, max, tlv, priv) define(`C_CONTROLBYTES_VOLATILE_READONLY', From 7716ffb2040fbf20fdb3dc1f380c781dd3dd347b Mon Sep 17 00:00:00 2001 From: Pin-chih Lin Date: Tue, 24 May 2022 15:13:45 +0800 Subject: [PATCH 3/4] rtnr: add rtnr-only override config Enables component RTNR for mt8195 binary Signed-off-by: Pin-chih Lin (cherry picked from commit 6c1dd397f576f17fdaa68222f5da1531432d023e) --- src/arch/xtensa/configs/override/mt8195_chrome_rtnr.config | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/arch/xtensa/configs/override/mt8195_chrome_rtnr.config diff --git a/src/arch/xtensa/configs/override/mt8195_chrome_rtnr.config b/src/arch/xtensa/configs/override/mt8195_chrome_rtnr.config new file mode 100644 index 000000000000..96da46bb8baa --- /dev/null +++ b/src/arch/xtensa/configs/override/mt8195_chrome_rtnr.config @@ -0,0 +1 @@ +CONFIG_COMP_RTNR=y From c4c4b9c9ba57d34dd4fdc37a26be499c84f45d43 Mon Sep 17 00:00:00 2001 From: Pin-chih Lin Date: Tue, 24 May 2022 15:12:51 +0800 Subject: [PATCH 4/4] topology1: rtnr: set bytes control to read-only Due to security requirement, the config bytes control is set to read-only for RTNR with hard-coded the config blob in the topology. It's WA until the security approval is obtained. Signed-off-by: Pin-chih Lin (cherry picked from commit 5df56355d150fc47c308e7f6cd407fe3d95e51f4) --- .../sof/pipe-google-rtc-audio-processing-rtnr-capture.m4 | 6 +++--- tools/topology/topology1/sof/pipe-rtnr-capture.m4 | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/topology/topology1/sof/pipe-google-rtc-audio-processing-rtnr-capture.m4 b/tools/topology/topology1/sof/pipe-google-rtc-audio-processing-rtnr-capture.m4 index c4deb6ff2606..96b62685a53b 100644 --- a/tools/topology/topology1/sof/pipe-google-rtc-audio-processing-rtnr-capture.m4 +++ b/tools/topology/topology1/sof/pipe-google-rtc-audio-processing-rtnr-capture.m4 @@ -47,9 +47,9 @@ CONTROLBYTES_PRIV(DEF_RTNR_PRIV, ) # RTNR Bytes control with max value of 255 -C_CONTROLBYTES(DEF_RTNR_BYTES, PIPELINE_ID, - CONTROLBYTES_OPS(bytes, 258 binds the mixer control to bytes get/put handlers, 258, 258), - CONTROLBYTES_EXTOPS(258 binds the mixer control to bytes get/put handlers, 258, 258), +C_CONTROLBYTES_READONLY(DEF_RTNR_BYTES, PIPELINE_ID, + CONTROLBYTES_OPS(bytes, 258 binds the mixer control to bytes get handlers, 258), + CONTROLBYTES_EXTOPS(258 binds the mixer control to bytes get handlers, 258), , , , CONTROLBYTES_MAX(, 256), , diff --git a/tools/topology/topology1/sof/pipe-rtnr-capture.m4 b/tools/topology/topology1/sof/pipe-rtnr-capture.m4 index cffa27c82833..5a4b6650cfd1 100644 --- a/tools/topology/topology1/sof/pipe-rtnr-capture.m4 +++ b/tools/topology/topology1/sof/pipe-rtnr-capture.m4 @@ -38,9 +38,9 @@ CONTROLBYTES_PRIV(DEF_RTNR_PRIV, ) # RTNR Bytes control with max value of 255 -C_CONTROLBYTES(DEF_RTNR_BYTES, PIPELINE_ID, - CONTROLBYTES_OPS(bytes, 258 binds the mixer control to bytes get/put handlers, 258, 258), - CONTROLBYTES_EXTOPS(258 binds the mixer control to bytes get/put handlers, 258, 258), +C_CONTROLBYTES_READONLY(DEF_RTNR_BYTES, PIPELINE_ID, + CONTROLBYTES_OPS(bytes, 258 binds the mixer control to bytes get handlers, 258), + CONTROLBYTES_EXTOPS(258 binds the mixer control to bytes get handlers, 258), , , , CONTROLBYTES_MAX(, 256), ,