PDA

View Full Version : Generate Audio in C



Mr.Macdonald
November 13th, 2010, 04:46 AM
I want to write a raw bit stream and output it to the audio device.

So I want to run my program and have it generate audio which is streamed to my speakers. Not my PC beeper speaker (controlled by pcspkr), but the audio jack.

How do I do this magic?
Thank you

worksofcraft
November 13th, 2010, 05:01 AM
I want to write a raw bit stream and output it to the audio device.

So I want to run my program and have it generate audio which is streamed to my speakers. Not my PC beeper speaker (controlled by pcspkr), but the audio jack.

How do I do this magic?
Thank you

I would look at using gstreamer... I've only used it from Python, so you may have to google for the C API :)

Mr.Macdonald
November 13th, 2010, 05:21 AM
I found this WFS (http://www.oreilly.de/catalog/multilinux/excerpt/ch14-05.htm)

When I try to write to dsp, it prints
open of /dev/dsp failed: Device or resource busy

Apparently this is only for the deprecated OSS. Is there an ALSA equivalent?

abhilashm86
November 13th, 2010, 03:14 PM
You can try OpenAL (http://climpxwss01.creativelabs.com/openal/default.aspx) , I however used in C++ to output some .wav sound in simulation.
The buffer and parameters API are different on windows and Linux platforms, make sure you go through documentation once.

Zugzwang
November 13th, 2010, 06:51 PM
There exists a tuturial on ALSA sound playback: http://www.linuxjournal.com/article/6735?page=0,1. It is a little bit old but it might still work. If it doesn't, search google for newer tutorials.

In Linux, there are multiple sound systems. You will need to choose one to find a suitable tutorial. ALSA is probably not a bad choice.

Arndt
November 13th, 2010, 06:58 PM
I want to write a raw bit stream and output it to the audio device.

So I want to run my program and have it generate audio which is streamed to my speakers. Not my PC beeper speaker (controlled by pcspkr), but the audio jack.

How do I do this magic?
Thank you

Maybe http://www.portaudio.com/ is useful. I'm new to sound generation, so I don't know if it fits the bill.