Skip to content

Commit 141d159

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 <peter.ujfalusi@linux.intel.com>
1 parent aa78d9a commit 141d159

1 file changed

Lines changed: 47 additions & 19 deletions

File tree

sound/soc/sof/ipc4-topology.c

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,39 +2894,69 @@ static int sof_ipc4_prepare_process_module(struct snd_sof_widget *swidget,
28942894
if (available_fmt->num_output_formats) {
28952895
struct sof_ipc4_audio_format *in_fmt;
28962896
struct sof_ipc4_pin_format *pin_fmt;
2897-
u32 out_ref_rate, out_ref_channels;
2898-
int out_ref_valid_bits, out_ref_type;
2897+
u32 ref_rate, ref_channels;
2898+
int ref_valid_bits, ref_type;
28992899

29002900
if (available_fmt->num_input_formats) {
2901+
/*
2902+
* The process module can change parameters and their operation
2903+
* depends on the direction:
2904+
* Playback: typically they have single output format. This is
2905+
* to 'force' the conversion from input to output.
2906+
* Use the input format as reference since the single
2907+
* format is going to be picked.
2908+
* Capture: typically they have multiple output formats to
2909+
* convert from dai (input) to FE (output) parameters.
2910+
* Use the input format as base and replace the param
2911+
* which is changed by the module with the FE parameter
2912+
* Reason: we can have module which changes the
2913+
* parameters in path, we cannot use the full
2914+
* FE param set for the module output lookup.
2915+
*/
29012916
in_fmt = &available_fmt->input_pin_fmts[input_fmt_index].audio_fmt;
29022917

2903-
out_ref_rate = in_fmt->sampling_frequency;
2904-
out_ref_channels =
2918+
ref_rate = in_fmt->sampling_frequency;
2919+
ref_channels =
29052920
SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(in_fmt->fmt_cfg);
2906-
out_ref_valid_bits =
2921+
ref_valid_bits =
29072922
SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(in_fmt->fmt_cfg);
2908-
out_ref_type = sof_ipc4_fmt_cfg_to_type(in_fmt->fmt_cfg);
2923+
ref_type = sof_ipc4_fmt_cfg_to_type(in_fmt->fmt_cfg);
29092924
} else {
29102925
/* for modules without input formats, use FE params as reference */
2911-
out_ref_rate = params_rate(fe_params);
2912-
out_ref_channels = params_channels(fe_params);
2926+
ref_rate = params_rate(fe_params);
2927+
ref_channels = params_channels(fe_params);
29132928
ret = sof_ipc4_get_sample_type(sdev, fe_params);
29142929
if (ret < 0)
29152930
return ret;
2916-
out_ref_type = (u32)ret;
2931+
ref_type = (u32)ret;
29172932

2918-
out_ref_valid_bits = sof_ipc4_get_valid_bits(sdev, fe_params);
2919-
if (out_ref_valid_bits < 0)
2920-
return out_ref_valid_bits;
2933+
ref_valid_bits = sof_ipc4_get_valid_bits(sdev, fe_params);
2934+
if (ref_valid_bits < 0)
2935+
return ref_valid_bits;
29212936
}
29222937

2938+
if (dir == SNDRV_PCM_STREAM_CAPTURE) {
2939+
if (available_fmt->changed_params & BIT(SNDRV_PCM_HW_PARAM_RATE))
2940+
ref_rate = params_rate(fe_params);
2941+
if (available_fmt->changed_params & BIT(SNDRV_PCM_HW_PARAM_CHANNELS))
2942+
ref_channels = params_channels(fe_params);
2943+
if (available_fmt->changed_params & BIT(SNDRV_PCM_HW_PARAM_FORMAT)) {
2944+
ref_valid_bits = sof_ipc4_get_valid_bits(sdev, fe_params);
2945+
if (ref_valid_bits < 0)
2946+
return ref_valid_bits;
2947+
2948+
ref_type = sof_ipc4_get_sample_type(sdev, fe_params);
2949+
if (ref_type < 0)
2950+
return ref_type;
2951+
}
2952+
}
29232953
output_fmt_index = sof_ipc4_init_output_audio_fmt(sdev, swidget,
29242954
&process->base_config,
29252955
available_fmt,
2926-
out_ref_rate,
2927-
out_ref_channels,
2928-
out_ref_valid_bits,
2929-
out_ref_type);
2956+
ref_rate,
2957+
ref_channels,
2958+
ref_valid_bits,
2959+
ref_type);
29302960
if (output_fmt_index < 0)
29312961
return output_fmt_index;
29322962

@@ -2940,9 +2970,7 @@ static int sof_ipc4_prepare_process_module(struct snd_sof_widget *swidget,
29402970
/* modify the pipeline params with the output format */
29412971
ret = sof_ipc4_update_hw_params(sdev, pipeline_params,
29422972
&process->output_format,
2943-
BIT(SNDRV_PCM_HW_PARAM_FORMAT) |
2944-
BIT(SNDRV_PCM_HW_PARAM_CHANNELS) |
2945-
BIT(SNDRV_PCM_HW_PARAM_RATE));
2973+
available_fmt->changed_params);
29462974
if (ret)
29472975
return ret;
29482976
}

0 commit comments

Comments
 (0)