Skip to content
Advertisement

How to properly set up ALSA device

Edit: This question is different than the proposed duplicate because I’m asking How do you set the period/buffer size that will work with multiple targets each with different sound hardware?.

I have created some code that attempts to set up ALSA before playback of an OGG file. The code below works on one embedded Linux platform, but on another it fails with the following output:

JavaScript

I’ve included only the code that demonstrates the issue. setup_alsa() is not complete and won’t completely configure an alsa device.

JavaScript

What is the normal way to setup ALSA that doesn’t require a specific buffer/period size be set that provides smooth audio playback?**

Advertisement

Answer

As it turns out, I can program my ALSA setup routine to let ALSA determine what the nearest working period/buffer size is by using snd_pcm_hw_params_set_buffer_size_near() instead of snd_pcm_hw_params_set_buffer_size().

The following code now works on both platforms:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement