2011/11/22 Andrew Eikum aeikum@codeweavers.com:
On Tue, Nov 22, 2011 at 06:31:03AM +0800, Raymond Yau wrote:
2011/11/17 Andrew Eikum aeikum@codeweavers.com:
On Wed, Nov 16, 2011 at 11:08:37PM +0100, Clemens Ladisch wrote:
On 11/16/2011 10:31 PM, Andrew Eikum wrote:
On Wed, Nov 16, 2011 at 10:20:07PM +0100, Clemens Ladisch wrote:
Andrew Eikum wrote: > +++ b/include/pcm.h > @@ -44,8 +44,20 @@ extern "C" { > > /** PCM generic info container */ > typedef struct _snd_pcm_info snd_pcm_info_t; > -/** PCM hardware configuration space container */ > + > +/** PCM hardware configuration space container > + * > + * snd_pcm_hw_params_t is an opaque structure which contains a set of possible > + * PCM hardware configurations. For example, a given instance might include a > + * range of buffer sizes, a range of period sizes, and a set of several sample > + * formats. Some subset of all possible combinations these sets may be valid, > + * but not necessarily any combination will be valid. > + * > + * No validation is done by the various snd_pcm_hw_params_set* functions.
These functions do validate the value that the application is trying to set and adjust all other dependent limits.
I didn't find that to be the case in my testing, at least between periods, period_size, and buffer_size. I've attached a test program here.
I can reproduce this.
Try running the program with LIBASOUND_DEBUG=1; it appears that there is a bug in the rate plugin. (Normal programs actually set their rate ...)
This doesn't change the output in any way. I checked the Arch Linux alsa-lib build script[1] and it doesn't seem to disable debugging in any obvious way. Do I have to explicitly enable debugging output and rebuild?
$ LIBASOUND_DEBUG=1 ./alsa_period_count min_buffer_frames: 80 set max buffer size: 80 snd_pcm_hw_params: -12 $
[1] http://projects.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=pa...
There is a bug in your program which set the buffer_size_max to buffer_size_min
err = snd_pcm_hw_params_set_periods(pcm, hw_params, 10, 0); if(err < 0){ printf("snd_pcm_hw_params_set_periods: %d\n", err); return 1; }
err = snd_pcm_hw_params_set_period_size(pcm, hw_params, 1024, 0); if(err < 0){ printf("snd_pcm_hw_params_set_period_size: %d\n", err); return 1; }
The above already set buffer size to 10240, but you set buffer_size_max to buffer_size_min (80)
err = snd_pcm_hw_params_get_buffer_size_min(hw_params, &buffer_frames); if(err < 0){ printf("snd_pcm_hw_params_get_buffer_size: %d\n", err); return 1; } printf("min_buffer_frames: %u\n", buffer_frames);
err = snd_pcm_hw_params_set_buffer_size_max(pcm, hw_params, &buffer_frames); if(err < 0){ printf("snd_pcm_hw_params_get_buffer_size: %d\n", err); return 1; } printf("set max buffer size: %u\n", buffer_frames);
Yes, that's exactly my point. I would expect set_buffer_size_max() to fail, since it's incompatible with the parameters set earlier. Instead, it succeeds.
snd_pcm_hw_params_get_buffer_size_min() return a wrong value (80)
so far , your program still work with "hw", "dmix" and "jack"
It seem the bug is only occur with "pulse" plugin.
"pulse" can get the correct value 10240 after you set the format , rate and channels
"dmix" has a default period size of 1024 "jack" support FLOAT only and a default rate obtained from jack server and a channel map in .asoundrc
pcm.jack { type jack playback_ports { 0 alsa_pcm:playback_1 1 alsa_pcm:playback_2 } capture_ports { 0 alsa_pcm:capture_1 1 alsa_pcm:capture_2 } }
./alsa_period_count jack refine_soft 'jack' (begin) ACCESS: MMAP_INTERLEAVED MMAP_NONINTERLEAVED RW_INTERLEAVED RW_NONINTERLEAVED FORMAT: FLOAT_LE SUBFORMAT: ALL SAMPLE_BITS: ALL FRAME_BITS: ALL CHANNELS: 2 RATE: 44100 PERIOD_TIME: ALL PERIOD_SIZE: ALL PERIOD_BYTES: ALL PERIODS: ALL BUFFER_TIME: ALL BUFFER_SIZE: ALL BUFFER_BYTES: ALL TICK_TIME: ALL Rule 0 (0xea7f80): FORMAT= FLOAT_LE -> FLOAT_LE SAMPLE_BITS=[1 4294967295] Rule 1 (0xea7e70): SAMPLE_BITS=[1 4294967295] -> 32 FORMAT= FLOAT_LE SAMPLE_BITS=32 Rule 2 (0xea7df0): SAMPLE_BITS=32 -> 32 FRAME_BITS=[1 4294967295] CHANNELS=2 Rule 3 (0xea7d70): FRAME_BITS=[1 4294967295] -> 64 SAMPLE_BITS=32 CHANNELS=2 Rule 4 (0xea7cf0): FRAME_BITS=64 -> 64 PERIOD_BYTES=ALL PERIOD_SIZE=ALL Rule 5 (0xea7cf0): FRAME_BITS=64 -> 64 BUFFER_BYTES=[1 4294967295] BUFFER_SIZE=[1 4294967295] Rule 6 (0xea7df0): CHANNELS=2 -> 2 FRAME_BITS=64 SAMPLE_BITS=32 Rule 7 (0xea7cf0): RATE=44100 -> 44100 PERIOD_SIZE=ALL PERIOD_TIME=ALL Rule 8 (0xea7cf0): RATE=44100 -> 44100 BUFFER_SIZE=[1 4294967295] BUFFER_TIME=[1 4294967295] Rule 9 (0xea7df0): PERIODS=ALL -> (0 4294967295] BUFFER_SIZE=[1 4294967295] PERIOD_SIZE=ALL Rule 10 (0xea7df0): PERIOD_SIZE=ALL -> (0 4294967295] BUFFER_SIZE=[1 4294967295] PERIODS=(0 4294967295] Rule 11 (0xea7cf0): PERIOD_SIZE=(0 4294967295] -> (0 536870912) PERIOD_BYTES=ALL FRAME_BITS=64 Rule 12 (0xea7c70): PERIOD_SIZE=(0 536870912) -> (0 189408058) PERIOD_TIME=ALL RATE=44100 Rule 13 (0xea7d70): BUFFER_SIZE=[1 4294967295] -> [1 4294967294] PERIOD_SIZE=(0 189408058) PERIODS=(0 4294967295] Rule 14 (0xea7cf0): BUFFER_SIZE=[1 4294967294] -> [1 536870911] BUFFER_BYTES=[1 4294967295] FRAME_BITS=64 Rule 15 (0xea7c70): BUFFER_SIZE=[1 536870911] -> [1 189408057] BUFFER_TIME=[1 4294967295] RATE=44100 Rule 16 (0xea7c70): PERIOD_BYTES=ALL -> (0 1515264464) PERIOD_SIZE=(0 189408058) FRAME_BITS=64 Rule 17 (0xea7c70): BUFFER_BYTES=[1 4294967295] -> [8 1515264456] BUFFER_SIZE=[1 189408057] FRAME_BITS=64 Rule 18 (0xea7cf0): PERIOD_TIME=ALL -> (0 4294967295) PERIOD_SIZE=(0 189408058) RATE=44100 Rule 19 (0xea7cf0): BUFFER_TIME=[1 4294967295] -> (22 4294967279) BUFFER_SIZE=[1 189408057] RATE=44100 Rule 0 (0xea7f80): FORMAT= FLOAT_LE -> FLOAT_LE SAMPLE_BITS=32 Rule 2 (0xea7df0): SAMPLE_BITS=32 -> 32 FRAME_BITS=64 CHANNELS=2 Rule 4 (0xea7cf0): FRAME_BITS=64 -> 64 PERIOD_BYTES=(0 1515264464) PERIOD_SIZE=(0 189408058) Rule 5 (0xea7cf0): FRAME_BITS=64 -> 64 BUFFER_BYTES=[8 1515264456] BUFFER_SIZE=[1 189408057] Rule 7 (0xea7cf0): RATE=44100 -> 44100 PERIOD_SIZE=(0 189408058) PERIOD_TIME=(0 4294967295) Rule 8 (0xea7cf0): RATE=44100 -> 44100 BUFFER_SIZE=[1 189408057] BUFFER_TIME=(22 4294967279) Rule 9 (0xea7df0): PERIODS=(0 4294967295] -> (0 4294967295] BUFFER_SIZE=[1 189408057] PERIOD_SIZE=(0 189408058) Rule 10 (0xea7df0): PERIOD_SIZE=(0 189408058) -> (0 189408058) BUFFER_SIZE=[1 189408057] PERIODS=(0 4294967295] Rule 11 (0xea7cf0): PERIOD_SIZE=(0 189408058) -> (0 189408058) PERIOD_BYTES=(0 1515264464) FRAME_BITS=64 Rule 12 (0xea7c70): PERIOD_SIZE=(0 189408058) -> (0 189408058) PERIOD_TIME=(0 4294967295) RATE=44100 Rule 14 (0xea7cf0): BUFFER_SIZE=[1 189408057] -> [1 189408057] BUFFER_BYTES=[8 1515264456] FRAME_BITS=64 Rule 15 (0xea7c70): BUFFER_SIZE=[1 189408057] -> [1 189408057] BUFFER_TIME=(22 4294967279) RATE=44100 min periods 2 dir 0 max periods 64 dir 0 min_buffer_frames: 10240 set max buffer size: 10240 refine_soft 'jack' (begin) ACCESS: MMAP_INTERLEAVED FORMAT: FLOAT_LE SUBFORMAT: STD SAMPLE_BITS: 32 FRAME_BITS: 64 CHANNELS: 2 RATE: 44100 PERIOD_TIME: (23219 23220) PERIOD_SIZE: 1024 PERIOD_BYTES: 8192 PERIODS: 10 BUFFER_TIME: (232199 232200) BUFFER_SIZE: 10240 BUFFER_BYTES: 81920 TICK_TIME: ALL Rule 4 (0xea7cf0): FRAME_BITS=64 -> 64 PERIOD_BYTES=8192 PERIOD_SIZE=1024 Rule 7 (0xea7cf0): RATE=44100 -> 44100 PERIOD_SIZE=1024 PERIOD_TIME=(23219 23220) Rule 9 (0xea7df0): PERIODS=10 -> 10 BUFFER_SIZE=10240 PERIOD_SIZE=1024 Rule 10 (0xea7df0): PERIOD_SIZE=1024 -> 1024 BUFFER_SIZE=10240 PERIODS=10 Rule 13 (0xea7d70): BUFFER_SIZE=10240 -> 10240 PERIOD_SIZE=1024 PERIODS=10 Rule 16 (0xea7c70): PERIOD_BYTES=8192 -> 8192 PERIOD_SIZE=1024 FRAME_BITS=64 Rule 18 (0xea7cf0): PERIOD_TIME=(23219 23220) -> (23219 23220) PERIOD_SIZE=1024 RATE=44100 min_periods: 2, max_periods: 64, buffer_frames: 10240, period_frames: 1024, buf/per: 10.000000, periods: 10, periods_dir: 0 ALSA <-> JACK PCM I/O Plugin Its setup is: stream : PLAYBACK access : MMAP_INTERLEAVED format : FLOAT_LE subformat : STD channels : 2 rate : 44100 exact rate : 44100 (44100/1) msbits : 32 buffer_size : 10240 period_size : 1024 period_time : 23219 tstamp_mode : NONE period_step : 1 avail_min : 1024 period_event : 0 start_threshold : 1 stop_threshold : 10240 silence_threshold: 0 silence_size : 0 boundary : 1342177280