Every audio engine I've tried (SoLoud, cAudio, openal-soft) hasn't worked on my pi zero. I just want to be able to play audio in a program without too much hassle. I can use a system call like system("aplay sound.wav") but system() calls are expensive and supposedly a security problem. Are there any alternatives to using a system call that I can use without being a major hassle? Thanks

  • What about SoLoud, cAudio, openal-soft. They crashes? What is system()? Python? – Ingo Feb 13 '18 at 22:04
  • Every engine I've tried has had a separate problem with it. SoLoud (eventually) compiles correctly using a custom-made CMakeLists.txt file, but produces no sound. The other two fail at compile time, and have various problems that seemingly have no fix (at least that can be found from compile errors, documentation and online resources). I'd rather avoid them for now than spend a huge amount of time trying to fix them as the project has a fast looming deadline. – user3925417 Feb 14 '18 at 11:23
  • Please edit your question and put your comment in there – Ingo Feb 14 '18 at 20:33
  • This is a general programming question. There are dozens of audio libraries out there. alsa, pulse, sdlmixer, gstreamer etc. etc. Never heard about SoLoud, and cAudio/OpenAl are a strange choice unless you need 3D sound. – Dmitry Grigoryev Apr 12 at 22:56

For simplicity, I can recommend gtkIOStream's ALSA Playback class. It is in C++ however.

For a dead simple standard setup, run like so :

  const string deviceName="hw:0,0"; // open the device
  Playback playBack(deviceName.c_str());

  snd_pcm_uframes_t pSize; // find out the number of frames per write
  cout<<"period size "<<pSize<<endl;

  cout<<"sample rate "<<playBack.getSampleRate()<<"Hz"<<endl;

  unsigned int ch=playBack.getChannels();
  cout<<"channels "<<ch<<endl;

  if (!playBack.prepared()){
    cout<<"should be prepared, but isn't"<<endl;
    return -1;

  Eigen::Array<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> buffer(pSize, ch);

  while (true){
    buffer.setZero(); // write your audio data to the buffer here.
    playBack<<buffer; // play the audio data

For a more complex example, consult the gtkIOStream example here.

If you want to install it, the tutorials are here.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.