Skip to content

Commit d4b2952

Browse files
committed
ASoC: SOF: ipc4-topology: Allow the use of multiple formats for src output
The SRC module can only change the rate, it keeps the format and channels intact, but this does not mean the the num_output_formats must be 0: The SRC module can support different formats/channels, we just need to check if the output format lists the correct combination of out rate and the input format/channels. Change the logic to prioritize the sink_rate of the module as target rate, then the rate of the FE in case of capture or in case of playback check the single rate specified in the output formats. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent 0225f32 commit d4b2952

1 file changed

Lines changed: 30 additions & 16 deletions

File tree

sound/soc/sof/ipc4-topology.c

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,16 +2630,6 @@ static int sof_ipc4_prepare_src_module(struct snd_sof_widget *swidget,
26302630
if (input_fmt_index < 0)
26312631
return input_fmt_index;
26322632

2633-
/*
2634-
* For playback, the SRC sink rate will be configured based on the requested output
2635-
* format, which is restricted to only deal with DAI's with a single format for now.
2636-
*/
2637-
if (dir == SNDRV_PCM_STREAM_PLAYBACK && available_fmt->num_output_formats > 1) {
2638-
dev_err(sdev->dev, "Invalid number of output formats: %d for SRC %s\n",
2639-
available_fmt->num_output_formats, swidget->widget->name);
2640-
return -EINVAL;
2641-
}
2642-
26432633
/*
26442634
* SRC does not perform format conversion, so the output channels and valid bit depth must
26452635
* be the same as that of the input.
@@ -2649,12 +2639,36 @@ static int sof_ipc4_prepare_src_module(struct snd_sof_widget *swidget,
26492639
out_ref_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(in_audio_fmt->fmt_cfg);
26502640
out_ref_type = sof_ipc4_fmt_cfg_to_type(in_audio_fmt->fmt_cfg);
26512641

2652-
/*
2653-
* For capture, the SRC module should convert the rate to match the rate requested by the
2654-
* PCM hw_params. Set the reference params based on the fe_params unconditionally as it
2655-
* will be ignored for playback anyway.
2656-
*/
2657-
out_ref_rate = params_rate(fe_params);
2642+
if (src->data.sink_rate) {
2643+
/* Use the sink rate as reference */
2644+
out_ref_rate = src->data.sink_rate;
2645+
} else if (dir == SNDRV_PCM_STREAM_CAPTURE) {
2646+
/*
2647+
* Use the fe rate as reference for capture if the sink rate is
2648+
* not set since we need to convert to the rate the PCM device
2649+
* is openned with
2650+
*/
2651+
out_ref_rate = params_rate(fe_params);
2652+
} else {
2653+
/*
2654+
* Otherwise try to guess what the rate should be:
2655+
* The output formats must have single rate specified if the
2656+
* sink rate is not set for an SRC in playback path.
2657+
*/
2658+
int i;
2659+
2660+
out_audio_fmt = &available_fmt->output_pin_fmts[0].audio_fmt;
2661+
out_ref_rate = out_audio_fmt->sampling_frequency;
2662+
for (i = 1; i < available_fmt->num_output_formats; i++) {
2663+
out_audio_fmt = &available_fmt->output_pin_fmts[i].audio_fmt;
2664+
if (out_ref_rate != out_audio_fmt->sampling_frequency) {
2665+
dev_err(sdev->dev,
2666+
"Cannot determine the output rate for SRC: %s\n",
2667+
swidget->widget->name);
2668+
return -EINVAL;
2669+
}
2670+
}
2671+
}
26582672

26592673
output_fmt_index = sof_ipc4_init_output_audio_fmt(sdev, swidget,
26602674
&src->data.base_config,

0 commit comments

Comments
 (0)