All of lore.kernel.org
 help / color / mirror / Atom feed
* Question about hw_param with Ctrl-Z + fg
       [not found] ` <redmine.journal-967542.20170403100335.fbd6fae50d6ed2e5@dm.renesas.com>
@ 2017-04-04  0:54   ` Kuninori Morimoto
  2017-04-04  4:10     ` Takashi Sakamoto
  0 siblings, 1 reply; 6+ messages in thread
From: Kuninori Morimoto @ 2017-04-04  0:54 UTC (permalink / raw)
  To: Linux-ALSA, hiroyuki.yokoyama.vx
  Cc: Fukawa, shiiba, mitsuhiro.kimura.kc, sakato, hideya.tanaka.nx,
	tomohiro.komagata.aj, hiroki.negishi.bx, yuta.wakasawa.pv,
	ryo.kodama.vz, hien.dang.eb, Kihara, ryo.kataoka.wt, honda,
	Chris.Paterson2, kouei.abe.cp, ren.imaoka.vj, goda,
	takashi.minami.xb, takahiko.gomi.yn, khiem.nguyen.xt,
	atsushi.tamaki.ks, harunobu.kurokawa.dn


Hi ALSA SoC ML

We noticed that 2nd hw_param on ALSA SoC isn't called if we used
Ctrl-Z + fg on aplay. hw_param is necessary especially if we use sampling
rate converter (it depends on .be_hw_params_fixup).
Ctrl-Z will use notmal STOP, and fg will use normal START,
thus it is impossible to distinction Ctrl-C (stop) or Ctrl-Z (temporary suspension).
Is this aplay issue ? or kernel issue ?

start/stop case
	- aplay xxx.wav
=>	- hw_param
	- SNDRV_PCM_TRIGGER_START
	- Ctrl-C (stop)	
	- SNDRV_PCM_TRIGGER_STOP

Ctrl-Z case
	- aplay xxx.wav
=>	- hw_param
	- SNDRV_PCM_TRIGGER_START
	- Ctrl-Z
	- SNDRV_PCM_TRIGGER_STOP
	- fg
=>	- ## no hw_param here
	- SNDRV_PCM_TRIGGER_START
	- Ctrl-C (stop)
	- SNDRV_PCM_TRIGGER_STOP

Best regards
---
Kuninori Morimoto

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about hw_param with Ctrl-Z + fg
  2017-04-04  0:54   ` Question about hw_param with Ctrl-Z + fg Kuninori Morimoto
@ 2017-04-04  4:10     ` Takashi Sakamoto
  2017-04-04  5:57       ` Kuninori Morimoto
  0 siblings, 1 reply; 6+ messages in thread
From: Takashi Sakamoto @ 2017-04-04  4:10 UTC (permalink / raw)
  To: Kuninori Morimoto, Linux-ALSA, hiroyuki.yokoyama.vx
  Cc: Fukawa, shiiba, mitsuhiro.kimura.kc, sakato, hideya.tanaka.nx,
	tomohiro.komagata.aj, hiroki.negishi.bx, hien.dang.eb,
	ryo.kodama.vz, Kihara, ryo.kataoka.wt, honda, Chris.Paterson2,
	kouei.abe.cp, ren.imaoka.vj, goda, takashi.minami.xb,
	takahiko.gomi.yn, khiem.nguyen.xt, yuta.wakasawa.pv,
	atsushi.tamaki.ks, harunobu.kurokawa.dn

Hi,

On Apr 4 2017 09:54, Kuninori Morimoto wrote:
> Is this aplay issue ? or kernel issue ?
> ...
> Ctrl-Z case
> 	- aplay xxx.wav
> =>	- hw_param
> 	- SNDRV_PCM_TRIGGER_START
> 	- Ctrl-Z
> 	- SNDRV_PCM_TRIGGER_STOP
> 	- fg
> =>	- ## no hw_param here
> 	- SNDRV_PCM_TRIGGER_START
> 	- Ctrl-C (stop)
> 	- SNDRV_PCM_TRIGGER_STOP

No issues.

I think it better to implement what you want in any .prepare callbacks, 
instead of the .be_hw_params_fixup callback, because in this case, PCM 
substream lapses into XRUN state in call graph from your hw IRQ handler. 
Typical applications recover from this state by calling ioctl(PREPARE), 
without any call of ioctl(HW_PARAMS).

Actually, you can see applications call ioctl(PREPARE), before you see 
call of 'struct snd_pcm_ops.trigger(START)'.


Regards

Takashi Sakamoto

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about hw_param with Ctrl-Z + fg
  2017-04-04  4:10     ` Takashi Sakamoto
@ 2017-04-04  5:57       ` Kuninori Morimoto
  2017-04-04  6:14         ` Takashi Sakamoto
  0 siblings, 1 reply; 6+ messages in thread
From: Kuninori Morimoto @ 2017-04-04  5:57 UTC (permalink / raw)
  To: Takashi Sakamoto
  Cc: Fukawa, Linux-ALSA, shiiba, mitsuhiro.kimura.kc, sakato,
	hideya.tanaka.nx, tomohiro.komagata.aj, hiroki.negishi.bx,
	hien.dang.eb, ryo.kodama.vz, Kihara, ryo.kataoka.wt, honda,
	hiroyuki.yokoyama.vx, Chris.Paterson2, kouei.abe.cp,
	ren.imaoka.vj, goda, takashi.minami.xb, takahiko.gomi.yn,
	khiem.nguyen.xt, yuta.wakasawa.pv, atsushi.tamaki.ks,
	harunobu.kurokawa.dn


Hi Sakamoto-san, Mark

Thank you for your feedback

> > Ctrl-Z case
> > 	- aplay xxx.wav
> > =>	- hw_param
> > 	- SNDRV_PCM_TRIGGER_START
> > 	- Ctrl-Z
> > 	- SNDRV_PCM_TRIGGER_STOP
> > 	- fg
> > =>	- ## no hw_param here
> > 	- SNDRV_PCM_TRIGGER_START
> > 	- Ctrl-C (stop)
> > 	- SNDRV_PCM_TRIGGER_STOP
> 
> No issues.
> 
> I think it better to implement what you want in any .prepare
> callbacks, instead of the .be_hw_params_fixup callback, because in
> this case, PCM substream lapses into XRUN state in call graph from
> your hw IRQ handler. Typical applications recover from this state by
> calling ioctl(PREPARE), without any call of ioctl(HW_PARAMS).
> 
> Actually, you can see applications call ioctl(PREPARE), before you see
> call of 'struct snd_pcm_ops.trigger(START)'.

Hmm...
Above .be_hw_params_fixup is used to convert sampling rate or channel
number or some other related things between SoC / Codec as DPCM feature.
Thus, I can't switch to .be_hw_params_fixup to .prepare I guess.
But Mark, am I misunderstanding ?

Best regards
---
Kuninori Morimoto

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about hw_param with Ctrl-Z + fg
  2017-04-04  5:57       ` Kuninori Morimoto
@ 2017-04-04  6:14         ` Takashi Sakamoto
  2017-04-04  8:02           ` Kuninori Morimoto
  0 siblings, 1 reply; 6+ messages in thread
From: Takashi Sakamoto @ 2017-04-04  6:14 UTC (permalink / raw)
  To: Kuninori Morimoto
  Cc: Fukawa, Linux-ALSA, shiiba, mitsuhiro.kimura.kc, sakato,
	hideya.tanaka.nx, tomohiro.komagata.aj, hiroki.negishi.bx,
	hien.dang.eb, ryo.kodama.vz, Kihara, ryo.kataoka.wt, honda,
	hiroyuki.yokoyama.vx, Chris.Paterson2, kouei.abe.cp,
	ren.imaoka.vj, goda, takashi.minami.xb, takahiko.gomi.yn,
	khiem.nguyen.xt, yuta.wakasawa.pv, atsushi.tamaki.ks,
	harunobu.kurokawa.dn

On Apr 4 2017 14:57, Kuninori Morimoto wrote:
>>> Ctrl-Z case
>>> 	- aplay xxx.wav
>>> =>	- hw_param
>>> 	- SNDRV_PCM_TRIGGER_START
>>> 	- Ctrl-Z
>>> 	- SNDRV_PCM_TRIGGER_STOP
>>> 	- fg
>>> =>	- ## no hw_param here
>>> 	- SNDRV_PCM_TRIGGER_START
>>> 	- Ctrl-C (stop)
>>> 	- SNDRV_PCM_TRIGGER_STOP
>>
>> No issues.
>>
>> I think it better to implement what you want in any .prepare
>> callbacks, instead of the .be_hw_params_fixup callback, because in
>> this case, PCM substream lapses into XRUN state in call graph from
>> your hw IRQ handler. Typical applications recover from this state by
>> calling ioctl(PREPARE), without any call of ioctl(HW_PARAMS).
>>
>> Actually, you can see applications call ioctl(PREPARE), before you see
>> call of 'struct snd_pcm_ops.trigger(START)'.
>
> Hmm...
> Above .be_hw_params_fixup is used to convert sampling rate or channel
> number or some other related things between SoC / Codec as DPCM feature.
> Thus, I can't switch to .be_hw_params_fixup to .prepare I guess.
> But Mark, am I misunderstanding ?

In 'struct snd_pcm_ops.prepare' callback, configured parameters of PCM 
substream are available via members of 'struct snd_pcm_runtime'. The 
runtime is a member of 'struct snd_pcm_substream'. It's available in any 
of .prepare callbacks in ALSA SoC part.


Regards

Takashi Sakamoto

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about hw_param with Ctrl-Z + fg
  2017-04-04  6:14         ` Takashi Sakamoto
@ 2017-04-04  8:02           ` Kuninori Morimoto
  2017-04-05  4:50             ` Kuninori Morimoto
  0 siblings, 1 reply; 6+ messages in thread
From: Kuninori Morimoto @ 2017-04-04  8:02 UTC (permalink / raw)
  To: Takashi Sakamoto
  Cc: Fukawa, Linux-ALSA, shiiba, mitsuhiro.kimura.kc, sakato,
	hideya.tanaka.nx, tomohiro.komagata.aj, hiroki.negishi.bx,
	hien.dang.eb, ryo.kodama.vz, Kihara, ryo.kataoka.wt, honda,
	hiroyuki.yokoyama.vx, Chris.Paterson2, kouei.abe.cp,
	ren.imaoka.vj, goda, takashi.minami.xb, takahiko.gomi.yn,
	khiem.nguyen.xt, yuta.wakasawa.pv, atsushi.tamaki.ks,
	harunobu.kurokawa.dn


Hi Sakamoto-san, Mark

> > Hmm...
> > Above .be_hw_params_fixup is used to convert sampling rate or channel
> > number or some other related things between SoC / Codec as DPCM feature.
> > Thus, I can't switch to .be_hw_params_fixup to .prepare I guess.
> > But Mark, am I misunderstanding ?
> 
> In 'struct snd_pcm_ops.prepare' callback, configured parameters of PCM
> substream are available via members of 'struct snd_pcm_runtime'. The
> runtime is a member of 'struct snd_pcm_substream'. It's available in
> any of .prepare callbacks in ALSA SoC part.

Thank you for detail explain.
I investigated this, and I tried to use .prepare with below system.

	[44.1kHz] -> CPU -> .be_hw_params_fixup[44.1kHz -> 48kHz] -> Codec

This means, CPU converts 44.1kHz to 48kHz, and
Codec want to receive 48kHz as parameter.
On CPU/Codec both side, these got 44.1kHz from runtime.

static int cpu/codec_prepare(struct snd_pcm_substream *substream)
{
	/*
	 * In 44.1kHz -> 48kHz convert case,
	 * .be_hw_params_fixup() do convert magic.
	 * but here .prepare, it still receive 44.1kHz
	 */
	printk("rate = %d\n", substream->runtime->rate);
}

On CPU side, I could get converted parameter somehow (see below),
but it has zero chance to get converted parameter on Codec side .prepare ?
Converted rate is located only struct snd_pcm_hw_params in my system (= simple-scu-card).
Current .be_hw_params_fixup() is saving converted rate/channel in struct snd_interval,
but it should save it to struct snd_soc_pcm_runtime ?

void asoc_simple_card_convert_fixup(...
				    struct snd_pcm_hw_params *hw_params)
{
	struct snd_interval *rate = hw_param_interval(hw_params,
						SNDRV_PCM_HW_PARAM_RATE);
	struct snd_interval *channels = hw_param_interval(hw_params,
						SNDRV_PCM_HW_PARAM_CHANNELS);
	printk("------fixup\n");
	if (data->convert_rate)
		rate->min =
		rate->max = data->convert_rate;

	if (data->convert_channels)
		channels->min =
		channels->max = data->convert_channels;
}


---- CPU could get converted rate --------------------------
static int cpu_prepare(struct snd_pcm_substream *substream)
{
	struct snd_soc_pcm_runtime *fe = substream->private_data;

	/* substream->runtime->rate is still 44.1kHz here */

	if (fe->dai_link->dynamic) {
		int stream = substream->stream;
		struct snd_soc_dpcm *dpcm;
		struct snd_pcm_hw_params *be_params;

		list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
			be_params = &dpcm->hw_params;

			/*
			 * I could receive 48kHz here as params_rate(be_params)
			 */
		}
	}

	return 0;
}


Best regards
---
Kuninori Morimoto

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about hw_param with Ctrl-Z + fg
  2017-04-04  8:02           ` Kuninori Morimoto
@ 2017-04-05  4:50             ` Kuninori Morimoto
  0 siblings, 0 replies; 6+ messages in thread
From: Kuninori Morimoto @ 2017-04-05  4:50 UTC (permalink / raw)
  To: Kuninori Morimoto
  Cc: Fukawa, Linux-ALSA, shiiba, mitsuhiro.kimura.kc, sakato,
	hideya.tanaka.nx, tomohiro.komagata.aj, hiroki.negishi.bx,
	hien.dang.eb, ryo.kodama.vz, Kihara, ryo.kataoka.wt, honda,
	hiroyuki.yokoyama.vx, khiem.nguyen.xt, Chris.Paterson2,
	kouei.abe.cp, ren.imaoka.vj, goda, takashi.minami.xb,
	takahiko.gomi.yn, Takashi Sakamoto, yuta.wakasawa.pv,
	atsushi.tamaki.ks, harunobu.kurokawa.dn


Hi Sakamoto-san, again

Thanks you for your help.
I think I could find my issue on my system.
I will post patch, soon

> > > Hmm...
> > > Above .be_hw_params_fixup is used to convert sampling rate or channel
> > > number or some other related things between SoC / Codec as DPCM feature.
> > > Thus, I can't switch to .be_hw_params_fixup to .prepare I guess.
> > > But Mark, am I misunderstanding ?
> > 
> > In 'struct snd_pcm_ops.prepare' callback, configured parameters of PCM
> > substream are available via members of 'struct snd_pcm_runtime'. The
> > runtime is a member of 'struct snd_pcm_substream'. It's available in
> > any of .prepare callbacks in ALSA SoC part.
> 
> Thank you for detail explain.
> I investigated this, and I tried to use .prepare with below system.
> 
> 	[44.1kHz] -> CPU -> .be_hw_params_fixup[44.1kHz -> 48kHz] -> Codec
> 
> This means, CPU converts 44.1kHz to 48kHz, and
> Codec want to receive 48kHz as parameter.
> On CPU/Codec both side, these got 44.1kHz from runtime.
> 
> static int cpu/codec_prepare(struct snd_pcm_substream *substream)
> {
> 	/*
> 	 * In 44.1kHz -> 48kHz convert case,
> 	 * .be_hw_params_fixup() do convert magic.
> 	 * but here .prepare, it still receive 44.1kHz
> 	 */
> 	printk("rate = %d\n", substream->runtime->rate);
> }
> 
> On CPU side, I could get converted parameter somehow (see below),
> but it has zero chance to get converted parameter on Codec side .prepare ?
> Converted rate is located only struct snd_pcm_hw_params in my system (= simple-scu-card).
> Current .be_hw_params_fixup() is saving converted rate/channel in struct snd_interval,
> but it should save it to struct snd_soc_pcm_runtime ?
> 
> void asoc_simple_card_convert_fixup(...
> 				    struct snd_pcm_hw_params *hw_params)
> {
> 	struct snd_interval *rate = hw_param_interval(hw_params,
> 						SNDRV_PCM_HW_PARAM_RATE);
> 	struct snd_interval *channels = hw_param_interval(hw_params,
> 						SNDRV_PCM_HW_PARAM_CHANNELS);
> 	printk("------fixup\n");
> 	if (data->convert_rate)
> 		rate->min =
> 		rate->max = data->convert_rate;
> 
> 	if (data->convert_channels)
> 		channels->min =
> 		channels->max = data->convert_channels;
> }
> 
> 
> ---- CPU could get converted rate --------------------------
> static int cpu_prepare(struct snd_pcm_substream *substream)
> {
> 	struct snd_soc_pcm_runtime *fe = substream->private_data;
> 
> 	/* substream->runtime->rate is still 44.1kHz here */
> 
> 	if (fe->dai_link->dynamic) {
> 		int stream = substream->stream;
> 		struct snd_soc_dpcm *dpcm;
> 		struct snd_pcm_hw_params *be_params;
> 
> 		list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
> 			be_params = &dpcm->hw_params;
> 
> 			/*
> 			 * I could receive 48kHz here as params_rate(be_params)
> 			 */
> 		}
> 	}
> 
> 	return 0;
> }
> 
> 
> Best regards
> ---
> Kuninori Morimoto

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-04-05  4:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-119657.20170403030456@dm.renesas.com>
     [not found] ` <redmine.journal-967542.20170403100335.fbd6fae50d6ed2e5@dm.renesas.com>
2017-04-04  0:54   ` Question about hw_param with Ctrl-Z + fg Kuninori Morimoto
2017-04-04  4:10     ` Takashi Sakamoto
2017-04-04  5:57       ` Kuninori Morimoto
2017-04-04  6:14         ` Takashi Sakamoto
2017-04-04  8:02           ` Kuninori Morimoto
2017-04-05  4:50             ` Kuninori Morimoto

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.