Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions src/audio/codec_adapter/codec/cadence.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,110 @@ int cadence_codec_init(struct comp_dev *dev)
return ret;
}

static int update_stream_sample_rate(struct comp_dev *dev)
{
struct comp_data *ca_data = comp_get_drvdata(dev);
struct codec_data *codec = comp_get_codec(dev);
struct cadence_codec_data *cd = codec->private;
struct sof_ipc_stream_params *stream = &ca_data->stream_params;
uint32_t api_id = CODEC_GET_API_ID(codec->id);
uint32_t sample_rate_id;
int ret;

switch (api_id) {
case CADENCE_CODEC_WRAPPER_ID:
sample_rate_id = CADENCE_SAMPLE_RATE_ID;
break;
default:
return 0;
}

API_CALL(cd, XA_API_CMD_SET_CONFIG_PARAM, sample_rate_id, &stream->rate, ret);
if (LIB_IS_FATAL_ERROR(ret)) {
comp_err(dev, "update_stream_sample_params(): failed to set sample rate.");
return ret;
}

return 0;
}

static int update_stream_sample_width(struct comp_dev *dev)
{
struct comp_data *ca_data = comp_get_drvdata(dev);
struct codec_data *codec = comp_get_codec(dev);
struct cadence_codec_data *cd = codec->private;
struct sof_ipc_stream_params *stream = &ca_data->stream_params;
uint32_t api_id = CODEC_GET_API_ID(codec->id);
uint32_t sample_width = (stream->frame_fmt == SOF_IPC_FRAME_S16_LE) ? 16 : 32;
uint32_t sample_width_id;
int ret;

switch (api_id) {
case CADENCE_CODEC_WRAPPER_ID:
sample_width_id = CADENCE_SAMPLE_WIDTH_ID;
break;
default:
return 0;
}

API_CALL(cd, XA_API_CMD_SET_CONFIG_PARAM, sample_width_id, &sample_width, ret);
if (LIB_IS_FATAL_ERROR(ret)) {
comp_err(dev, "update_stream_sample_width(): failed to set sample width.");
return ret;
}

return 0;
}

static int update_stream_channels(struct comp_dev *dev)
{
struct comp_data *ca_data = comp_get_drvdata(dev);
struct codec_data *codec = comp_get_codec(dev);
struct cadence_codec_data *cd = codec->private;
struct sof_ipc_stream_params *stream = &ca_data->stream_params;
uint32_t api_id = CODEC_GET_API_ID(codec->id);
uint32_t sample_channels_id;
int ret;

switch (api_id) {
case CADENCE_CODEC_WRAPPER_ID:
sample_channels_id = CADENCE_CHANNELS_COUNT_ID;
break;
default:
return 0;
}

API_CALL(cd, XA_API_CMD_SET_CONFIG_PARAM, sample_channels_id, &stream->channels, ret);
if (LIB_IS_FATAL_ERROR(ret)) {
comp_err(dev, "update_stream_channels(): failed to set channels");
return ret;
}

return 0;
}

static int update_stream_params(struct comp_dev *dev)
{
int ret = 0;

comp_dbg(dev, "update_stream_params() start");

ret = update_stream_sample_rate(dev);
if (ret)
return ret;

ret = update_stream_sample_width(dev);
if (ret)
return ret;

ret = update_stream_channels(dev);
if (ret)
return ret;

comp_dbg(dev, "update_stream_params() done");
return 0;
}

static int apply_config(struct comp_dev *dev, enum codec_cfg_type type)
{
int ret = 0;
Expand Down Expand Up @@ -413,6 +517,14 @@ int cadence_codec_prepare(struct comp_dev *dev)
}
}

/* Update codec config with stream parameters */
ret = update_stream_params(dev);
if (ret) {
comp_err(dev, "cadence_codec_prepare() error %x: failed to update stream params",
ret);
goto err;
}

/* Allocate memory for the codec */
API_CALL(cd, XA_API_CMD_GET_MEMTABS_SIZE, 0, &mem_tabs_size, ret);
if (ret != LIB_NO_ERROR) {
Expand Down
6 changes: 6 additions & 0 deletions src/include/sof/audio/codec_adapter/codec/cadence.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ struct cadence_api {
xa_codec_func_t *api;
};

enum default_stream_params_ids {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is for a single or group of specific Cadence codec then we should say in the comments as users may try and use it for any Cadence codec. Can be incrementally fixed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgirdwood i need a clarification from @mrajwa. I think this default parameters IDS are actually for CODEC_WRAPPER which for Intel is the DAP algorithm.

CADENCE_SAMPLE_RATE_ID = 1,
CADENCE_SAMPLE_WIDTH_ID = 2,
CADENCE_CHANNELS_COUNT_ID = 4,
};

struct cadence_codec_data {
char name[LIB_NAME_MAX_LEN];
void *self;
Expand Down