Reputation: 17382
I am interested in using Linux and OS X systems as digital musical instruments, for experimental purposes.
I want to know, what are the possible methods of sending an array of numerical data (which describes some length of audio) to the 3.5mm audio out. (So it can be played using some speakers, of course.)
My requirements are that this can be done using C++, as I need real-time generation of audio samples. (Python probably isn't going to cut it.) Ideally I would like to do this cross-platform, but am not so interested in doing this one windows.
The idea is to do something like:
1: Set output mode to 44100KHz, 24bit Mono (L&R). 2: Generate an array of 44100 signed 24bit integers. 3: Tell the computer play XYZ seconds/samples of the data which is in the array, starting from sample number XYZ.
It's easy to do this on something like an Arduino. (Which also can be programmed in C++) For those who are familiar, you can either use the digital out pins directly, or for something more sophisticated, build a simple daughter board which modifies your signal correctly so that it is sinusoidal with both positive and negative voltage swing. (Rather than just positive.)
I think I need something like OpenAL, which as far as I can tell is like OpenGL. I don't seem to be able to find much information on it. It seems as if it isn't developed anymore and hasn't been used for several years. I'm guessing there's an alternative?
Upvotes: 1
Views: 1961
Reputation: 106
OpenAL is a very good choice for this. And it's much easier to learn than OpenGL. Cut-and-paste coding.
It may not have changed recently, but is still in wide use. I personally use it on iOS / OS X. You should double-check for your Linux flavor of choice.
I don't know if it can playback 24-bit PCM. But it certainly can accept 16-bit PCM at 44100 if the underlying audio chip supports that.
Here is one tutorial that may help you:
http://kcat.strangesoft.net/openal-tutorial.html
Upvotes: 3