static snd_pcm_t *handle;
static snd_pcm_uframes_t buffer_size, period_size;
static snd_pcm_t *handle;
static snd_pcm_uframes_t buffer_size, period_size;
ret |= snd_pcm_hw_params_set_period_size_near(handle, hwparams, &period_size, NULL);
if (ret != 0) {
ret |= snd_pcm_hw_params_set_period_size_near(handle, hwparams, &period_size, NULL);
if (ret != 0) {
}
snd_pcm_hw_params_get_buffer_size(hwparams, &buffer_size);
snd_pcm_hw_params_get_period_size(hwparams, &period_size, NULL);
snd_pcm_hw_params_get_channels(hwparams, &channels);
}
snd_pcm_hw_params_get_buffer_size(hwparams, &buffer_size);
snd_pcm_hw_params_get_period_size(hwparams, &period_size, NULL);
snd_pcm_hw_params_get_channels(hwparams, &channels);
- silent_period = realloc(silent_period, period_size * 2 * channels);
- if (silent_period != NULL)
- memset(silent_period, 0, period_size * 2 * channels);
+ silent_period = calloc(period_size * channels, 2);
- ret = snd_pcm_prepare(handle);
- ret |= snd_pcm_start(handle);
+ ret = snd_pcm_prepare(handle);
+ if (ret != 0) {
+ fprintf(stderr, PFX "snd_pcm_prepare failed: %d\n", ret);
+ goto fail;
+ }
ret = snd_pcm_writei(handle, samples, len);
if (ret < 0) {
ret = snd_pcm_recover(handle, ret, 1);
ret = snd_pcm_writei(handle, samples, len);
if (ret < 0) {
ret = snd_pcm_recover(handle, ret, 1);
- if (ret != 0)
- fprintf(stderr, "sndout_alsa snd_pcm_recover: %d\n", ret);
+ if (ret != 0 && failure_counter++ < 5)
+ fprintf(stderr, PFX "snd_pcm_recover: %d\n", ret);