#define _GNU_SOURCE #include #include #include #include #define check(v) if(v < 0) { perror(#v); exit(1); } int main(void) { snd_pcm_t *handle; snd_pcm_hw_params_t *hw_params; snd_pcm_sw_params_t *sw_params; int val = 0; char *name = getenv("DEVICE"); snd_pcm_hw_params_alloca(&hw_params); snd_pcm_sw_params_alloca(&sw_params); if(!name) name = "hw:0"; printf("opening %s\n", name); check(snd_pcm_open(&handle, name, SND_PCM_STREAM_PLAYBACK, 0)); check(snd_pcm_hw_params_any(handle, hw_params)); check(snd_pcm_hw_params(handle, hw_params)); check(snd_pcm_sw_params_current(handle, sw_params)); // Enable the period event check(snd_pcm_sw_params_set_period_event(handle, sw_params, 1)); check(snd_pcm_sw_params_get_period_event(sw_params, &val)); assert(val == 1); // After applying sw params once, the params struct still says the // period event is enabled. check(snd_pcm_sw_params(handle, sw_params)); check(snd_pcm_sw_params_get_period_event(sw_params, &val)); assert(val == 1); // Applying the same sw params a second time should still leave the // period event enabled, but this assert fails. check(snd_pcm_sw_params(handle, sw_params)); check(snd_pcm_sw_params_get_period_event(sw_params, &val)); assert(val == 1); return 0; }