S16_LE + softvol = bad
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?
Signature · 1 line
Alexander E. Patrakov
Quoted 2 lines · Alexander E. Patrakov
some cards (most notably, Intel HD audio) have the PCM control as softvol, and default to
S16_LEas 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
At Thu, 17 Jan 2008 15:00:47 +0100,
Quoted 8 lines · Clemens Ladisch
Quoted 2 lines · Alexander E. Patrakov
some cards (most notably, Intel HD audio) have the PCM control as softvol, and default to
S16_LEas 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
At Thu, 17 Jan 2008 15:11:18 +0100,
Quoted 8 lines · I wrote:
At Thu, 17 Jan 2008 15:00:47 +0100,
Quoted 5 lines · Clemens Ladisch
Quoted 2 lines · Alexander E. Patrakov
some cards (most notably, Intel HD audio) have the PCM control as softvol, and default to
S16_LEas a format for dmix.
Quoted 7 lines
Quoted 3 lines
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
src/conf/alsa.conf +1 -1
@@ -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
src/pcm/pcm_direct.c +5 -1
@@ -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 ,
src/pcm/pcm_dmix.c +5 -3
@@ -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, ¶ms.format, + SND_PCM_HW_PARAM_FORMAT, SCONF_UNCHANGED, ¶ms.format, SND_PCM_HW_PARAM_RATE, 0, ¶ms.rate, SND_PCM_HW_PARAM_CHANNELS, 0, ¶ms.channels, SND_PCM_HW_PARAM_PERIOD_TIME, 0, ¶ms.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 ;
2008/1/17, Takashi Iwai <[email protected]>:
Quoted 1 line
... 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!
Quoted 58 lines
Takashi
diff -r
f20b309ff22asrc/conf/alsa.confsrc/conf/alsa.conf Thu Jan 17 15:18:53 2008 +0100 renamed from src/conf/alsa.conf Tue Jan 15 14:29:34 2008 +0100 +1
-1@@ -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.carddiff -r
f20b309ff22asrc/pcm/pcm_direct.csrc/pcm/pcm_direct.c Thu Jan 17 15:18:53 2008 +0100 renamed from src/pcm/pcm_direct.c Tue Jan 15 14:29:34 2008 +0100 +5
-1@@ -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
f20b309ff22asrc/pcm/pcm_dmix.csrc/pcm/pcm_dmix.c Thu Jan 17 15:18:53 2008 +0100 renamed from src/pcm/pcm_dmix.c Tue Jan 15 14:29:34 2008 +0100 +5
-3@@ -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, ¶ms.format, + SND_PCM_HW_PARAM_FORMAT, SCONF_UNCHANGED, ¶ms.format, SND_PCM_HW_PARAM_RATE, 0, ¶ms.rate, SND_PCM_HW_PARAM_CHANNELS, 0, ¶ms.channels, SND_PCM_HW_PARAM_PERIOD_TIME, 0, ¶ms.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;
Signature · 1 line
Alexander E. Patrakov
At Thu, 17 Jan 2008 20:01:09 +0500,
Quoted 10 lines · Alexander E. Patrakov
2008/1/17, Takashi Iwai <[email protected]>:
Quoted 1 line
... and the below is the fix. Give it a try.
Tested with no explicit defaults.pcm.dmix.format, with explicit
S16_LE, and with explicitS32_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
Quoted 4 lines · Takashi Iwai
At Thu, 17 Jan 2008 20:01:09 +0500,
Quoted 2 lines · Alexander E. Patrakov
2008/1/17, Takashi Iwai <[email protected]>:
Quoted 1 line
... and the below is the fix. Give it a try.
Quoted 8 lines
Quoted 6 lines
Tested with no explicit defaults.pcm.dmix.format, with explicit
S16_LE, and with explicitS32_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?
Signature · 1 line
Alexander E. Patrakov
At Wed, 23 Jan 2008 16:21:46 +0500,
Quoted 13 lines · Alexander E. Patrakov
Quoted 11 lines · Takashi Iwai
At Thu, 17 Jan 2008 20:01:09 +0500,
Quoted 8 lines · Alexander E. Patrakov
2008/1/17, Takashi Iwai <[email protected]>:
Quoted 1 line
... and the below is the fix. Give it a try.
Tested with no explicit defaults.pcm.dmix.format, with explicit
S16_LE, and with explicitS32_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!
Quoted 4 lines
Quoted 1 line
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
A message that is not in the archive (sent off-list or not yet received): [email protected]
[sorry for a possible duplicate]
2008/1/17, Clemens Ladisch <[email protected]>:
Quoted 7 lines
Quoted 2 lines · Alexander E. Patrakov
some cards (most notably, Intel HD audio) have the PCM control as softvol, and default to
S16_LEas 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