Skip to content

Commit

Permalink
copier: dai: apply gain feature
Browse files Browse the repository at this point in the history
Add gain configuration and apply gain processing in copier dai.

Signed-off-by: Ievgen Ganakov <ievgen.ganakov@intel.com>
  • Loading branch information
iganakov committed Sep 5, 2024
1 parent eb8625c commit 74948d2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/audio/copier/copier_dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 */
Expand Down
11 changes: 11 additions & 0 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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);
}

struct list_item *sink_list;
/* Skip in case of endpoint DAI devices created by the copier */
if (converter) {
Expand Down
2 changes: 2 additions & 0 deletions src/include/sof/audio/ipc-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 74948d2

Please sign in to comment.