Skip to content

Commit a8bd16a

Browse files
committed
Audio: DRC: Add processing enable switch control
This patch adds to DRC component in IPC4 mode a control to switch processing on/off. The control is useful for DRC pipeline that is used for both headphone (unprocessed) and speaker (processed). It also allows the user to switch off DRC processing if desired. If a blob has enable set to false the processing cannot be enabled with the switch control. If the blob enables processing, the user space can control processing on or off. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent 486ccfe commit a8bd16a

3 files changed

Lines changed: 49 additions & 6 deletions

File tree

src/audio/drc/drc.c

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ static int drc_init(struct processing_module *mod)
184184
}
185185

186186
drc_reset_state(&cd->state);
187+
188+
/* Initialize DRC to enabled. If defined by topology, a control may set
189+
* enabled to false before prepare() or during streaming with the switch
190+
* control from user space.
191+
*/
192+
cd->enabled = true;
193+
cd->enable_switch = true;
187194
return 0;
188195

189196
cd_fail:
@@ -203,15 +210,40 @@ static int drc_free(struct processing_module *mod)
203210
return 0;
204211
}
205212

206-
static int drc_set_config(struct processing_module *mod, uint32_t config_id,
213+
static int drc_set_config(struct processing_module *mod, uint32_t param_id,
207214
enum module_cfg_fragment_position pos, uint32_t data_offset_size,
208215
const uint8_t *fragment, size_t fragment_size, uint8_t *response,
209216
size_t response_size)
210217
{
211218
struct drc_comp_data *cd = module_get_private_data(mod);
219+
struct comp_dev *dev = mod->dev;
220+
221+
comp_dbg(dev, "drc_set_config()");
212222

213-
comp_info(mod->dev, "drc_set_config()");
223+
#if CONFIG_IPC_MAJOR_4
224+
struct sof_ipc4_control_msg_payload *ctl = (struct sof_ipc4_control_msg_payload *)fragment;
225+
226+
switch (param_id) {
227+
case SOF_IPC4_SWITCH_CONTROL_PARAM_ID:
228+
if (ctl->id == SOF_DRC_CTRL_INDEX_ENABLE_SWITCH &&
229+
ctl->num_elems == SOF_DRC_NUM_ELEMS_ENABLE_SWITCH) {
230+
cd->enable_switch = ctl->chanv[0].value;
231+
comp_info(dev, "drc_set_config(), enable_switch = %d", cd->enable_switch);
232+
} else {
233+
comp_err(dev, "Illegal switch control id = %d, num_elems = %d",
234+
ctl->id, ctl->num_elems);
235+
return -EINVAL;
236+
}
214237

238+
return 0;
239+
240+
case SOF_IPC4_ENUM_CONTROL_PARAM_ID:
241+
comp_err(dev, "drc_set_config(), illegal control.");
242+
return -EINVAL;
243+
}
244+
#endif
245+
246+
comp_info(dev, "drc_set_config(), bytes control");
215247
return comp_data_blob_set(cd->model_handler, pos, data_offset_size, fragment,
216248
fragment_size);
217249
}
@@ -262,6 +294,9 @@ static int drc_process(struct processing_module *mod,
262294
}
263295
}
264296

297+
/* Control pass-though in processing function with switch control */
298+
cd->enabled = cd->config && cd->config->params.enabled && cd->enable_switch;
299+
265300
cd->drc_func(mod, source, sink, frames);
266301

267302
/* calc new free and available */

src/audio/drc/drc.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ struct comp_dev;
3333
#define DRC_DIVISION_FRAMES 32
3434
#define DRC_DIVISION_FRAMES_MASK (DRC_DIVISION_FRAMES - 1)
3535

36+
/* First switch control instance is zero (SOF_IPC4_SWITCH_CONTROL_PARAM_ID), and the
37+
* control is common for all channels.
38+
*/
39+
#define SOF_DRC_CTRL_INDEX_ENABLE_SWITCH 0
40+
#define SOF_DRC_NUM_ELEMS_ENABLE_SWITCH 1
41+
3642
/* Stores the state of DRC */
3743
struct drc_state {
3844
/* The detector_average is the target gain obtained by looking at the
@@ -71,8 +77,10 @@ struct drc_comp_data {
7177
struct comp_data_blob_handler *model_handler;
7278
struct sof_drc_config *config; /**< pointer to setup blob */
7379
bool config_ready; /**< set when fully received */
80+
bool enabled; /**< control processing via blob and switch */
81+
bool enable_switch; /**< enable switch state */
7482
enum sof_ipc_frame source_format; /**< source frame format */
75-
drc_func drc_func; /**< processing function */
83+
drc_func drc_func; /**< processing function */
7684
};
7785

7886
struct drc_proc_fnmap {

src/audio/drc/drc_generic.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ static void drc_s16_default(struct processing_module *mod,
544544
int fragment_samples;
545545
int fragment;
546546

547-
if (!p->enabled) {
547+
if (!cd->enabled) {
548548
/* Delay the input sample only and don't do other processing. This is used when the
549549
* DRC is disabled. We want to do this to match the processing delay of other bands
550550
* in multi-band DRC kernel case.
@@ -690,7 +690,7 @@ static void drc_s24_default(struct processing_module *mod,
690690
int fragment_samples;
691691
int fragment;
692692

693-
if (!p->enabled) {
693+
if (!cd->enabled) {
694694
/* Delay the input sample only and don't do other processing. This is used when the
695695
* DRC is disabled. We want to do this to match the processing delay of other bands
696696
* in multi-band DRC kernel case. Note: use 32 bit delay function.
@@ -738,7 +738,7 @@ static void drc_s32_default(struct processing_module *mod,
738738
int fragment_samples;
739739
int fragment;
740740

741-
if (!p->enabled) {
741+
if (!cd->enabled) {
742742
/* Delay the input sample only and don't do other processing. This is used when the
743743
* DRC is disabled. We want to do this to match the processing delay of other bands
744744
* in multi-band DRC kernel case.

0 commit comments

Comments
 (0)