Scott
Scott

Reputation:

OpenAL Real Time Audio Processing from Microphone

I would like to write a cross-platform application that can process and play back microphone data in real time. Imagine as a proof of concept a chat room where people can talk to each other and apply filters to their voices. Is OpenAL appropriate for this? If not, can someone provide an alternative? Additionally, if anyone can provide or link me to a simple "hello world" program that reads from the microphone and spits the output back out, that would be awesome.

Thanks!

Upvotes: 5

Views: 5047

Answers (3)

JCooper
JCooper

Reputation: 6525

OpenAL might not be great for this purpose. I would recommend using SDL (perhaps with SDL_Mixer) or PortAudio. Both are cross-platform and both are fairly easy to use.

To use OpenAL for this purpose you have to poll to see how many samples have accumulated in a hidden circular buffer. Then you grab them out when you decide you're ready. Then you apply your filter. Then you attach the filtered data to a buffer. Then you queue the buffer onto a source and tell the source to play (unless it's already playing). The strength of OpenAL, in my opinion, is for applying 3D effects. It's not as great at real-time filtering, although I expect you can make it work if you're willing to accept a little more lag on the output. I prefer the callback model over the buffer-object model for filtering.


Edit: I posted some code that would do exactly this over at: OpenAL: How to create simple "Microphone Echo" programm? A comment points out where one would put the processing.

Upvotes: 3

Karl
Karl

Reputation: 14974

OpenAL is technically capable of it according to the API, but Apple's implementation for iOS doesn't include the audio capture features.

On iOS, you'll need to either use Audio Queues or Audio Units to record. For applying realtime effects, Audio Units is the way to go, though much more complicated than Audio Queues.

Upvotes: 2

mahboudz
mahboudz

Reputation: 39376

Apple has two samples (or more) that do that. Check out aurioTouch and SpeakHere. aurioTouch can take mic input and play it back and SpeakHere can take in input and record it, and you can pretty easily modify it to play that back.

Upvotes: -1

Related Questions