0

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
0

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
  playBack.getPeriodSize(&pSize);
  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.

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.