All of lore.kernel.org
 help / color / mirror / Atom feed
* S16_LE + softvol = bad
@ 2008-01-17 13:40 Alexander E. Patrakov
  2008-01-17 14:00 ` Clemens Ladisch
  0 siblings, 1 reply; 9+ messages in thread
From: Alexander E. Patrakov @ 2008-01-17 13:40 UTC (permalink / raw)
  To: alsa-devel

Hello developers,

some cards (most notably, Intel HD audio) have the PCM control as softvol, and 
default to S16_LE as a format for dmix. Since softvol is configured to attenuate 
signal, and not many people set this control to 100% (especially those who have 
no other volume controls), this effectively leaves less than 16 bits per sample.

The card can surely produce sound of better quality in most cases, if one 
changes defaults.pcm.dmix.format in ~/.asoundrc. However, one should now search 
a lot of forums in order to know about this setting. Not everyone does this, and 
not everyone is even able to diagnose the "noisy sound in Linux" problem 
properly as "too few bits per sample in the default configuration". A much 
better situation would be if ALSA defaulted to good quality (i.e.: S24_LE or 
S32_LE on all cards that require softvol and support this sample format). Could 
you please change the files in /usr/share/alsa/cards accordingly?

-- 
Alexander E. Patrakov

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

* Re: S16_LE + softvol = bad
  2008-01-17 13:40 S16_LE + softvol = bad Alexander E. Patrakov
@ 2008-01-17 14:00 ` Clemens Ladisch
  2008-01-17 14:11   ` Takashi Iwai
       [not found]   ` <c072ca310801170612p7d06813ve5269dd82afb6619@mail.gmail.com>
  0 siblings, 2 replies; 9+ messages in thread
From: Clemens Ladisch @ 2008-01-17 14:00 UTC (permalink / raw)
  To: Alexander E. Patrakov, alsa-devel

Alexander E. Patrakov wrote:
> some cards (most notably, Intel HD audio) have the PCM control as softvol, and 
> default to S16_LE as a format for dmix.

HDA-Intel.conf doesn't set a sample format, and when none is set, dmix
tries S32 before S16.  You get S16 only if the device doesn't support
S32.


Regards,
Clemens

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

* Re: S16_LE + softvol = bad
  2008-01-17 14:00 ` Clemens Ladisch
@ 2008-01-17 14:11   ` Takashi Iwai
  2008-01-17 14:23     ` Takashi Iwai
       [not found]   ` <c072ca310801170612p7d06813ve5269dd82afb6619@mail.gmail.com>
  1 sibling, 1 reply; 9+ messages in thread
From: Takashi Iwai @ 2008-01-17 14:11 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: alsa-devel, Alexander E. Patrakov

At Thu, 17 Jan 2008 15:00:47 +0100,
Clemens Ladisch wrote:
> 
> Alexander E. Patrakov wrote:
> > some cards (most notably, Intel HD audio) have the PCM control as softvol, and 
> > default to S16_LE as a format for dmix.
> 
> HDA-Intel.conf doesn't set a sample format, and when none is set, dmix
> tries S32 before S16.  You get S16 only if the device doesn't support
> S32.

The plugin code is written partly in such a way, but the other parts
do require the format given explicitly.  So, it doesn't work as is.
Fixing this wouldn't be hard, I guess, though.


Takashi

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

* Re: S16_LE + softvol = bad
       [not found]   ` <c072ca310801170612p7d06813ve5269dd82afb6619@mail.gmail.com>
@ 2008-01-17 14:14     ` Alexander E. Patrakov
  0 siblings, 0 replies; 9+ messages in thread
From: Alexander E. Patrakov @ 2008-01-17 14:14 UTC (permalink / raw)
  To: cladisch; +Cc: tiwai, alsa-devel

[sorry for a possible duplicate]
2008/1/17, Clemens Ladisch <cladisch@fastmail.net>:
> Alexander E. Patrakov wrote:
> > some cards (most notably, Intel HD audio) have the PCM control as softvol, and
> > default to S16_LE as a format for dmix.
>
> HDA-Intel.conf doesn't set a sample format, and when none is set, dmix
> tries S32 before S16.  You get S16 only if the device doesn't support
> S32.

Sorry, this doesn't appear to be the case here.

# with explicit defaults.pcm.dmix.format S32_LE
patrakov@home:~$ aplay -vv /usr/share/sounds/alsa/Front_Left.wav
Playing WAVE '/usr/share/sounds/alsa/Front_Left.wav' : Signed 16 bit
Little Endian, Rate 48000 Hz, Mono
Plug PCM: Route conversion PCM (sformat=S32_LE)
  Transformation table:
    0 <- 0
    1 <- 0
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 1
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 8192
  period_size  : 1024
  period_time  : 21333
  tick_time    : 0
  tstamp_mode  : NONE
  period_step  : 1
  sleep_min    : 0
  avail_min    : 1024
  xfer_align   : 1024
  start_threshold  : 8192
  stop_threshold   : 8192
  silence_threshold: 0
  silence_size : 0
  boundary     : 1073741824
Slave: Soft volume PCM
Control: PCM Playback Volume
min_dB: -51
max_dB: 0
resolution: 256
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S32_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 32
  buffer_size  : 8192
  period_size  : 1024
  period_time  : 21333
  tick_time    : 0
  tstamp_mode  : NONE
  period_step  : 1
  sleep_min    : 0
  avail_min    : 1024
  xfer_align   : 1024
  start_threshold  : 8192
  stop_threshold   : 8192
  silence_threshold: 0
  silence_size : 0
  boundary     : 1073741824
Slave: Direct Stream Mixing PCM
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S32_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 32
  buffer_size  : 8192
  period_size  : 1024
  period_time  : 21333
  tick_time    : 0
  tstamp_mode  : NONE
  period_step  : 1
  sleep_min    : 0
  avail_min    : 1024
  xfer_align   : 1024
  start_threshold  : 8192
  stop_threshold   : 8192
  silence_threshold: 0
  silence_size : 0
  boundary     : 1073741824
Hardware PCM card 0 'HDA Intel' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S32_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 32
  buffer_size  : 8192
  period_size  : 1024
  period_time  : 21333
  tick_time    : 4000
  tstamp_mode  : NONE
  period_step  : 1
  sleep_min    : 0
  avail_min    : 1024
  xfer_align   : 1024
  start_threshold  : 1
  stop_threshold   : 1073741824
  silence_threshold: 0
  silence_size : 1073741824
  boundary     : 1073741824
#+                                                 | 00%

# The same without defaults.pcm.dmix.format
patrakov@home:~$ aplay -vv /usr/share/sounds/alsa/Front_Left.wav
Playing WAVE '/usr/share/sounds/alsa/Front_Left.wav' : Signed 16 bit
Little Endian, Rate 48000 Hz, Mono
Plug PCM: Route conversion PCM (sformat=S16_LE)
  Transformation table:
    0 <- 0
    1 <- 0
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 1
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 16384
  period_size  : 1024
  period_time  : 21333
  tick_time    : 0
  tstamp_mode  : NONE
  period_step  : 1
  sleep_min    : 0
  avail_min    : 1024
  xfer_align   : 1024
  start_threshold  : 16384
  stop_threshold   : 16384
  silence_threshold: 0
  silence_size : 0
  boundary     : 1073741824
Slave: Soft volume PCM
Control: PCM Playback Volume
min_dB: -51
max_dB: 0
resolution: 256
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 16384
  period_size  : 1024
  period_time  : 21333
  tick_time    : 0
  tstamp_mode  : NONE
  period_step  : 1
  sleep_min    : 0
  avail_min    : 1024
  xfer_align   : 1024
  start_threshold  : 16384
  stop_threshold   : 16384
  silence_threshold: 0
  silence_size : 0
  boundary     : 1073741824
Slave: Direct Stream Mixing PCM
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 16384
  period_size  : 1024
  period_time  : 21333
  tick_time    : 0
  tstamp_mode  : NONE
  period_step  : 1
  sleep_min    : 0
  avail_min    : 1024
  xfer_align   : 1024
  start_threshold  : 16384
  stop_threshold   : 16384
  silence_threshold: 0
  silence_size : 0
  boundary     : 1073741824
Hardware PCM card 0 'HDA Intel' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 16384
  period_size  : 1024
  period_time  : 21333
  tick_time    : 4000
  tstamp_mode  : NONE
  period_step  : 1
  sleep_min    : 0
  avail_min    : 1024
  xfer_align   : 1024
  start_threshold  : 1
  stop_threshold   : 1073741824
  silence_threshold: 0
  silence_size : 1073741824
  boundary     : 1073741824
#                        +                         | 49%

This is with libasound2 1.0.15-3 from Debian.
--
Alexander E. Patrakov

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

* Re: S16_LE + softvol = bad
  2008-01-17 14:11   ` Takashi Iwai
@ 2008-01-17 14:23     ` Takashi Iwai
  2008-01-17 15:01       ` Alexander E. Patrakov
  0 siblings, 1 reply; 9+ messages in thread
From: Takashi Iwai @ 2008-01-17 14:23 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: alsa-devel, Alexander E. Patrakov

At Thu, 17 Jan 2008 15:11:18 +0100,
I wrote:
> 
> At Thu, 17 Jan 2008 15:00:47 +0100,
> Clemens Ladisch wrote:
> > 
> > Alexander E. Patrakov wrote:
> > > some cards (most notably, Intel HD audio) have the PCM control as softvol, and 
> > > default to S16_LE as a format for dmix.
> > 
> > HDA-Intel.conf doesn't set a sample format, and when none is set, dmix
> > tries S32 before S16.  You get S16 only if the device doesn't support
> > S32.
> 
> The plugin code is written partly in such a way, but the other parts
> do require the format given explicitly.  So, it doesn't work as is.
> Fixing this wouldn't be hard, I guess, though.

... and the below is the fix.  Give it a try.


Takashi

diff -r f20b309ff22a src/conf/alsa.conf
--- a/src/conf/alsa.conf	Tue Jan 15 14:29:34 2008 +0100
+++ b/src/conf/alsa.conf	Thu Jan 17 15:18:53 2008 +0100
@@ -68,7 +68,7 @@ defaults.pcm.ipc_perm 0660
 defaults.pcm.ipc_perm 0660
 defaults.pcm.dmix.max_periods 0
 defaults.pcm.dmix.rate 48000
-defaults.pcm.dmix.format S16_LE
+defaults.pcm.dmix.format "unchanged"
 defaults.pcm.dmix.card defaults.pcm.card
 defaults.pcm.dmix.device defaults.pcm.device
 defaults.pcm.dsnoop.card defaults.pcm.card
diff -r f20b309ff22a src/pcm/pcm_direct.c
--- a/src/pcm/pcm_direct.c	Tue Jan 15 14:29:34 2008 +0100
+++ b/src/pcm/pcm_direct.c	Thu Jan 17 15:18:53 2008 +0100
@@ -874,7 +874,11 @@ int snd_pcm_direct_initialize_slave(snd_
 			return ret;
 		}
 	}
-	ret = snd_pcm_hw_params_set_format(spcm, hw_params, params->format);
+	if (params->format == SND_PCM_FORMAT_UNKNOWN)
+		ret = -EINVAL;
+	else
+		ret = snd_pcm_hw_params_set_format(spcm, hw_params,
+						   params->format);
 	if (ret < 0) {
 		static const snd_pcm_format_t dmix_formats[] = {
 			SND_PCM_FORMAT_S32,
diff -r f20b309ff22a src/pcm/pcm_dmix.c
--- a/src/pcm/pcm_dmix.c	Tue Jan 15 14:29:34 2008 +0100
+++ b/src/pcm/pcm_dmix.c	Thu Jan 17 15:18:53 2008 +0100
@@ -1267,7 +1267,7 @@ int _snd_pcm_dmix_open(snd_pcm_t **pcmp,
 	params.periods = 3;
 
 	err = snd_pcm_slave_conf(root, dopen.slave, &sconf, 8,
-				 SND_PCM_HW_PARAM_FORMAT, 0, &params.format,
+				 SND_PCM_HW_PARAM_FORMAT, SCONF_UNCHANGED, &params.format,
 				 SND_PCM_HW_PARAM_RATE, 0, &params.rate,
 				 SND_PCM_HW_PARAM_CHANNELS, 0, &params.channels,
 				 SND_PCM_HW_PARAM_PERIOD_TIME, 0, &params.period_time,
@@ -1282,8 +1282,10 @@ int _snd_pcm_dmix_open(snd_pcm_t **pcmp,
 	if (psize == -1 && params.period_time == -1)
 		params.period_time = 125000;    /* 0.125 seconds */
 
-	/* sorry, limited features */
-	if (! (dmix_supported_format & (1ULL << params.format))) {
+	if (params.format == -2)
+		params.format = SND_PCM_FORMAT_UNKNOWN;
+	else if (!(dmix_supported_format & (1ULL << params.format))) {
+		/* sorry, limited features */
 		SNDERR("Unsupported format");
 		snd_config_delete(sconf);
 		return -EINVAL;

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

* Re: S16_LE + softvol = bad
  2008-01-17 14:23     ` Takashi Iwai
@ 2008-01-17 15:01       ` Alexander E. Patrakov
  2008-01-18 12:46         ` Takashi Iwai
  0 siblings, 1 reply; 9+ messages in thread
From: Alexander E. Patrakov @ 2008-01-17 15:01 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

2008/1/17, Takashi Iwai <tiwai@suse.de>:
> ... and the below is the fix.  Give it a try.

Tested with no explicit defaults.pcm.dmix.format, with explicit
S16_LE, and with explicit S32_LE, all with Intel HD audio and the PC
speaker (total 6 cases, including one meaningless). In all cases, the
code was able to choose the correct format for talking with hardware
(i.e., the worst of (a) explicitly specified, if any, and (b) the best
hardware-supported one). Thanks for a quick fix!

>
>
> Takashi
>
> diff -r f20b309ff22a src/conf/alsa.conf
> --- a/src/conf/alsa.conf        Tue Jan 15 14:29:34 2008 +0100
> +++ b/src/conf/alsa.conf        Thu Jan 17 15:18:53 2008 +0100
> @@ -68,7 +68,7 @@ defaults.pcm.ipc_perm 0660
>  defaults.pcm.ipc_perm 0660
>  defaults.pcm.dmix.max_periods 0
>  defaults.pcm.dmix.rate 48000
> -defaults.pcm.dmix.format S16_LE
> +defaults.pcm.dmix.format "unchanged"
>  defaults.pcm.dmix.card defaults.pcm.card
>  defaults.pcm.dmix.device defaults.pcm.device
>  defaults.pcm.dsnoop.card defaults.pcm.card
> diff -r f20b309ff22a src/pcm/pcm_direct.c
> --- a/src/pcm/pcm_direct.c      Tue Jan 15 14:29:34 2008 +0100
> +++ b/src/pcm/pcm_direct.c      Thu Jan 17 15:18:53 2008 +0100
> @@ -874,7 +874,11 @@ int snd_pcm_direct_initialize_slave(snd_
>                         return ret;
>                 }
>         }
> -       ret = snd_pcm_hw_params_set_format(spcm, hw_params, params->format);
> +       if (params->format == SND_PCM_FORMAT_UNKNOWN)
> +               ret = -EINVAL;
> +       else
> +               ret = snd_pcm_hw_params_set_format(spcm, hw_params,
> +                                                  params->format);
>         if (ret < 0) {
>                 static const snd_pcm_format_t dmix_formats[] = {
>                         SND_PCM_FORMAT_S32,
> diff -r f20b309ff22a src/pcm/pcm_dmix.c
> --- a/src/pcm/pcm_dmix.c        Tue Jan 15 14:29:34 2008 +0100
> +++ b/src/pcm/pcm_dmix.c        Thu Jan 17 15:18:53 2008 +0100
> @@ -1267,7 +1267,7 @@ int _snd_pcm_dmix_open(snd_pcm_t **pcmp,
>         params.periods = 3;
>
>         err = snd_pcm_slave_conf(root, dopen.slave, &sconf, 8,
> -                                SND_PCM_HW_PARAM_FORMAT, 0, &params.format,
> +                                SND_PCM_HW_PARAM_FORMAT, SCONF_UNCHANGED, &params.format,
>                                  SND_PCM_HW_PARAM_RATE, 0, &params.rate,
>                                  SND_PCM_HW_PARAM_CHANNELS, 0, &params.channels,
>                                  SND_PCM_HW_PARAM_PERIOD_TIME, 0, &params.period_time,
> @@ -1282,8 +1282,10 @@ int _snd_pcm_dmix_open(snd_pcm_t **pcmp,
>         if (psize == -1 && params.period_time == -1)
>                 params.period_time = 125000;    /* 0.125 seconds */
>
> -       /* sorry, limited features */
> -       if (! (dmix_supported_format & (1ULL << params.format))) {
> +       if (params.format == -2)
> +               params.format = SND_PCM_FORMAT_UNKNOWN;
> +       else if (!(dmix_supported_format & (1ULL << params.format))) {
> +               /* sorry, limited features */
>                 SNDERR("Unsupported format");
>                 snd_config_delete(sconf);
>                 return -EINVAL;
>


-- 
Alexander E. Patrakov

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

* Re: S16_LE + softvol = bad
  2008-01-17 15:01       ` Alexander E. Patrakov
@ 2008-01-18 12:46         ` Takashi Iwai
  2008-01-23 11:21           ` Alexander E. Patrakov
  0 siblings, 1 reply; 9+ messages in thread
From: Takashi Iwai @ 2008-01-18 12:46 UTC (permalink / raw)
  To: Alexander E. Patrakov; +Cc: alsa-devel

At Thu, 17 Jan 2008 20:01:09 +0500,
Alexander E. Patrakov wrote:
> 
> 2008/1/17, Takashi Iwai <tiwai@suse.de>:
> > ... and the below is the fix.  Give it a try.
> 
> Tested with no explicit defaults.pcm.dmix.format, with explicit
> S16_LE, and with explicit S32_LE, all with Intel HD audio and the PC
> speaker (total 6 cases, including one meaningless). In all cases, the
> code was able to choose the correct format for talking with hardware
> (i.e., the worst of (a) explicitly specified, if any, and (b) the best
> hardware-supported one). Thanks for a quick fix!

Thanks for checking.  I applied it to HG tree now.

This might break something on some drivers due to the format changes
(requiring larger buffers) although I don't think it won't be much.
Let's see.  For such devices, we can add S16 in the card config.


Takashi

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

* Re: S16_LE + softvol = bad
  2008-01-18 12:46         ` Takashi Iwai
@ 2008-01-23 11:21           ` Alexander E. Patrakov
  2008-01-23 11:31             ` Takashi Iwai
  0 siblings, 1 reply; 9+ messages in thread
From: Alexander E. Patrakov @ 2008-01-23 11:21 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

Takashi Iwai wrote:
> At Thu, 17 Jan 2008 20:01:09 +0500,
> Alexander E. Patrakov wrote:
>> 2008/1/17, Takashi Iwai <tiwai@suse.de>:
>>> ... and the below is the fix.  Give it a try.
>> Tested with no explicit defaults.pcm.dmix.format, with explicit
>> S16_LE, and with explicit S32_LE, all with Intel HD audio and the PC
>> speaker (total 6 cases, including one meaningless). In all cases, the
>> code was able to choose the correct format for talking with hardware
>> (i.e., the worst of (a) explicitly specified, if any, and (b) the best
>> hardware-supported one). Thanks for a quick fix!
> 
> Thanks for checking.  I applied it to HG tree now.

Could you please apply the same tweak (use the best available sample format 
unless overridden) to dsnoop, too?

-- 
Alexander E. Patrakov

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

* Re: S16_LE + softvol = bad
  2008-01-23 11:21           ` Alexander E. Patrakov
@ 2008-01-23 11:31             ` Takashi Iwai
  0 siblings, 0 replies; 9+ messages in thread
From: Takashi Iwai @ 2008-01-23 11:31 UTC (permalink / raw)
  To: Alexander E. Patrakov; +Cc: alsa-devel

At Wed, 23 Jan 2008 16:21:46 +0500,
Alexander E. Patrakov wrote:
> 
> Takashi Iwai wrote:
> > At Thu, 17 Jan 2008 20:01:09 +0500,
> > Alexander E. Patrakov wrote:
> >> 2008/1/17, Takashi Iwai <tiwai@suse.de>:
> >>> ... and the below is the fix.  Give it a try.
> >> Tested with no explicit defaults.pcm.dmix.format, with explicit
> >> S16_LE, and with explicit S32_LE, all with Intel HD audio and the PC
> >> speaker (total 6 cases, including one meaningless). In all cases, the
> >> code was able to choose the correct format for talking with hardware
> >> (i.e., the worst of (a) explicitly specified, if any, and (b) the best
> >> hardware-supported one). Thanks for a quick fix!
> > 
> > Thanks for checking.  I applied it to HG tree now.
> 
> Could you please apply the same tweak (use the best available sample format 
> unless overridden) to dsnoop, too?

Done.


Takashi

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

end of thread, other threads:[~2008-01-23 11:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-17 13:40 S16_LE + softvol = bad Alexander E. Patrakov
2008-01-17 14:00 ` Clemens Ladisch
2008-01-17 14:11   ` Takashi Iwai
2008-01-17 14:23     ` Takashi Iwai
2008-01-17 15:01       ` Alexander E. Patrakov
2008-01-18 12:46         ` Takashi Iwai
2008-01-23 11:21           ` Alexander E. Patrakov
2008-01-23 11:31             ` Takashi Iwai
     [not found]   ` <c072ca310801170612p7d06813ve5269dd82afb6619@mail.gmail.com>
2008-01-17 14:14     ` Alexander E. Patrakov

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.