Skip to content

Commit bf1e3b7

Browse files
MingJenTailgirdwood
authored andcommitted
Support both 48kHz and 16kHz recording
Add 48kHz recording support to RTNR Signed-off-by: Ming Jen Tai <mingjen_tai@realtek.com>
1 parent de408a2 commit bf1e3b7

9 files changed

Lines changed: 171 additions & 48 deletions

File tree

src/audio/rtnr/rtnr.c

Lines changed: 63 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,58 @@ static rtnr_func rtnr_find_func(enum sof_ipc_frame fmt)
181181
return NULL;
182182
}
183183

184+
static inline void rtnr_set_process(struct comp_dev *dev)
185+
{
186+
comp_info(dev, "rtnr_set_process()");
187+
struct comp_data *cd = comp_get_drvdata(dev);
188+
189+
cd->process_enable = true;
190+
RTKMA_API_Bypass(cd->rtk_agl, 0);
191+
}
192+
193+
static inline void rtnr_set_bypass(struct comp_dev *dev)
194+
{
195+
comp_info(dev, "rtnr_set_bypass()");
196+
struct comp_data *cd = comp_get_drvdata(dev);
197+
198+
cd->process_enable = false;
199+
RTKMA_API_Bypass(cd->rtk_agl, 1);
200+
}
201+
202+
static inline void rtnr_set_process_sample_rate(struct comp_dev *dev, uint32_t sample_rate)
203+
{
204+
comp_dbg(dev, "rtnr_set_process_sample_rate()");
205+
struct comp_data *cd = comp_get_drvdata(dev);
206+
207+
cd->process_sample_rate = sample_rate;
208+
}
209+
210+
static int32_t rtnr_check_config_validity(struct comp_dev *dev,
211+
struct comp_data *cd)
212+
{
213+
struct sof_rtnr_config *p_config = comp_get_data_blob(cd->model_handler, NULL, NULL);
214+
int ret = 0;
215+
216+
if (!p_config) {
217+
comp_err(dev, "rtnr_check_config_validity() error: invalid cd->model_handler");
218+
ret = -EINVAL;
219+
} else {
220+
comp_info(dev, "rtnr_check_config_validity() enabled: %d sample_rate:%d",
221+
p_config->params.enabled,
222+
p_config->params.sample_rate);
223+
224+
if (p_config->params.enabled)
225+
rtnr_set_process(dev);
226+
else
227+
rtnr_set_bypass(dev);
228+
229+
rtnr_set_process_sample_rate(dev, p_config->params.sample_rate);
230+
}
231+
232+
return ret;
233+
}
234+
235+
184236
/*
185237
* End of RTNR setup code. Next the standard component methods.
186238
*/
@@ -235,7 +287,14 @@ static struct comp_dev *rtnr_new(const struct comp_driver *drv,
235287
/* Component defaults */
236288
cd->source_channel = 0;
237289

238-
cd->rtk_agl = RTKMA_API_Context_Create();
290+
/* Check config */
291+
ret = rtnr_check_config_validity(dev, cd);
292+
if (ret < 0) {
293+
comp_cl_err(&comp_rtnr, "rtnr_new(): rtnr_check_config_validity() failed.");
294+
goto cd_fail;
295+
}
296+
297+
cd->rtk_agl = RTKMA_API_Context_Create(cd->process_sample_rate);
239298
if (cd->rtk_agl == 0) {
240299
comp_cl_err(&comp_rtnr, "rtnr_new(): RTKMA_API_Context_Create failed.");
241300
goto cd_fail;
@@ -303,6 +362,9 @@ static int rtnr_params(struct comp_dev *dev, struct sof_ipc_stream_params *param
303362
case 16000:
304363
comp_info(dev, "rtnr_params(), sample rate = 16000 kHz");
305364
break;
365+
case 48000:
366+
comp_info(dev, "rtnr_params(), sample rate = 48000 kHz");
367+
break;
306368
default:
307369
comp_err(dev, "rtnr_nr_params(), invalid sample rate(%d kHz)",
308370
sourceb->stream.rate);
@@ -317,24 +379,6 @@ static int rtnr_params(struct comp_dev *dev, struct sof_ipc_stream_params *param
317379
return 0;
318380
}
319381

320-
static inline void rtnr_set_process(struct comp_dev *dev)
321-
{
322-
comp_info(dev, "rtnr_set_process()");
323-
struct comp_data *cd = comp_get_drvdata(dev);
324-
325-
cd->process_enable = true;
326-
RTKMA_API_Bypass(cd->rtk_agl, 0);
327-
}
328-
329-
static inline void rtnr_set_bypass(struct comp_dev *dev)
330-
{
331-
comp_info(dev, "rtnr_set_bypass()");
332-
struct comp_data *cd = comp_get_drvdata(dev);
333-
334-
cd->process_enable = false;
335-
RTKMA_API_Bypass(cd->rtk_agl, 1);
336-
}
337-
338382
static int rtnr_cmd_get_data(struct comp_dev *dev,
339383
struct sof_ipc_ctrl_data *cdata, int max_size)
340384
{
@@ -355,28 +399,6 @@ static int rtnr_cmd_get_data(struct comp_dev *dev,
355399
return ret;
356400
}
357401

358-
static int32_t rtnr_check_config_validity(struct comp_dev *dev,
359-
struct comp_data *cd)
360-
{
361-
struct sof_rtnr_config *p_config = comp_get_data_blob(cd->model_handler, NULL, NULL);
362-
int ret = 0;
363-
364-
if (!p_config) {
365-
comp_err(dev, "rtnr_check_config_validity() error: invalid cd->model_handler");
366-
ret = -EINVAL;
367-
} else {
368-
comp_info(dev, "rtnr_check_config_validity() params.enabled: %d",
369-
p_config->params.enabled);
370-
371-
if (p_config->params.enabled)
372-
rtnr_set_process(dev);
373-
else
374-
rtnr_set_bypass(dev);
375-
}
376-
377-
return ret;
378-
}
379-
380402
static int rtnr_cmd_set_data(struct comp_dev *dev,
381403
struct sof_ipc_ctrl_data *cdata)
382404
{

src/include/sof/audio/rtnr/rtklib/include/RTK_MA_API.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void RTKMA_API_Process(void *Context, _Bool has_ref, int SampleRate, int MicCh);
3232

3333
void RTKMA_API_Prepare(void *Context);
3434

35-
void *RTKMA_API_Context_Create(void);
35+
void *RTKMA_API_Context_Create(int sample_rate);
3636

3737
void RTKMA_API_Context_Free(void *Context);
3838

src/include/sof/audio/rtnr/rtnr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct comp_data {
3434
uint32_t sink_rate;
3535
uint32_t source_rate;
3636
bool process_enable;
37+
uint32_t process_sample_rate;
3738
int ref_shift;
3839
bool ref_32bits;
3940
bool ref_active;

src/include/user/rtnr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
struct sof_rtnr_params {
1616
/* 1 to enable RTNR, 0 to disable it */
1717
int32_t enabled;
18+
uint32_t sample_rate;
19+
int32_t reserved;
1820
} __attribute__((packed, aligned(4)));
1921

2022
struct sof_rtnr_config {

src/platform/tigerlake/include/platform/lib/memory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,9 @@
264264
#define RT_TIMES 3
265265
#define RT_SHARED_TIMES 6
266266
#else
267+
/* Reserve more memory for RTNR */
267268
#ifdef CONFIG_COMP_RTNR
268-
#define RT_TIMES 6
269+
#define RT_TIMES 5
269270
#define RT_SHARED_TIMES 11
270271
#else
271272
#define RT_TIMES 8

tools/topology/topology1/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ set(TPLGS
136136
"sof-tgl-max98357a-rt5682\;sof-tgl-max98357a-rt5682-pdm1\;-DCODEC=MAX98357A\;-DFMT=s16le\;-DDMIC_DAI_LINK_16k_PDM=STEREO_PDM1\;-DPLATFORM=tgl\;-DAMP_SSP=1"
137137
"sof-tgl-max98357a-rt5682\;sof-tgl-max98357a-rt5682-pdm1-drceq\;-DCODEC=MAX98357A\;-DFMT=s16le\;-DDMIC_DAI_LINK_16k_PDM=STEREO_PDM1\;-DPLATFORM=tgl\;-DAMP_SSP=1\;-DDRC_EQ"
138138
"sof-tgl-max98357a-rt5682\;sof-tgl-rt1011-rt5682\;-DCODEC=RT1011\;-DFMT=s24le\;-DPLATFORM=tgl\;-DAMP_SSP=1"
139-
"sof-tgl-max98357a-rt5682\;sof-tgl-max98357a-rt5682-rtnr\;-DCODEC=MAX98357A\;-DFMT=s16le\;-DPLATFORM=tgl\;-DAMP_SSP=1\;-DCHANNELS=2\;-DDMICPROC=eq-iir-volume\;-DRTNR"
139+
"sof-tgl-max98357a-rt5682\;sof-tgl-max98357a-rt5682-rtnr\;-DCODEC=MAX98357A\;-DFMT=s16le\;-DPLATFORM=tgl\;-DAMP_SSP=1\;-DCHANNELS=2\;-DDMIC16KPROC=eq-iir-volume\;-DRTNR"
140140
"sof-tgl-max98357a-rt5682-rtnr-16kHz\;sof-tgl-max98357a-rt5682-rtnr-16kHz\;-DCODEC=MAX98357A\;-DFMT=s16le\;-DCHANNELS=2\;-DDMICPROC=eq-iir-volume\;-DRTNR"
141141
"sof-tgl-max98373-rt5682\;sof-tgl-max98373-rt5682\;-DAMP_SSP=1"
142142
"sof-tgl-max98373-rt5682\;sof-tgl-max98373-rt5682-igonr\;-DAMP_SSP=1\;-DIGO"

tools/topology/topology1/sof-tgl-max98357a-rt5682.m4

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ define(DMIC_DAI_LINK_16k_ID, `2')
9999
define(KWD_PIPE_SCH_DEADLINE_US, 5000)
100100

101101
# if RTNR is defined, define DMIC16KPROC as rtnr
102-
ifdef(`RTNR',`', define(DMIC16KPROC, rtnr))
102+
ifdef(`RTNR',
103+
`define(DMICPROC, rtnr)',
104+
`ifdef(`DMICPROC', , `define(DMICPROC, eq-iir-volume)')')
105+
106+
ifdef(`RTNR',
107+
`define(DMIC16KPROC, rtnr)',
108+
`ifdef(`DMIC16KPROC', , `define(DMIC16KPROC, eq-iir-volume)')')
103109

104110
# include the generic dmic if RTNR is defined, else include generic dmic with kwd
105111
include(ifdef(`RTNR', platform/intel/intel-generic-dmic.m4, platform/intel/intel-generic-dmic-kwd.m4))

tools/topology/topology1/sof/pipe-rtnr-capture-16khz.m4

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ define(DEF_RTNR_BYTES, concat(`rtnr_bytes_', PIPELINE_ID))
2727

2828
CONTROLBYTES_PRIV(DEF_RTNR_PRIV,
2929
` bytes "0x53,0x4f,0x46,0x00,0x00,0x00,0x00,0x00,'
30-
` 0x18,0x00,0x00,0x00,0x00,0x30,0x01,0x03,'
30+
` 0x20,0x00,0x00,0x00,0x00,0x30,0x01,0x03,'
3131
` 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'
3232
` 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'
33-
` 0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'
33+
` 0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'
3434
` 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'
35-
` 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00"'
35+
` 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,'
36+
` 0x80,0x3e,0x00,0x00,0x00,0x00,0x00,0x00"'
3637
)
3738

3839
# RTNR Bytes control with max value of 255
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Capture RTNR Pipeline and PCM
2+
#
3+
# Pipeline Endpoints for connection are :-
4+
#
5+
# host PCM_C <--- B1 <--- RTNR 0 <-- B0 <-- sink DAI0
6+
#
7+
#
8+
#
9+
10+
# Include topology builder
11+
include(`utils.m4')
12+
include(`buffer.m4')
13+
include(`pcm.m4')
14+
include(`dai.m4')
15+
include(`pipeline.m4')
16+
include(`bytecontrol.m4')
17+
include(`rtnr.m4')
18+
19+
ifdef(`RTNR_BUFFER_SIZE_MIN',`', define(RTNR_BUFFER_SIZE_MIN, `65536'))
20+
ifdef(`RTNR_BUFFER_SIZE_MAX',`', define(RTNR_BUFFER_SIZE_MAX, `65536'))
21+
#
22+
# Controls
23+
#
24+
25+
define(DEF_RTNR_PRIV, concat(`rtnr_priv_', PIPELINE_ID))
26+
define(DEF_RTNR_BYTES, concat(`rtnr_bytes_', PIPELINE_ID))
27+
28+
CONTROLBYTES_PRIV(DEF_RTNR_PRIV,
29+
` bytes "0x53,0x4f,0x46,0x00,0x00,0x00,0x00,0x00,'
30+
` 0x20,0x00,0x00,0x00,0x00,0x30,0x01,0x03,'
31+
` 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'
32+
` 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'
33+
` 0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'
34+
` 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'
35+
` 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,'
36+
` 0x80,0xbb,0x00,0x00,0x00,0x00,0x00,0x00"'
37+
)
38+
39+
# RTNR Bytes control with max value of 255
40+
C_CONTROLBYTES(DEF_RTNR_BYTES, PIPELINE_ID,
41+
CONTROLBYTES_OPS(bytes, 258 binds the mixer control to bytes get/put handlers, 258, 258),
42+
CONTROLBYTES_EXTOPS(258 binds the mixer control to bytes get/put handlers, 258, 258),
43+
, , ,
44+
CONTROLBYTES_MAX(, 256),
45+
,
46+
DEF_RTNR_PRIV)
47+
48+
49+
#
50+
# Components and Buffers
51+
#
52+
53+
# Host "Capture" PCM
54+
# with 0 sink and 2 source periods
55+
W_PCM_CAPTURE(PCM_ID, Capture, 0, 2, SCHEDULE_CORE)
56+
57+
# "RTNR 0" has 2 sink period and 2 source periods
58+
W_RTNR(0, PIPELINE_FORMAT, 2, DAI_PERIODS, SCHEDULE_CORE, LIST(` ', "DEF_RTNR_BYTES"))
59+
60+
# Capture Buffers
61+
W_BUFFER(0, COMP_BUFFER_SIZE(4,
62+
COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS,
63+
eval(PCM_MAX_RATE / SCHEDULE_PERIOD)), PLATFORM_PASS_MEM_CAP)
64+
65+
W_BUFFER(1, COMP_BUFFER_SIZE(4,
66+
COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS,
67+
eval(PCM_MAX_RATE / SCHEDULE_PERIOD)), PLATFORM_PASS_MEM_CAP)
68+
69+
P_GRAPH(pipe-rtnr-capture-PIPELINE_ID, PIPELINE_ID,
70+
LIST(` ',
71+
`dapm(N_PCMC(PCM_ID), N_BUFFER(1))',
72+
`dapm(N_BUFFER(1), N_RTNR(0))',
73+
`dapm(N_RTNR(0), N_BUFFER(0))'))
74+
75+
#
76+
# Pipeline Source and Sinks
77+
#
78+
indir(`define', concat(`PIPELINE_SINK_', PIPELINE_ID), N_BUFFER(0))
79+
indir(`define', concat(`PIPELINE_PCM_', PIPELINE_ID), Capture PCM_ID)
80+
81+
#
82+
# PCM Configuration
83+
#
84+
85+
PCM_CAPABILITIES(Capture PCM_ID, CAPABILITY_FORMAT_NAME(PIPELINE_FORMAT),
86+
PCM_MIN_RATE, PCM_MAX_RATE, PIPELINE_CHANNELS, PIPELINE_CHANNELS,
87+
2, 16, 192, 16384, RTNR_BUFFER_SIZE_MIN, RTNR_BUFFER_SIZE_MAX)
88+
89+
undefine(`DEF_RTNR_PRIV')
90+
undefine(`DEF_RTNR_BYTES')

0 commit comments

Comments
 (0)