Introducing - Pyaudiogen

T

Thomas Jollans

Hello list,

Here's a little Python toy I've been hacking on, as I thought it might
amuse some of you. [1] Python 3.1+ (not sure about 3.0)

It's a package called 'audiogen' which includes bindings to libao for
portable audio output and some functions/classes/... for generating
audio. It grew from the idea that code like this would be neat:

def sinewave(arguments go here):
wavetable = # generate sinusoid waveform
while True:
yield wavetable

or even something like this:

def eric_idle(arguments do here):
for note in (Do, Re, Mi):
yield plucked_string(note)
yield pause(beats=2)

Generalised a bit to allow for stereo / multi-channel output, plus some
decorators, and you get pyaudiogen. Some examples and all the code is on
bitbucket [1]. For good measure, here's the sine wave function sketched
above as real, working, code:

@wave_gen(channels=1) # mono output
def sinusoid(freq, amp, srate : 'rate'):
from math import sin, pi
wavelength = srate // freq
wavetable = wave.from_float(amp*sin(2 * pi * x / wavelength)
for x in range(int(wavelength)))
while True:
yield (wavetable,)


Suggestions welcomed!

-- Thomas


[1] <URL:http://bitbucket.org/jollybox/pyaudiogen>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top