+ PARA_INFO_LOG("opening %s\n", dev);
+ msg = "unable to open pcm";
+ ret = snd_pcm_open(&pad->handle, dev, SND_PCM_STREAM_PLAYBACK,
+ SND_PCM_NONBLOCK);
+ if (ret < 0)
+ goto fail;
+ ret = snd_pcm_hw_params_malloc(&hwparams);
+ assert(ret >= 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 = 1000U * WRITE_CMD_OPT_UINT32_VAL(ALSA, BUFFER_TIME,
+ wn->lpr);
+ 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;