Skip to content

Commit

Permalink
renamed to wavebender
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharydenton committed Apr 23, 2011
1 parent 016f25a commit c9d5ae0
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion binaural.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from wavegen import *
from wavebender import *
import sys

channels = ((sine_wave(170.0, amplitude=0.1),),
Expand Down
5 changes: 2 additions & 3 deletions damped.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from wavegen import *
from wavebender import *
from itertools import *
import sys

Expand All @@ -10,7 +10,6 @@ def ncycles(iterable, n):
def waves():
l = int(44100*0.4) # each note lasts 0.4 seconds

# ACG ACG ACG ACG DCD DCD DCD DCD ...
return cycle(chain(ncycles(chain(islice(damped_wave(frequency=440.0, amplitude=0.1, length=int(l/4)), l),
islice(damped_wave(frequency=261.63, amplitude=0.1, length=int(l/4)), l),
islice(damped_wave(frequency=329.63, amplitude=0.1, length=int(l/4)), l)), 3),
Expand All @@ -24,7 +23,7 @@ def waves():
islice(damped_wave(frequency=293.66, amplitude=0.1, length=int(l/4)), l)),
islice(damped_wave(frequency=261.63, amplitude=0.1, length=3*l), 3*l)))

channels = ((waves(),), (waves(), white_noise(amplitude=0.01),))
channels = ((waves(),), (waves(), white_noise(amplitude=0.001),))

samples = compute_samples(channels, None)
write_wavefile(sys.stdout, samples, None)
2 changes: 1 addition & 1 deletion focus3.py
Expand Up @@ -10,7 +10,7 @@
+++ 100+0/10 302+4/10 500+0/10
'''
from wavegen import *
from wavebender import *
from itertools import *
import sys

Expand Down
9 changes: 4 additions & 5 deletions sbagen.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
import re
import sys
from wavegen import *
from wavebender import *
from itertools import *

def sbagen_phrase(phrase):
Expand Down Expand Up @@ -35,11 +35,10 @@ def sequencer(*seqs):
'''
return chain(*(islice(generator, duration) for generator, duration in seqs))

try:
if sys.argv[1:]:
channels = sbagen_line(' '.join(sys.argv[1:]))
except IndexError:
print >> sys.stderr, "You must enter an sbagen script."
else:
sys.exit(1)

samples = compute_samples(channels)
write_pcm(sys.stdout, samples)
write_wavefile(sys.stdout, samples)
2 changes: 1 addition & 1 deletion square.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from wavegen import *
from wavebender import *
from math import cos
import sys

Expand Down
16 changes: 8 additions & 8 deletions violin.py
@@ -1,16 +1,16 @@
#!/usr/bin/env python
from wavegen import *
from wavebender import *
import sys

def violin(amplitude=0.1):
# simulates a violin playing G.
return (sine_wave(400.0, amplitude=0.76*amplitude),
sine_wave(800.0, amplitude=0.44*amplitude),
sine_wave(1200.0, amplitude=0.32*amplitude),
sine_wave(3400.0, amplitude=0.16*amplitude),
sine_wave(600.0, amplitude=1.0*amplitude),
sine_wave(1000.0, amplitude=0.44*amplitude),
sine_wave(1600.0, amplitude=0.32*amplitude))
return (damped_wave(400.0, amplitude=0.76*amplitude, length=44100 * 5),
damped_wave(800.0, amplitude=0.44*amplitude, length=44100 * 5),
damped_wave(1200.0, amplitude=0.32*amplitude, length=44100 * 5),
damped_wave(3400.0, amplitude=0.16*amplitude, length=44100 * 5),
damped_wave(600.0, amplitude=1.0*amplitude, length=44100 * 5),
damped_wave(1000.0, amplitude=0.44*amplitude, length=44100 * 5),
damped_wave(1600.0, amplitude=0.32*amplitude, length=44100 * 5))

channels = (violin(),)
samples = compute_samples(channels, 44100 * 60 * 1)
Expand Down
6 changes: 3 additions & 3 deletions wavegen.py → wavebender.py
Expand Up @@ -19,7 +19,7 @@ def sine_wave(frequency=440.0, framerate=44100, amplitude=0.5):
period = int(framerate / frequency)
if amplitude > 1.0: amplitude = 1.0
if amplitude < 0.0: amplitude = 0.0
lookup_table = [float(amplitude) * math.sin(2.0*math.pi*float(frequency)*(float(i%period)/float(framerate))) for i in range(period)]
lookup_table = [float(amplitude) * math.sin(2.0*math.pi*float(frequency)*(float(i%period)/float(framerate))) for i in xrange(period)]
return (lookup_table[i%period] for i in count(0))

def square_wave(frequency=440.0, framerate=44100, amplitude=0.5):
Expand All @@ -34,7 +34,7 @@ def square_wave(frequency=440.0, framerate=44100, amplitude=0.5):
def damped_wave(frequency=440.0, framerate=44100, amplitude=0.5, length=44100):
if amplitude > 1.0: amplitude = 1.0
if amplitude < 0.0: amplitude = 0.0
return (float(amplitude) * math.exp(-(float(i%length)/float(framerate))) * math.sin(2.0*math.pi*float(frequency)*(float(i)/float(framerate))) for i in count(0))
return (math.exp(-(float(i%length)/float(framerate))) * s for i, s in enumerate(sine_wave(frequency, framerate, amplitude)))

def white_noise(amplitude=0.5):
'''
Expand Down Expand Up @@ -95,7 +95,7 @@ def main():
args = parser.parse_args()

# each channel is defined by infinite functions which are added to produce a sample.
channels = ((sine_wave(args.frequency, args.rate, args.amplitude), white_noise(0.1)) for i in range(args.channels))
channels = ((sine_wave(args.frequency, args.rate, args.amplitude),) for i in range(args.channels))

# convert the channel functions into waveforms
samples = compute_samples(channels, args.rate * args.time)
Expand Down
8 changes: 8 additions & 0 deletions whitenoise.py
@@ -0,0 +1,8 @@
#!/usr/bin/env python
from wavebender import *
import sys

channels = ((white_noise(amplitude=0.1),),)

samples = compute_samples(channels, 44100 * 60 * 1)
write_wavefile(sys.stdout, samples, 44100 * 60 * 1, nchannels=1)

0 comments on commit c9d5ae0

Please sign in to comment.