views:

312

answers:

1

I am new to CoreAudio, and I would like to output a simple sine wave and square wave with a given frequency and amplitude through the speakers using CA. I don't want to use sound files as I want to synthesize the sound.

What do I need to do this? And can you give me an example or tutorial? Thanks.

+1  A: 

Are you new to audio programming in general? As a starting point i would check out

http://www.audiosynth.com/sinewavedemo.html

This is a minimum osx sinewave implementation by the legendary James Harkins. Note, it doesn't use CoreAudio at all.

If you specifically want to use CoreAudio for your sinewave you need to create an output unit (RemoteIO on the iphone, AUHAL on osx) and supply an input callback, where you can pretty much use the code from the above example. Check out

http://developer.apple.com/mac/library/technotes/tn2002/tn2091.html

The benefits of CoreAudio are chiefly, chain other effects with your sinewave, write plugins for hosts like Logic & provide the interfaces for them, write a host (like Logic) for plugins that can be chained together.

If you don't wont to write a plugin, or host plugins then CoreAudio might not actually be for you. But one of the best things about using CoreAudio is that once you get your sinewave callback working it is easy to add effects, or mix multiple sines together

To do this you need to put your output unit in a graph, to which you can effects, mixers, etc.

Here is some help on setting up graphs http://timbolstad.com/2010/03/16/core-audio-getting-started-pt2/

It isn't as difficult as it looks. Apple provides C++ helper classes for many things (/Developer/Examples/CoreAudio/PublicUtility) and even if you don't want to use C++ (you don't have to!) they can be a useful guide to the CoreAudio API.

mustISignUp
Mmm.. The first example (audiosynth.com...) gives 11415 compile errors and it is quite old (Project Builder), but I'll take a look at it's source code. Thanks
Time Machine
Yes it is quite old but it's not too difficult to get working (i have it running here) and it is an invaluable insight into low-level audio on OSX
mustISignUp