Easy way to generate tones / sine waves on mac? (ruby would be good)

I am writing a program that includes playing sine waves and a combination of sine waves ... it should work on a Mac, and I'm looking for a simple API that I can use. I am open to ObjC, C, C ++, Ruby, Python, etc. I don't care what language it is, so far it is just a few lines of code. But Ruby would be nice :-)

On Linux, you can write in / 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 for the audio equipment. I know the sample code in / Developer / Examples / CoreAudio / SimpleSDK / DefaultOutputUnit, but it's a few hundred lines of funny Core Audio / AudioUnit code, and I want something simple with it.

+3
source share
3 answers

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 accessible via easy_install (I used python2.5)

+5
source

PCM /usr/bin/afplay, OSX.

+1

: Bloopsaphone!

Depending on your needs, CSound may be something you can pay attention to, although this is probably not exactly what you had in mind.

0
source

Source: https://habr.com/ru/post/1720423/


All Articles