views:

543

answers:

3

I'm writing a program that involves playing back sine waves and combinations of sine waves... it must run on Mac, and I'm looking for a simple API that I can use. I'm open to ObjC, C, C++, Ruby, Python, etc.... I don't care what language as long as it's just a few lines of code. But Ruby would be nice :-)

On Linux you can write to /dev/dsp, /dev/sound etc. but not on mac. I know how to generate a sine wave, but the problem is getting the PCM samples that I create to the audio hardware. I'm aware of the example code in /Developer/Examples/CoreAudio/SimpleSDK/DefaultOutputUnit but it's several hundred lines of ridiculous Core Audio / AudioUnit code and I want something simple to work with.

A: 

You could dump your PCM to a wave file on disk and use /usr/bin/afplay which is a standard binary on OSX.

nall
Thing about disk speed and space. Save it in the RAM.
Time Machine
+2  A: 

one way is to use PyAudio

import pyaudio, array, math

p = pyaudio.PyAudio()
stream = p.open(rate=44100, channels=1, format=pyaudio.paFloat32, output=True)
stream.write(array.array('f',
    (.25 * math.sin(i / 10.) for i in range(44100))).tostring())
stream.close()
p.terminate()

not very clean code, but it works

PyAudio is not standard, but is available through easy_install (I used python2.5)

cobbal
Looks like I might also be able to use PortAudio directly inside ObjC apps as well.
sbwoodside
A: 

Edit: Bloopsaphone!

Depending on your needs, CSound might be something to look into, though it probably wasn't exactly what you had in mind.

Bob Aman