The classical C program is something like:
int main() { fprintf(stderr, "hello world\n"); }
a classical OpenGL program is:
open up a window
setup ortho view
draw a colored triangle
Now, I want to do the most basic thing for sound i开发者_开发百科n Linux.
I want to:
1) open up speakers
2) send a bunch of data, meant to be interpreted at 40Khz,
3) have pseakers play said data
no midi, no instruments, ... just playing back raw data
What is the easiest way to do this in a C program? [and what libraries; what's the equiv to OpenGL for sound?]
Thanks!
Sound equivalent of OpenGL is OpenAL library. It is cross-platform, whereas ALSA is Linux-specific.
Linux has two sound API:s: the older Open Sound System (OSS), and the current Advanced Linux Sound Architecture (ALSA).
ALSA is not renowned for being extremely easy to get going with; it's possible that the smallest "hello world"-type app will frighten you. It's mostly verbose due to error-checking though.
You can also use the fact that the default output device is generally mapped as /dev/dsp, so you can just write bits into it and have them played back.
There is a counterpart to OpenGL called, unsurprisingly, OpenAL.
精彩评论