All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
To: lgirdwood@gmail.com, broonie@kernel.org
Cc: alsa-devel@alsa-project.org,
	pierre-louis.bossart@linux.intel.com,
	ranjani.sridharan@linux.intel.com, kai.vehmanen@linux.intel.com,
	libin.yang@intel.com, yung-chuan.liao@linux.intel.com,
	chao.song@linux.intel.com, jaska.uimonen@linux.intel.com
Subject: [PATCH 6/6] ASoC: SOF: ipc4-topology: update pipeline_params in process prepare
Date: Thu, 16 Mar 2023 17:11:37 +0200	[thread overview]
Message-ID: <20230316151137.7598-7-peter.ujfalusi@linux.intel.com> (raw)
In-Reply-To: <20230316151137.7598-1-peter.ujfalusi@linux.intel.com>

From: Libin Yang <libin.yang@intel.com>

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>
Co-developed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Chao Song <chao.song@linux.intel.com>
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
---
 sound/soc/sof/ipc4-topology.c | 50 ++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/sound/soc/sof/ipc4-topology.c b/sound/soc/sof/ipc4-topology.c
index 962ec38b70cc..963ec730381b 100644
--- a/sound/soc/sof/ipc4-topology.c
+++ b/sound/soc/sof/ipc4-topology.c
@@ -964,6 +964,48 @@ static int sof_ipc4_widget_assign_instance_id(struct snd_sof_dev *sdev,
 	return 0;
 }
 
+/* update hw_params based on the audio stream format */
+static int sof_ipc4_update_hw_params(struct snd_sof_dev *sdev, struct snd_pcm_hw_params *params,
+				     struct sof_ipc4_audio_format *fmt)
+{
+	snd_pcm_format_t snd_fmt;
+	struct snd_interval *i;
+	struct snd_mask *m;
+	int valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
+	unsigned int channels, rate;
+
+	switch (valid_bits) {
+	case 16:
+		snd_fmt = SNDRV_PCM_FORMAT_S16_LE;
+		break;
+	case 24:
+		snd_fmt = SNDRV_PCM_FORMAT_S24_LE;
+		break;
+	case 32:
+		snd_fmt = SNDRV_PCM_FORMAT_S32_LE;
+		break;
+	default:
+		dev_err(sdev->dev, "invalid PCM valid_bits %d\n", valid_bits);
+		return -EINVAL;
+	}
+
+	m = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
+	snd_mask_none(m);
+	snd_mask_set_format(m, snd_fmt);
+
+	rate = fmt->sampling_frequency;
+	i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
+	i->min = rate;
+	i->max = rate;
+
+	channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
+	i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
+	i->min = channels;
+	i->max = channels;
+
+	return 0;
+}
+
 static int sof_ipc4_init_audio_fmt(struct snd_sof_dev *sdev,
 				   struct snd_sof_widget *swidget,
 				   struct sof_ipc4_base_module_cfg *base_config,
@@ -1673,10 +1715,16 @@ static int sof_ipc4_prepare_process_module(struct snd_sof_widget *swidget,
 
 	/* copy Pin 0 output format */
 	if (available_fmt->num_output_formats && ret < available_fmt->num_output_formats &&
-	    !available_fmt->output_pin_fmts[ret].pin_index)
+	    !available_fmt->output_pin_fmts[ret].pin_index) {
 		memcpy(&process->output_format, &available_fmt->output_pin_fmts[ret].audio_fmt,
 		       sizeof(struct sof_ipc4_audio_format));
 
+		/* modify the pipeline params with the pin 0 output format */
+		ret = sof_ipc4_update_hw_params(sdev, pipeline_params, &process->output_format);
+		if (ret)
+			return ret;
+	}
+
 	/* update pipeline memory usage */
 	sof_ipc4_update_pipeline_mem_usage(sdev, swidget, &process->base_config);
 
-- 
2.39.2


  parent reply	other threads:[~2023-03-16 15:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-16 15:11 [PATCH 0/6] ASoC: SOF: ipc4-topology: Add support for effect widget Peter Ujfalusi
2023-03-16 15:11 ` [PATCH 1/6] ASoC: SOF: ipc4-topology: Move the kcontrol module_id update to helper Peter Ujfalusi
2023-03-16 15:11 ` [PATCH 2/6] ASoC: SOF: ipc4-topology: add effect widget support Peter Ujfalusi
2023-03-16 15:11 ` [PATCH 3/6] ASoC: SOF: ipc4-topology: add base module config extension structure Peter Ujfalusi
2023-03-16 15:11 ` [PATCH 4/6] ASoC: SOF: ipc4-topology: Add support for base config extension Peter Ujfalusi
2023-03-16 15:11 ` [PATCH 5/6] ASoC: SOF: ipc4-topology: set copier output format for process module Peter Ujfalusi
2023-03-16 15:11 ` Peter Ujfalusi [this message]
2023-03-17 17:44 ` [PATCH 0/6] ASoC: SOF: ipc4-topology: Add support for effect widget Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230316151137.7598-7-peter.ujfalusi@linux.intel.com \
    --to=peter.ujfalusi@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=chao.song@linux.intel.com \
    --cc=jaska.uimonen@linux.intel.com \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=lgirdwood@gmail.com \
    --cc=libin.yang@intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.