Skip to content

Commit 9e23068

Browse files
libinyangranj063
authored andcommitted
ASoC: SOF: ipc4-topology: update pipeline_params in process prepare
Some modules may modify the audio format during processing. So, update the pipeline params based on pin 0's output format during process prepare. Signed-off-by: Libin Yang <libin.yang@intel.com> Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
1 parent eadc01d commit 9e23068

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

sound/soc/sof/ipc4-topology.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,48 @@ static int sof_ipc4_widget_assign_instance_id(struct snd_sof_dev *sdev,
985985
return 0;
986986
}
987987

988+
/* update hw_params based on the audio stream format */
989+
static int sof_ipc4_update_hw_params(struct snd_sof_dev *sdev, struct snd_pcm_hw_params *params,
990+
struct sof_ipc4_audio_format *fmt)
991+
{
992+
struct snd_interval *i;
993+
struct snd_mask *m;
994+
snd_pcm_format_t snd_fmt;
995+
unsigned int channels, rate;
996+
int valid_bits;
997+
998+
rate = fmt->sampling_frequency;
999+
i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
1000+
i->min = rate;
1001+
i->max = rate;
1002+
1003+
channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
1004+
i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
1005+
i->min = channels;
1006+
i->max = channels;
1007+
1008+
valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
1009+
switch (valid_bits) {
1010+
case 16:
1011+
snd_fmt = SNDRV_PCM_FORMAT_S16_LE;
1012+
break;
1013+
case 24:
1014+
snd_fmt = SNDRV_PCM_FORMAT_S24_LE;
1015+
break;
1016+
case 32:
1017+
snd_fmt = SNDRV_PCM_FORMAT_S32_LE;
1018+
break;
1019+
default:
1020+
dev_err(sdev->dev, "invalid pcm valid_bits %d\n", valid_bits);
1021+
return -EINVAL;
1022+
}
1023+
m = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
1024+
snd_mask_none(m);
1025+
snd_mask_set_format(m, snd_fmt);
1026+
1027+
return 0;
1028+
}
1029+
9881030
static int sof_ipc4_init_audio_fmt(struct snd_sof_dev *sdev,
9891031
struct snd_sof_widget *swidget,
9901032
struct sof_ipc4_base_module_cfg *base_config,
@@ -1755,6 +1797,11 @@ static int sof_ipc4_prepare_process_module(struct snd_sof_widget *swidget,
17551797
memcpy(cfg, base_cfg_ext, process->base_config_ext_size);
17561798
}
17571799

1800+
/* modify the pipeline params with the pin 0 output format */
1801+
ret = sof_ipc4_update_hw_params(sdev, pipeline_params, &process->output_format);
1802+
if (ret)
1803+
return ret;
1804+
17581805
return 0;
17591806
}
17601807

0 commit comments

Comments
 (0)