Hello All, I'm curious if the Dmix plugin has a fixed period size and, if so, how to deal with that. I'm a bit of an ALSA newbie, so please forgive any confused assumptions in the question. Here's the symptoms I am seeing and the problem I am trying to get at: While investigating some audio stuttering issues in a program being run inside DOSBox, I came to the conclusion that the audio buffer size being set in the DOSBox configuration had no effect. Upon further investigation, the buffer size setting of a test program using libSDL also had no effect. This appears to be due to the fact that libSDL always sets the buffer size to twice the period size and that the period size can not be changed for the default audio device on my computer for a given rate. However, it can be changed if the hardware device is used directly. I have appended the alsa-lib test program I am using to investigate this behavior and the output of the program when run against both the default device (using dmix) and the first hardware device (hw:0,0). My machine is a Thinkpad T60p with an AD1981HD using the HDA-Intel driver. I am running Debian testing with no /etc/asoundrc or ~/.asoundrc files. So, is this a shortcoming of Dmix, something else, or am I misunderstanding the issue? Can I work around it somehow, either globally, per-program, or by changing application code? Thanks for your time and effort, Kevin -8<---------------------- printalsaparams.c ------------------------- /* Based on http://equalarea.com/paul/alsa-audio.html#playex */ #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <alsa/asoundlib.h> void print_params(const snd_pcm_hw_params_t *params) { snd_pcm_uframes_t buffersizemax, buffersizemin; snd_pcm_uframes_t periodsizemax, periodsizemin; unsigned int periodsmax, periodsmin; unsigned int ratemax, ratemin; assert(snd_pcm_hw_params_get_buffer_size_min(params, &buffersizemin) == 0); assert(snd_pcm_hw_params_get_buffer_size_max(params, &buffersizemax) == 0); printf("Buffer Size: %lu - %lu\n", buffersizemin, buffersizemax); assert(snd_pcm_hw_params_get_periods_min(params, &periodsmin, NULL) == 0); assert(snd_pcm_hw_params_get_periods_max(params, &periodsmax, NULL) == 0); printf("Periods: %u - %u\n", periodsmin, periodsmax); assert(snd_pcm_hw_params_get_period_size_min(params, &periodsizemin, NULL) == 0); assert(snd_pcm_hw_params_get_period_size_max(params, &periodsizemax, NULL) == 0); printf("Period Size: %lu - %lu\n", periodsizemin, periodsizemax); assert(snd_pcm_hw_params_get_rate_min(params, &ratemin, NULL) == 0); assert(snd_pcm_hw_params_get_rate_max(params, &ratemax, NULL) == 0); printf("Rate: %u - %u\n", ratemin, ratemax); } int main(int argc, const char **argv) { const char *devname; int err; unsigned int rate = 44100; snd_pcm_t *playback_handle; snd_pcm_hw_params_t *hw_params; if (argc > 2) { fprintf(stderr, "Usage: alsacfg [device name]\n"); return EXIT_FAILURE; } else if (argc == 2) { devname = argv[1]; } else { devname = "default"; } if ((err = snd_pcm_open(&playback_handle, devname, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)) < 0) { fprintf (stderr, "cannot open audio device %s: %s\n", devname, snd_strerror(err)); return EXIT_FAILURE; } snd_pcm_hw_params_alloca(&hw_params); if ((err = snd_pcm_hw_params_any(playback_handle, hw_params)) < 0) { fprintf(stderr, "cannot initialize hardware parameter structure: %s\n", snd_strerror(err)); return EXIT_FAILURE; } printf("After Initialization\n"); print_params(hw_params); printf("\n"); if ((err = snd_pcm_hw_params_set_access(playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { fprintf(stderr, "cannot set access type: %s\n", snd_strerror(err)); return EXIT_FAILURE; } if ((err = snd_pcm_hw_params_set_format(playback_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) { fprintf(stderr, "cannot set sample format: %s\n", snd_strerror(err)); return EXIT_FAILURE; } if ((err = snd_pcm_hw_params_set_channels(playback_handle, hw_params, 2)) < 0) { fprintf(stderr, "cannot set channel count: %s\n", snd_strerror(err)); return EXIT_FAILURE; } printf("After Channels\n"); print_params(hw_params); printf("\n"); if ((err = snd_pcm_hw_params_set_rate_near(playback_handle, hw_params, &rate, NULL)) < 0) { fprintf(stderr, "cannot set sample rate: %s\n", snd_strerror(err)); return EXIT_FAILURE; } printf("After Rate\n"); print_params(hw_params); printf("\n"); if ((err = snd_pcm_hw_params(playback_handle, hw_params)) < 0) { fprintf(stderr, "cannot set parameters: %s\n", snd_strerror(err)); return EXIT_FAILURE; } printf("After Set Params\n"); print_params(hw_params); printf("\n"); if ((err = snd_pcm_prepare(playback_handle)) < 0) { fprintf (stderr, "cannot prepare audio interface for use: %s\n", snd_strerror(err)); return EXIT_FAILURE; } if ((err = snd_pcm_close(playback_handle)) < 0) { fprintf (stderr, "cannot close audio interface: %s\n", snd_strerror(err)); return EXIT_FAILURE; } return EXIT_SUCCESS; } -8<------------------------------------------------------------------- -8<------------------- Output with default PCM ----------------------- After Initialization Buffer Size: 170 - 733007751 Periods: 0 - 8623621 Period Size: 85 - 91628833 Rate: 4000 - 4294967295 After Channels Buffer Size: 170 - 733007751 Periods: 0 - 8623621 Period Size: 85 - 91628833 Rate: 4000 - 4294967295 After Rate Buffer Size: 1881 - 7526 Periods: 1 - 9 Period Size: 940 - 941 Rate: 44100 - 44100 After Set Params Buffer Size: 7526 - 7526 Periods: 7 - 9 Period Size: 940 - 941 Rate: 44100 - 44100 -8<------------------------------------------------------------------- -8<-------------------- Output with hw:0,0 PCM ----------------------- After Initialization Buffer Size: 32 - 16384 Periods: 2 - 32 Period Size: 16 - 8192 Rate: 8000 - 48000 After Channels Buffer Size: 64 - 16384 Periods: 2 - 32 Period Size: 32 - 8192 Rate: 8000 - 48000 After Rate Buffer Size: 64 - 16384 Periods: 2 - 32 Period Size: 32 - 8192 Rate: 44100 - 44100 After Set Params Buffer Size: 16384 - 16384 Periods: 32 - 32 Period Size: 512 - 512 Rate: 44100 - 44100 -8<------------------------------------------------------------------- -- Cheers, | kevin@xxxxxxxxxxxxxxx | JIM: kevinoid@xxxxxxxxxx Kevin | http://kevinlocke.name | IRC: kevinoid on freenode ------------------------------------------------------------------------------ Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox _______________________________________________ Alsa-user mailing list Alsa-user@xxxxxxxxxxxxxxxxxxxxx https://lists.sourceforge.net/lists/listinfo/alsa-user