Skip to content
Browse files

busy bees

  • Loading branch information...
1 parent 353b658 commit 1cabff908ecf0e34f71707a8c3340b31f8ab8704 @hecanjog committed Mar 3, 2012
Showing with 25 additions and 8 deletions.
  1. +9 −1 dsp.py
  2. +16 −7 haiku.py
View
10 dsp.py
@@ -128,8 +128,16 @@ def transpose(audio_string, amount):
def byte_string(number):
""" Return integer encoded as bytes formatted for wave data """
+ number = cap(number, 32767, -32768)
return struct.pack("<h", number)
+def pack(number):
+ """ wrapper for byte_string that takes -1.0 to 1.0 as input """
+ number = cap(number, 1.0, -1.0)
+ number = (number + 1.0) * 0.5
+ number = number * 65535 - 32768
+ return byte_string(int(number))
+
def tone(length=44100, freq=440, wavetype='sine2pi', amp=1.0, blocksize=0):
cyclelen = htf(freq * 0.99)
numcycles = length / cyclelen
@@ -169,7 +177,7 @@ def noise(length):
def cycle(freq, wavetype='sine2pi', amp=1.0):
wavecycle = wavetable(wavetype, htf(freq))
- return ''.join([byte_string(cap(amp * s * 32767, 32767, -32768)) * audio_params[0] for s in wavecycle])
+ return ''.join([pack(amp * s) * audio_params[0] for s in wavecycle])
def scale(low_target, high_target, low, high, pos):
pos = float(pos - low) / float(high - low)
View
23 haiku.py
@@ -1,14 +1,23 @@
import dsp
dsp.timer('start')
+dsp.seed('beec')
-out = ''
-thirty = 44100 * 2 * 2 * 30;
+# Busy bees
+# I revised this over 4+ hours, and ended up with
+# almost nothing to show for it. So it goes!
-for i in range(thirty):
- d = i % (thirty / 100) + 1
- s = i % d
- out += chr(s % 256)
+def bee(tonic, out=''):
+ t = dsp.stf(120) / dsp.htf(tonic);
-print dsp.write(out, 'haiku-12-03-01-thirtyc', False)
+ for i in range(t):
+ wtable = dsp.wavetable('line', dsp.htf(tonic))
+ out += dsp.pan(''.join([dsp.pack(0.4 * f * 2.0 - 1.0) * 2 for f in wtable]), dsp.rand())
+
+ return out
+
+out = dsp.mix([bee(100 * i) for i in range(1, 10)], False)
+
+print dsp.write(out, 'haiku-12-03-02-beec', False)
dsp.timer('stop')
+

0 comments on commit 1cabff9

Please sign in to comment.
Something went wrong with that request. Please try again.