Skip to content

Commit 147b33a

Browse files
committed
copier: dai: apply gain feature
Add gain configuration and apply gain processing in copier dai. Signed-off-by: Ievgen Ganakov <ievgen.ganakov@intel.com>
1 parent 3ea2a2e commit 147b33a

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/audio/copier/copier_dai.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <sof/audio/module_adapter/module/generic.h>
1111
#include "copier.h"
1212
#include "dai_copier.h"
13+
#include "copier_gain.h"
1314

1415
LOG_MODULE_DECLARE(copier, CONFIG_SOF_LOG_LEVEL);
1516

@@ -217,9 +218,29 @@ static int copier_dai_init(struct comp_dev *dev,
217218
if (ret < 0)
218219
goto e_zephyr_free;
219220

221+
/* Allocate gain data if selected for this dai type and set basic params */
222+
if (dai->apply_gain) {
223+
struct copier_gain_params *gain_data = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED,
224+
0, SOF_MEM_CAPS_RAM,
225+
sizeof(*gain_data));
226+
if (!gain_data) {
227+
ret = -ENOMEM;
228+
goto e_zephyr_free;
229+
}
230+
cd->dd[index]->gain_data = gain_data;
231+
232+
ret = copier_gain_set_params(dev, cd->dd[index]);
233+
if (ret < 0) {
234+
comp_err(dev, "Failed to set gain params!");
235+
goto gain_free;
236+
}
237+
}
238+
220239
cd->endpoint_num++;
221240

222241
return 0;
242+
gain_free:
243+
rfree(dd->gain_data);
223244
e_zephyr_free:
224245
dai_common_free(dd);
225246
free_dd:
@@ -348,6 +369,7 @@ void copier_dai_free(struct copier_data *cd)
348369
{
349370
for (int i = 0; i < cd->endpoint_num; i++) {
350371
dai_common_free(cd->dd[i]);
372+
rfree(cd->dd[i]->gain_data);
351373
rfree(cd->dd[i]);
352374
}
353375
/* only dai have multi endpoint case */

src/audio/dai-zephyr.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <sof/audio/component_ext.h>
1010
#include <sof/audio/format.h>
1111
#include <sof/audio/pipeline.h>
12+
#include <module/module/base.h>
1213
#include <sof/common.h>
1314
#include <rtos/panic.h>
1415
#include <sof/ipc/msg.h>
@@ -37,6 +38,7 @@
3738

3839
#include "copier/copier.h"
3940
#include "copier/dai_copier.h"
41+
#include "copier/copier_gain.h"
4042

4143
#include <zephyr/device.h>
4244
#include <zephyr/drivers/dai.h>
@@ -319,6 +321,16 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
319321
ret = stream_copy_from_no_consume(dd->dma_buffer, dd->local_buffer,
320322
dd->process, bytes, dd->chmap);
321323
#if CONFIG_IPC_MAJOR_4
324+
/* Apply gain to the local buffer */
325+
if (dd->ipc_config.apply_gain) {
326+
ret = copier_gain_input(dev, dd->local_buffer, dd->gain_data,
327+
GAIN_ADD, bytes);
328+
if (ret)
329+
comp_err(dev, "copier_gain_input() failed err=%d", ret);
330+
buffer_stream_writeback(dd->local_buffer, bytes);
331+
}
332+
333+
struct list_item *sink_list;
322334
/* Skip in case of endpoint DAI devices created by the copier */
323335
if (converter) {
324336
/*

src/include/sof/audio/ipc-config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ struct ipc_config_dai {
8080
const struct ipc4_audio_format *out_fmt;/**< audio format for output pin 0 - required
8181
* for ACE 2.0 and newer
8282
*/
83+
/* Gain feature flag */
84+
bool apply_gain;
8385
};
8486

8587
/* generic volume component */

0 commit comments

Comments
 (0)