[alsa-devel] Problem with "set_period_size"
Alicia Romero
alromor84 at gmail.com
Thu Feb 23 15:06:12 CET 2012
Hi list!
I am new using an ALSA device and I have a problem when setting the period
size.
In my code I try to set the period size to 640 as follow:
snd_pcm_hw_params_set_access (stream->pb_pcm, params,
SND_PCM_ACCESS_RW_INTERLEAVED);
/* Set format */
snd_pcm_hw_params_set_format (stream->pb_pcm, params,
SND_PCM_FORMAT_S16_LE);
/* Set number of channels */
snd_pcm_hw_params_set_channels (stream->pb_pcm, params, 2);
/* Set clock rate */
rate =32000;
snd_pcm_hw_params_set_rate_near (stream->pb_pcm, params, &rate, NULL);
/* Set period size to samples_per_frame frames. */
stream->pb_frames = (snd_pcm_uframes_t) 640;
snd_pcm_hw_params_set_period_size_near (stream->pb_pcm, params,
&stream->pb_frames, NULL);
/* Set the sound device buffer size and latency */
if (param->flags & PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY)
tmp_buf_size = (rate / 1000) * param->output_latency_ms;
else
tmp_buf_size = (rate / 1000) * PJMEDIA_SND_DEFAULT_PLAY_LATENCY;
snd_pcm_hw_params_set_buffer_size_near (stream->pb_pcm, params,
&tmp_buf_size);
stream->param.output_latency_ms = tmp_buf_size / (rate / 1000);
/* Activate the parameters */
snd_pcm_hw_params (stream->pb_pcm, params);
The problem here is that the period size is not set to 640, but to 512.
Otherwise if I use instead:
stream->pb_frames = (snd_pcm_uframes_t) 640;
snd_pcm_hw_params_set_period_size (stream->pb_pcm, params,
&stream->pb_frames, NULL);
the period size is set to 640 and the device is working correctly.
Why is not set to 640 if I use the "*_near*" version?
Thanks!!! :)
More information about the Alsa-devel
mailing list