Re: underrun problems after setting parameters with snd_pcm_set_params()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey,


On Tue, 28 Apr 2020, robert rozee wrote:

> the problem only occurs with SHORT sound clips. i found that clips longer than 
> 1111ms played without flaw. clips less that 500ms generally failed to play to 
> the end, but there was no error code returned.

in general, given you have sources available to all the popular apps, it's 
good to check how other apps use the API. I.e. aplay.c may be useful 
simple additional reference for you to see how to use the interfaces.

I think you are missing draining the samples at the end, and then 
your latency is setting is incorrect. I.e.

> snd_pcm_set_params(handle, SND_PCM_FORMAT_U8,
>                            SND_PCM_ACCESS_RW_INTERLEAVED,
>                            1,                           // number of channels
>                            48000,                       // bitrate (bps)
>                            1,                           // resampling on/off
>                            min(500000, sample_length)); // latency

That sample_length does not look, the unit is usecs here. Please try
just putting latency of 500000 (i.e. 0.5sec).

> // send out current buffer content
>   frames=snd_pcm_writei(handle, @buffer, frames_to_write_now);
>   if frames<0 then frames=snd_pcm_recover(handle, frames, 0);
>   if frames<0 then break;
> }

When you have finished writing the audio samples to the ALSA device, you 
need to wait until ALSA has a chance to play all samples out. If you look 
at playback_go() in aplay.c, you'll see:

       snd_pcm_nonblock(handle, 0);
       snd_pcm_drain(handle);
       snd_pcm_nonblock(handle, nonblock);

... at the end. 

Br, Kai



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux