- snd_pcm_sw_params_alloca(&swparams);
- if (snd_pcm_hw_params_any(pad->handle, hwparams) < 0)
- return -E_BROKEN_CONF;
- if (snd_pcm_hw_params_set_access(pad->handle, hwparams,
- SND_PCM_ACCESS_RW_INTERLEAVED) < 0)
- return -E_ACCESS_TYPE;
- if (snd_pcm_hw_params_set_format(pad->handle, hwparams, FORMAT) < 0)
- return -E_SAMPLE_FORMAT;
- if (snd_pcm_hw_params_set_channels(pad->handle, hwparams,
- pad->channels) < 0)
- return -E_CHANNEL_COUNT;
- if (snd_pcm_hw_params_set_rate_near(pad->handle, hwparams,
- &pad->samplerate, 0) < 0)
- return -E_SET_RATE;
- err = snd_pcm_hw_params_get_buffer_time_max(hwparams, &pad->buffer_time, 0);
- if (err < 0 || !pad->buffer_time)
- return -E_GET_BUFFER_TIME;
- PARA_INFO_LOG("buffer time: %d\n", pad->buffer_time);
- if (snd_pcm_hw_params_set_buffer_time_near(pad->handle, hwparams,
- &pad->buffer_time, 0) < 0)
- return -E_SET_BUFFER_TIME;
- if (snd_pcm_hw_params(pad->handle, hwparams) < 0)
- return -E_HW_PARAMS;
- snd_pcm_hw_params_get_period_size(hwparams, &period_size, 0);
+ msg = "Broken alsa configuration";
+ ret = snd_pcm_hw_params_any(pad->handle, hwparams);
+ if (ret < 0)
+ goto fail;
+ msg = "access type not available";
+ ret = snd_pcm_hw_params_set_access(pad->handle, hwparams,
+ SND_PCM_ACCESS_RW_INTERLEAVED);
+ if (ret < 0)
+ goto fail;
+ msg = "sample format not available";
+ ret = snd_pcm_hw_params_set_format(pad->handle, hwparams,
+ pad->sample_format);
+ if (ret < 0)
+ goto fail;
+ msg = "channels count not available";
+ ret = snd_pcm_hw_params_set_channels(pad->handle, hwparams,
+ pad->channels);
+ if (ret < 0)
+ goto fail;
+ msg = "could not set sample rate";
+ ret = snd_pcm_hw_params_set_rate_near(pad->handle, hwparams,
+ &pad->sample_rate, NULL);
+ if (ret < 0)
+ goto fail;
+ /* alsa wants microseconds */
+ pad->buffer_time = conf->buffer_time_arg * 1000;
+ msg = "could not set buffer time";
+ ret = snd_pcm_hw_params_set_buffer_time_near(pad->handle, hwparams,
+ &pad->buffer_time, NULL);
+ if (ret < 0)
+ goto fail;
+ pad->buffer_time /= 1000; /* we prefer milliseconds */
+ period_time = pad->buffer_time * 250; /* buffer time / 4 */
+ msg = "could not set period time";
+ ret = snd_pcm_hw_params_set_period_time_near(pad->handle, hwparams,
+ &period_time, NULL);
+ if (ret < 0)
+ goto fail;
+
+ msg = "unable to install hw params";
+ ret = snd_pcm_hw_params(pad->handle, hwparams);
+ if (ret < 0)
+ goto fail;
+ snd_pcm_hw_params_get_period_size(hwparams, &period_size, NULL);