Skip to content

Commit 6e461bd

Browse files
mbukowsklgirdwood
authored andcommitted
copier: gain: interface changes for setting gain params
Change type of arguments for gain params setting functions. DAI data struct is replaced by gain_params. Components other than DAI can also use copier gain feature (eg. microphone privacy) Signed-off-by: Michal Bukowski <[email protected]>
1 parent 5716bae commit 6e461bd

File tree

5 files changed

+41
-32
lines changed

5 files changed

+41
-32
lines changed

src/audio/copier/copier_dai.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ static int copier_dai_init(struct comp_dev *dev,
229229
}
230230
cd->dd[index]->gain_data = gain_data;
231231

232-
ret = copier_gain_set_params(dev, cd->dd[index]);
232+
ret = copier_gain_set_params(dev, cd->dd[index]->gain_data,
233+
GAIN_DEFAULT_FADE_PERIOD,
234+
cd->dd[index]->dai->type);
233235
if (ret < 0) {
234236
comp_err(dev, "Failed to set gain params!");
235237
goto gain_free;

src/audio/copier/copier_gain.c

+16-14
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@
1515

1616
LOG_MODULE_DECLARE(copier, CONFIG_SOF_LOG_LEVEL);
1717

18-
int copier_gain_set_params(struct comp_dev *dev, struct dai_data *dd)
18+
int copier_gain_set_params(struct comp_dev *dev,
19+
struct copier_gain_params *gain_params,
20+
uint32_t fade_period,
21+
enum sof_ipc_dai_type dai_type)
1922
{
2023
struct processing_module *mod = comp_mod(dev);
2124
struct copier_data *cd = module_get_private_data(mod);
2225
struct ipc4_base_module_cfg *ipc4_cfg = &cd->config.base;
2326
uint32_t sampling_freq = ipc4_cfg->audio_fmt.sampling_frequency;
2427
uint32_t frames = sampling_freq / dev->pipeline->period;
25-
uint32_t fade_period = GAIN_DEFAULT_FADE_PERIOD;
2628
int ret;
2729

2830
/* Set basic gain parameters */
29-
copier_gain_set_basic_params(dev, dd, ipc4_cfg);
31+
copier_gain_set_basic_params(dev, gain_params, ipc4_cfg);
3032

31-
switch (dd->dai->type) {
33+
switch (dai_type) {
3234
case SOF_DAI_INTEL_DMIC:
3335
{
3436
struct dmic_config_data *dmic_cfg = cd->gtw_cfg;
@@ -43,18 +45,18 @@ int copier_gain_set_params(struct comp_dev *dev, struct dai_data *dd)
4345
/* Get fade period from DMIC blob */
4446
fade_period = dmic_glb_cfg->ext_global_cfg.fade_in_period;
4547
/* Convert and assign silence and fade length values */
46-
dd->gain_data->silence_sg_length =
48+
gain_params->silence_sg_length =
4749
frames * dmic_glb_cfg->ext_global_cfg.silence_period;
48-
dd->gain_data->fade_sg_length = frames * fade_period;
50+
gain_params->fade_sg_length = frames * fade_period;
4951
}
5052
break;
5153
default:
52-
comp_info(dev, "Apply default fade period for dai type %d", dd->dai->type);
54+
comp_info(dev, "Apply default fade period for dai type %d", dai_type);
5355
break;
5456
}
5557

5658
/* Set fade parameters */
57-
ret = copier_gain_set_fade_params(dev, dd, ipc4_cfg, fade_period, frames);
59+
ret = copier_gain_set_fade_params(dev, gain_params, ipc4_cfg, fade_period, frames);
5860
if (ret)
5961
comp_err(dev, "Failed to set fade params");
6062

@@ -150,7 +152,10 @@ int copier_gain_dma_control(union ipc4_connector_node_id node, const char *confi
150152
break;
151153
}
152154

153-
ret = copier_set_gain(dev, cd->dd[0], gain_data);
155+
struct ipc4_copier_module_cfg *copier_cfg = cd->dd[0]->dai_spec_config;
156+
const int channels = copier_cfg->base.audio_fmt.channels_count;
157+
158+
ret = copier_set_gain(dev, cd->dd[0]->gain_data, gain_data, channels);
154159
if (ret)
155160
comp_err(dev, "Gain DMA control: failed to set gain");
156161
return ret;
@@ -159,12 +164,9 @@ int copier_gain_dma_control(union ipc4_connector_node_id node, const char *confi
159164
return -ENODEV;
160165
}
161166

162-
int copier_set_gain(struct comp_dev *dev, struct dai_data *dd,
163-
struct gain_dma_control_data *gain_data)
167+
int copier_set_gain(struct comp_dev *dev, struct copier_gain_params *gain_params,
168+
struct gain_dma_control_data *gain_data, int channels)
164169
{
165-
struct copier_gain_params *gain_params = dd->gain_data;
166-
struct ipc4_copier_module_cfg *copier_cfg = dd->dai_spec_config;
167-
const int channels = copier_cfg->base.audio_fmt.channels_count;
168170
uint16_t static_gain[MAX_GAIN_COEFFS_CNT];
169171
int ret;
170172

src/audio/copier/copier_gain.h

+14-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <sof/audio/buffer.h>
1212
#include <ipc4/base_fw.h>
13+
#include <ipc4/gateway.h>
1314
#include <ipc/dai.h>
1415
#if SOF_USE_HIFI(3, COPIER) || SOF_USE_HIFI(4, COPIER) || SOF_USE_HIFI(5, COPIER)
1516
#include <xtensa/tie/xt_hifi3.h>
@@ -117,10 +118,13 @@ struct gain_dma_control_data {
117118
* the given device and DAI data.
118119
*
119120
* @param dev The pointer to the component device structure.
120-
* @param dd The pointer to the DAI data structure.
121+
* @param gain_params The pointer to gain params structure.
122+
* @param fade_period The fade period in milliseconds.
123+
* @param dai_type DAI type
121124
* @return 0 on success, negative error code on failure.
122125
*/
123-
int copier_gain_set_params(struct comp_dev *dev, struct dai_data *dd);
126+
int copier_gain_set_params(struct comp_dev *dev, struct copier_gain_params *gain_params,
127+
uint32_t fade_period, enum sof_ipc_dai_type dai_type);
124128

125129
/**
126130
* @brief Sets the basic gain parameters.
@@ -129,10 +133,10 @@ int copier_gain_set_params(struct comp_dev *dev, struct dai_data *dd);
129133
* by the given device and DAI data.
130134
*
131135
* @param dev The pointer to the component device structure.
132-
* @param dd The pointer to the DAI data structure.
136+
* @param gain_params The pointer to gain params structure.
133137
* @param ipc4_cfg The pointer to the IPC4 base module config.
134138
*/
135-
void copier_gain_set_basic_params(struct comp_dev *dev, struct dai_data *dd,
139+
void copier_gain_set_basic_params(struct comp_dev *dev, struct copier_gain_params *gain_params,
136140
struct ipc4_base_module_cfg *ipc4_cfg);
137141

138142
/**
@@ -142,13 +146,13 @@ void copier_gain_set_basic_params(struct comp_dev *dev, struct dai_data *dd,
142146
* by the given device and DAI data.
143147
*
144148
* @param dev The pointer to the component device structure.
145-
* @param dd The pointer to the DAI data structure.
149+
* @param gain_params The pointer to gain params structure.
146150
* @param ipc4_cfg The pointer to the IPC4 base module config.
147151
* @param fade_period The fade period in milliseconds.
148152
* @param frames The number of frames to fade.
149153
* @return 0 on success, negative error code on failure.
150154
*/
151-
int copier_gain_set_fade_params(struct comp_dev *dev, struct dai_data *dd,
155+
int copier_gain_set_fade_params(struct comp_dev *dev, struct copier_gain_params *gain_params,
152156
struct ipc4_base_module_cfg *ipc4_cfg,
153157
uint32_t fade_period, uint32_t frames);
154158

@@ -209,12 +213,13 @@ enum copier_gain_state copier_gain_eval_state(struct copier_gain_params *gain_pa
209213
* Sets/modify gain for a copier module in runtime.
210214
*
211215
* @param dev The copier device structure.
212-
* @param dd The DAI data structure.
216+
* @param gain_params The pointer to the copier_gain_params structure.
213217
* @param gain_data The gain control data structure.
218+
* @param channels Number of audio channels.
214219
* @return 0 on success, otherwise a negative error code.
215220
*/
216-
int copier_set_gain(struct comp_dev *dev, struct dai_data *dd,
217-
struct gain_dma_control_data *gain_data);
221+
int copier_set_gain(struct comp_dev *dev, struct copier_gain_params *gain_params,
222+
struct gain_dma_control_data *gain_data, int channels);
218223

219224
/**
220225
* Checks for unity gain mode.

src/audio/copier/copier_generic.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,20 @@ int apply_attenuation(struct comp_dev *dev, struct copier_data *cd,
6060
}
6161
}
6262

63-
void copier_gain_set_basic_params(struct comp_dev *dev, struct dai_data *dd,
63+
void copier_gain_set_basic_params(struct comp_dev *dev, struct copier_gain_params *gain_params,
6464
struct ipc4_base_module_cfg *ipc4_cfg)
6565
{
66-
struct copier_gain_params *gain_params = dd->gain_data;
6766

6867
gain_params->channels_count = ipc4_cfg->audio_fmt.channels_count;
6968

7069
for (int i = 0; i < MAX_GAIN_COEFFS_CNT; i++)
7170
gain_params->gain_coeffs[i] = UNITY_GAIN_GENERIC;
7271
}
7372

74-
int copier_gain_set_fade_params(struct comp_dev *dev, struct dai_data *dd,
73+
int copier_gain_set_fade_params(struct comp_dev *dev, struct copier_gain_params *gain_params,
7574
struct ipc4_base_module_cfg *ipc4_cfg,
7675
uint32_t fade_period, uint32_t frames)
7776
{
78-
struct copier_gain_params *gain_params = dd->gain_data;
7977
uint16_t step_i64_to_i16;
8078

8179
if (fade_period == GAIN_DEFAULT_FADE_PERIOD) {
@@ -88,6 +86,8 @@ int copier_gain_set_fade_params(struct comp_dev *dev, struct dai_data *dd,
8886
/* Special case for GAIN_ZERO_TRANS_MS to support zero fade-in transition time */
8987
gain_params->fade_sg_length = 0;
9088
return 0;
89+
} else {
90+
gain_params->fade_sg_length = frames * fade_period;
9191
}
9292

9393
/* High precision step for fade-in calculation, keeps accurate precision */

src/audio/copier/copier_hifi.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ int apply_attenuation(struct comp_dev *dev, struct copier_data *cd,
7575
}
7676
}
7777

78-
void copier_gain_set_basic_params(struct comp_dev *dev, struct dai_data *dd,
78+
void copier_gain_set_basic_params(struct comp_dev *dev, struct copier_gain_params *gain_params,
7979
struct ipc4_base_module_cfg *ipc4_cfg)
8080
{
81-
struct copier_gain_params *gain_params = dd->gain_data;
8281

8382
/* Set default gain coefficients */
8483
for (int i = 0; i < ARRAY_SIZE(gain_params->gain_coeffs); ++i)
@@ -91,11 +90,10 @@ void copier_gain_set_basic_params(struct comp_dev *dev, struct dai_data *dd,
9190
gain_params->channels_count = ipc4_cfg->audio_fmt.channels_count;
9291
}
9392

94-
int copier_gain_set_fade_params(struct comp_dev *dev, struct dai_data *dd,
93+
int copier_gain_set_fade_params(struct comp_dev *dev, struct copier_gain_params *gain_params,
9594
struct ipc4_base_module_cfg *ipc4_cfg,
9695
uint32_t fade_period, uint32_t frames)
9796
{
98-
struct copier_gain_params *gain_params = dd->gain_data;
9997
uint16_t init_gain[MAX_GAIN_COEFFS_CNT];
10098
uint16_t step_i64_to_i16;
10199
ae_f16 step_f16;
@@ -113,6 +111,8 @@ int copier_gain_set_fade_params(struct comp_dev *dev, struct dai_data *dd,
113111
/* Special case for GAIN_ZERO_TRANS_MS to support zero fade in transition time */
114112
gain_params->fade_sg_length = 0;
115113
return 0;
114+
} else {
115+
gain_params->fade_sg_length = frames * fade_period;
116116
}
117117

118118
/* High precision step for fade-in calculation, keeps accurate precision */

0 commit comments

Comments
 (0)