copier: dai: apply gain feature

Add gain configuration and apply gain processing in copier dai.

Signed-off-by: Ievgen Ganakov <ievgen.ganakov@intel.com>
This commit is contained in:
Ievgen Ganakov 2024-07-18 17:20:59 +02:00 committed by Liam Girdwood
parent 0c9094bcc5
commit b6f6f6aee4
3 changed files with 35 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#include <sof/audio/module_adapter/module/generic.h>
#include "copier.h"
#include "dai_copier.h"
#include "copier_gain.h"
LOG_MODULE_DECLARE(copier, CONFIG_SOF_LOG_LEVEL);
@ -217,9 +218,29 @@ static int copier_dai_init(struct comp_dev *dev,
if (ret < 0)
goto e_zephyr_free;
/* Allocate gain data if selected for this dai type and set basic params */
if (dai->apply_gain) {
struct copier_gain_params *gain_data = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED,
0, SOF_MEM_CAPS_RAM,
sizeof(*gain_data));
if (!gain_data) {
ret = -ENOMEM;
goto e_zephyr_free;
}
cd->dd[index]->gain_data = gain_data;
ret = copier_gain_set_params(dev, cd->dd[index]);
if (ret < 0) {
comp_err(dev, "Failed to set gain params!");
goto gain_free;
}
}
cd->endpoint_num++;
return 0;
gain_free:
rfree(dd->gain_data);
e_zephyr_free:
dai_common_free(dd);
free_dd:
@ -348,6 +369,7 @@ void copier_dai_free(struct copier_data *cd)
{
for (int i = 0; i < cd->endpoint_num; i++) {
dai_common_free(cd->dd[i]);
rfree(cd->dd[i]->gain_data);
rfree(cd->dd[i]);
}
/* only dai have multi endpoint case */

View File

@ -9,6 +9,7 @@
#include <sof/audio/component_ext.h>
#include <sof/audio/format.h>
#include <sof/audio/pipeline.h>
#include <module/module/base.h>
#include <sof/common.h>
#include <rtos/panic.h>
#include <sof/ipc/msg.h>
@ -37,6 +38,7 @@
#include "copier/copier.h"
#include "copier/dai_copier.h"
#include "copier/copier_gain.h"
#include <zephyr/device.h>
#include <zephyr/drivers/dai.h>
@ -319,6 +321,15 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
ret = stream_copy_from_no_consume(dd->dma_buffer, dd->local_buffer,
dd->process, bytes, dd->chmap);
#if CONFIG_IPC_MAJOR_4
/* Apply gain to the local buffer */
if (dd->ipc_config.apply_gain) {
ret = copier_gain_input(dev, dd->local_buffer, dd->gain_data,
GAIN_ADD, bytes);
if (ret)
comp_err(dev, "copier_gain_input() failed err=%d", ret);
buffer_stream_writeback(dd->local_buffer, bytes);
}
/* Skip in case of endpoint DAI devices created by the copier */
if (converter) {
/*

View File

@ -80,6 +80,8 @@ struct ipc_config_dai {
const struct ipc4_audio_format *out_fmt;/**< audio format for output pin 0 - required
* for ACE 2.0 and newer
*/
/* Gain feature flag */
bool apply_gain;
};
/* generic volume component */