Skip to content

Commit ea4f69e

Browse files
committed
ASoC: SOF: ipc4-topology: Correct the process module's output lookup
The process module can change different parameters in the audio path and this change has to be properly evaluated and applied. In case of playback we are converting from multiple input formats to a single format (or just passing through without change), the output format lookup must be based on the input format. In case of capture, we are converting from a single input format to a format which is to be passed to the FE, we need to use the input parameters and the FE parameters to be able to find the correct format: for those parameters that are modified by the module instance we need to use the FE parameter while for the rest we use the input parameters. Signed-off-by: Peter Ujfalusi <[email protected]>
1 parent 53ada05 commit ea4f69e

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

sound/soc/sof/ipc4-topology.c

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,21 +2671,48 @@ static int sof_ipc4_prepare_process_module(struct snd_sof_widget *swidget,
26712671
if (available_fmt->num_output_formats) {
26722672
struct sof_ipc4_audio_format *in_fmt;
26732673
struct sof_ipc4_pin_format *pin_fmt;
2674-
u32 out_ref_rate, out_ref_channels;
2675-
int out_ref_valid_bits;
2674+
u32 ref_rate, ref_channels;
2675+
int ref_valid_bits;
26762676

2677+
/*
2678+
* The process module can change parameters and their operation
2679+
* depends on the direction:
2680+
* Playback: typically they have single output format. This is
2681+
* to 'force' the conversion from input to output.
2682+
* Use the input format as reference since the single
2683+
* format is going to be picked.
2684+
* Capture: typically they have multiple output formats to
2685+
* convert from dai (input) to FE (output) parameters.
2686+
* Use the input format as base and replace the param
2687+
* which is changed by the module with the FE parameter
2688+
* Reason: we can have module which changes the
2689+
* parameters in path, we cannot use the full
2690+
* FE param set for the module output lookup.
2691+
*/
26772692
in_fmt = &available_fmt->input_pin_fmts[input_fmt_index].audio_fmt;
26782693

2679-
out_ref_rate = in_fmt->sampling_frequency;
2680-
out_ref_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(in_fmt->fmt_cfg);
2681-
out_ref_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(in_fmt->fmt_cfg);
2694+
ref_rate = in_fmt->sampling_frequency;
2695+
ref_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(in_fmt->fmt_cfg);
2696+
ref_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(in_fmt->fmt_cfg);
2697+
2698+
if (dir == SNDRV_PCM_STREAM_CAPTURE) {
2699+
if (available_fmt->changed_params & BIT(SNDRV_PCM_HW_PARAM_RATE))
2700+
ref_rate = params_rate(fe_params);
2701+
if (available_fmt->changed_params & BIT(SNDRV_PCM_HW_PARAM_CHANNELS))
2702+
ref_channels = params_channels(fe_params);
2703+
if (available_fmt->changed_params & BIT(SNDRV_PCM_HW_PARAM_FORMAT)) {
2704+
ref_valid_bits = sof_ipc4_get_valid_bits(sdev, fe_params);
2705+
if (ref_valid_bits < 0)
2706+
return ref_valid_bits;
2707+
}
2708+
}
26822709

26832710
output_fmt_index = sof_ipc4_init_output_audio_fmt(sdev, swidget,
26842711
&process->base_config,
26852712
available_fmt,
2686-
out_ref_rate,
2687-
out_ref_channels,
2688-
out_ref_valid_bits);
2713+
ref_rate,
2714+
ref_channels,
2715+
ref_valid_bits);
26892716
if (output_fmt_index < 0)
26902717
return output_fmt_index;
26912718

@@ -2699,9 +2726,7 @@ static int sof_ipc4_prepare_process_module(struct snd_sof_widget *swidget,
26992726
/* modify the pipeline params with the output format */
27002727
ret = sof_ipc4_update_hw_params(sdev, pipeline_params,
27012728
&process->output_format,
2702-
BIT(SNDRV_PCM_HW_PARAM_FORMAT) |
2703-
BIT(SNDRV_PCM_HW_PARAM_CHANNELS) |
2704-
BIT(SNDRV_PCM_HW_PARAM_RATE));
2729+
available_fmt->changed_params);
27052730
if (ret)
27062731
return ret;
27072732
}

0 commit comments

Comments
 (0)