Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

import changes from sugar maple prep

  • Loading branch information...
commit 6a965d4476651b08eac6e3f0014cd83f47d46045 1 parent 4f21fce
Erik Schoster authored
View
20 console.py
@@ -2,25 +2,35 @@
import subprocess
import os
import dsp
+import wes
import sounds
+dsp.quiet = True
+
class Fabric(cmd.Cmd):
prompt = 'fabric: '
intro = 'A just-in-realtime console.'
+ poempos = 0
+
def play(self, cmd):
orcs = os.listdir('orc/')
for orc in orcs:
if cmd[0] == orc[0:2]:
- cmd[0] = 'orc/' + orc
- shhh = open(os.devnull, 'w')
- p = subprocess.Popen(['python'] + cmd, shell=False, stdout=shhh)
- shhh.close()
- print 'playing', cmd
+ cmd.pop(0)
+ orc = 'orc.' + orc.split('.')[0]
+ p = __import__(orc, globals(), locals(), ['play'])
+ process = dsp.poly(p.play, [sounds] + cmd + ['l:' + str(self.poempos)])
+
+ print 'playing', orc, cmd
return True
print 'not found'
+ def do_swell(self, cmd):
+ orcswell = __import__('orc.swell', globals(), locals(), ['play'])
+ dsp.poly(orcswell.play, [sounds] + cmd.split(' '))
+
def default(self, cmd):
self.play(cmd.split(' '))
View
33 dsp.py
@@ -13,7 +13,10 @@
import time
import hashlib
import subprocess
+from multiprocessing import Process, Queue
import os
+import sys
+import cStringIO
from datetime import datetime
audio_params = [2, 2, 44100, 0, "NONE", "not_compressed"]
@@ -25,6 +28,10 @@
seedint = 0
seedstep = 0
seedhash = ''
+quiet = True
+
+def notify(message):
+ sys.stderr.write(message)
def lget(list, index, default=True):
""" Safely return a selected element from a list and handle IndexErrors """
@@ -108,13 +115,14 @@ def timer(cmd='start'):
global thetime
if cmd == 'start':
thetime = time.time()
- print 'Started render at timestamp', thetime
+
+ if not quiet: print 'Started render at timestamp', thetime
return thetime
elif cmd == 'stop':
thetime = time.time() - thetime
themin = int(thetime) / 60
thesec = thetime - (themin * 60)
- print 'Render time:', themin, 'min', thesec, 'sec'
+ if not quiet: print 'Render time:', themin, 'min', thesec, 'sec'
return thetime
def transpose(audio_string, amount):
@@ -556,7 +564,7 @@ def read(filename):
""" Read a 44.1k / 16bit WAV file from disk with the Python wave module.
Mono files are converted to stereo automatically. """
filename = snddir + filename
- print 'loading', filename
+ if not quiet: print 'loading', filename
file = wave.open(filename, "r")
file_frames = file.readframes(file.getnframes())
@@ -575,11 +583,19 @@ def read(filename):
return snd
-def play(out=''):
- """ A silly alsa-dependent hack to enable another silly hack """
+def poly(p, a=[]):
+ p = Process(target=p, args=(a,))
+ p.start()
+
+ return p
+
+def play(out='', cache=False):
+ """ A silly hack to enable another silly hack """
+ if cache: filename = cache(out)
+
shhh = open(os.devnull, 'w')
- filename = cache(out)
- p = subprocess.Popen(['aplay', '-f', 'cd', filename], shell=False, stdout=shhh, stderr=shhh)
+ s = subprocess.Popen(['aplay', '-q', '-f', 'cd'], stdin=subprocess.PIPE, stdout=shhh, stderr=shhh)
+ s.communicate(out)
shhh.close()
return out
@@ -599,6 +615,9 @@ def stream(outs=['']):
return outs
+def args():
+ return [arg for arg in sys.argv if arg != '']
+
def insert_into(haystack, needle, position):
# split string at position index
hay = cut(haystack, 0, position)
View
1  linepos.txt
@@ -0,0 +1 @@
+165
View
0  orc/__init__.py
No changes.
View
75 orc/pulse.py
@@ -0,0 +1,75 @@
+import dsp
+import wes
+
+def play(args):
+ sounds = args.pop(0)
+
+ t = dsp.stf(10)
+ m = 3
+ volume = 1.0
+ sounds = [sounds.va.data, sounds.vb.data, sounds.vc.data, sounds.vd.data, sounds.ve.data, sounds.vf.data, sounds.vg.data]
+ violin = ''
+
+ for arg in args:
+ a = arg.split(':')
+
+ if a[0] == 't':
+ t = dsp.stf(float(a[1]))
+
+ if a[0] == 'm':
+ m = int(a[1])
+
+ if a[0] == 'v':
+ volume = float(a[1]) / 100.0
+
+ if a[0] == 's':
+ violin = sounds[ord(a[1]) - 97]
+
+
+ elapsed = 0
+ line = wes.readline()
+ w = 0
+
+ while elapsed < t:
+ word = line[w % len(line)-1]
+ if violin == '':
+ violin = sounds[int(wes.rword(word) * (len(sounds)-1))]
+
+ fraglen = dsp.mstf(wes.rword(word) * 1000 + 30)
+ seglen = len(word) * fraglen
+
+ divs = [int(wes.translate(a) * 7 + 1) for a in list(word)]
+
+ chordsize = int(wes.rword(word) * 5 + 2)
+
+ chords = []
+ for i in range(chordsize):
+ chord = [dsp.cut(violin, int(wes.rword(word) * (dsp.flen(violin) - seglen)), seglen) for j in range(len(divs))]
+ chords += [ dsp.mix(chord, False, wes.rword(word) * 30 + 3) ]
+
+ streams = []
+ for i,d in enumerate(divs):
+ i = i % len(chords)-1
+ dlen = seglen / d
+
+ padtable = dsp.breakpoint([wes.rword(word) * dlen * 0.125 for bi in range(d / 4)], d)
+ padtable = [int(bi) for bi in padtable]
+
+ attacklen = int(dlen * wes.rword(word) * 0.5) + 41
+ silencelen = dlen - attacklen
+ chord = dsp.fill(chords[i], attacklen)
+ chord = dsp.env(chord, 'phasor', volume)
+ chord = dsp.pad(chord, 0, silencelen)
+ chord = dsp.pan(chord, wes.rword(word))
+ chord = ''.join([dsp.pad(chord, 0, padtable[dd]) for dd in range(d)])
+ chord = dsp.benv(chord, [wes.rword(word) * volume for e in range(int(wes.rword(word) * 7) + 2)])
+ streams += [ chord ]
+
+ out = dsp.mix(streams) * len(word) * m
+
+ if dsp.flen(out) + elapsed > t:
+ out = dsp.cut(out, 0, t - elapsed)
+
+ dsp.play(out)
+ w += 1
+ elapsed += dsp.flen(out)
View
68 orc/rainbow.py
@@ -0,0 +1,68 @@
+import dsp
+import wes
+
+def play(args):
+ sounds = args.pop(0)
+ sounds = [sounds.va.data, sounds.vb.data, sounds.vc.data, sounds.vd.data, sounds.ve.data, sounds.vf.data, sounds.vg.data]
+ length = dsp.stf(1)
+ m = 20
+ d = 3
+ volume = 1.0
+ violin = ''
+
+ for arg in args:
+ a = arg.split(':')
+
+ if a[0] == 's':
+ violin = sounds[ord(a[1]) - 97]
+
+ if a[0] == 't':
+ length = dsp.stf(float(a[1]))
+
+ if a[0] == 'm':
+ m = int(a[1])
+
+ if a[0] == 'v':
+ volume = float(a[1]) / 100.0
+
+ if a[0] == 'd':
+ d = float(a[1])
+
+
+ elapsed = 0
+ while elapsed < length:
+ line = wes.readline()
+ for word in line:
+ if violin == '':
+ violin = sounds[int(wes.rword(word) * (len(sounds)-1))]
+
+ vstart = int(wes.rword(word) * (dsp.flen(violin) - (length / len(line))))
+ v = dsp.cut(violin, vstart, length / len(line))
+
+ numgrains = int(wes.rword(word) * m + len(word) + 2)
+ grainampcurve = dsp.breakpoint([0] + [wes.rword(word) for gc in range(len(word))], numgrains)
+ grainpancurve = dsp.breakpoint([0.5] + [wes.rword(word) for gc in range(len(word))], numgrains)
+ grainpadcurve = dsp.breakpoint([wes.rword(word) * 200 for gc in range(len(word))], numgrains)
+ grainlencurve = dsp.breakpoint([wes.rword(word) * 200 + 0.1 for gc in range(len(word))], numgrains)
+ grainstartcurve = dsp.breakpoint([wes.rword(word) * (dsp.flen(v) - max(grainlencurve)) for gc in range(len(word))], numgrains)
+
+ grains = []
+ for i in range(numgrains):
+ grainpan = grainpancurve[i]
+ grainamp = grainampcurve[i] * volume + 0.01
+ grainenv = wes.wtypes[int(wes.rword(word) * (len(wes.wtypes)-1))]
+
+ grain = dsp.cut(v, int(grainstartcurve[i]), int(grainlencurve[i]))
+ grain = dsp.pan(grain, grainpan)
+ grain = dsp.env(grain, grainenv, True, grainamp)
+ grain = dsp.pad(grain, 0, int(grainpadcurve[i]))
+
+ grains += [ grain ]
+
+ wordpad = dsp.stf(wes.rword(word) * d)
+
+ out = dsp.pad(''.join(grains), 0, wordpad)
+
+ dsp.play(out)
+
+ elapsed += dsp.flen(out)
View
26 orc/scatter.py
@@ -1,26 +0,0 @@
-import dsp
-import sys
-import sounds
-
-args = [arg for arg in sys.argv if arg != '']
-
-dsp.seed(args[1])
-
-slen = dsp.mstf(dsp.randint(40, 1000))
-violin = dsp.randchoose([sounds.va.data, sounds.vb.data, sounds.vc.data, sounds.vd.data, sounds.ve.data])
-vlen = dsp.flen(violin)
-violin = [dsp.cut(violin, dsp.randint(0, vlen - slen), slen) for i in range(len(args[1]))]
-scale = [0.25, 0.5, 1.0, 1.667, 2.0, 3.0]
-
-wtypes = ['sine', 'tri']
-
-outs = []
-for i,v in enumerate(violin):
- v = dsp.transpose(v, dsp.randchoose(scale))
- v = dsp.benv(dsp.pan(v, dsp.rand()), [0] + [dsp.rand() for i in range(4)] + [0])
- v = dsp.pad(v, 0, dsp.randint(4410 * 2, 44100))
- #dsp.delay(dsp.rand(0.0, 0.2))
-
- outs += [ v ]
-
-dsp.stream(outs)
View
106 orc/swell.py
@@ -1,55 +1,57 @@
import dsp
-import time
-import sys
-
-scale = [1.0, 1.125, 1.25, 1.333, 1.5, 1.667, 1.875, 2.0]
-freqs = [1,3,5]
-octave_range = [4, 4]
-pre = []
-length = dsp.stf(3)
-reps = 1
-prerender = False
-
-args = [arg for arg in sys.argv if arg != '']
-
-for arg in args:
- a = arg.split(':')
-
- if a[0] == 'f':
- freqs = a[1].split('.')
- freqs = [int(f) for f in freqs]
-
- if a[0] == 'o':
- octave_range = a[1].split('.')
- octave_range = [float(o) for o in octave_range]
-
- if a[0] == 'l':
- length = dsp.stf(float(a[1]))
-
- if a[0] == 'r':
- reps = int(a[1])
-
- if a[0] == 'p':
- prerender = True
-
-
-violin = dsp.read('sounds/violin-c.wav')
-violin = [dsp.cut(violin.data, dsp.randint(0, 44100), length)]
-
-freqs = [scale[i - 1] * ( dsp.rand(octave_range[0], octave_range[1]) / 4.0 ) for i in freqs]
-
-dsp.dsp_grain *= 4
-
-for i,v in enumerate(violin):
-
- v = dsp.mix([dsp.fill(dsp.transpose(v, f), length) for f in freqs])
- v = dsp.env(v, 'sine')
-
- v *= reps
-
- if prerender == True:
- pre += [ dsp.cache(v) ]
- else:
+import wes
+
+def play(args):
+ freqs = [1,3,5]
+ octave =3
+ pre = []
+ length = dsp.stf(1)
+ reps = 1
+ volume = 1
+ sounds = args.pop(0)
+ sounds = [sounds.va.data, sounds.vb.data, sounds.vc.data, sounds.vd.data, sounds.ve.data, sounds.vf.data, sounds.vg.data]
+ violin = ''
+
+ for arg in args:
+ a = arg.split(':')
+
+ if a[0] == 'f':
+ freqs = a[1].split('.')
+ freqs = [int(f) for f in freqs]
+
+ if a[0] == 'o':
+ octave = float(a[1])
+
+ if a[0] == 't':
+ length = dsp.stf(float(a[1]))
+
+ if a[0] == 'r':
+ reps = int(a[1])
+
+ if a[0] == 'p':
+ prerender = True
+
+ if a[0] == 'v':
+ volume = float(a[1]) / 100.0
+
+ if a[0] == 's':
+ violin = sounds[ord(a[1]) - 97]
+
+ freqs = [wes.scale[i - 1] * ( octave / 4.0 ) for i in freqs]
+
+ dsp.dsp_grain *= 4
+ line = wes.readline()
+
+ for word in line:
+ vstart = int(wes.rword(word) * 44100)
+ if violin == '':
+ violin = sounds[int(wes.rword(word) * (len(sounds)-1))]
+ v = dsp.cut(violin, vstart, length / len(line))
+ v = dsp.mix([dsp.fill(dsp.transpose(v, f), length / len(line)) for f in freqs])
+ v = dsp.env(v, 'sine', False, volume)
+
+ v *= reps
+
dsp.play(v)
-dsp.dsp_grain /= 4
+ dsp.dsp_grain /= 4
View
9 sounds.py
@@ -0,0 +1,9 @@
+import dsp
+
+va = dsp.read('sounds/violin-a.wav')
+vb = dsp.read('sounds/violin-b.wav')
+vc = dsp.read('sounds/violin-d.wav')
+vd = dsp.read('sounds/violin-d.wav')
+ve = dsp.read('sounds/violin-a.wav')
+vf = dsp.read('sounds/violin-ff.wav')
+vg = dsp.read('sounds/violin-gg.wav')
View
116 wes.py
@@ -1,32 +1,12 @@
import dsp
+import re
-def slow(s, speed=0.5, grainsize=4410, transpose=0, shape='line', out=''):
- inlen = dsp.flen(s)
- targetlen = int(inlen * (1.0 / speed))
-
- def bestfit(tlen, gsize, depth=0):
- if tlen % gsize != 0 and depth < 500:
- gsize = bestfit(tlen, gsize + 1, depth + 1)
- return gsize
-
- grainsize = bestfit(targetlen, grainsize)
- numgrains = targetlen / grainsize
-
- grains = []
- positions = dsp.wavetable(shape, numgrains, inlen - grainsize, 0)
- for i in range(numgrains):
- grains += [dsp.cut(s, int(positions[i]), grainsize)]
-
- if transpose > 0:
- grains = [dsp.transpose(g, transpose) for g in grains]
- grains = [dsp.fill(g, grainsize) for g in grains]
-
- grains = [dsp.env(g, 'sine', True) for g in grains]
- grains = [''.join(grains), dsp.pad(''.join(grains[1:]), grainsize / 2, grainsize / 2)]
-
- out += dsp.mix(grains)
-
- return out
+scale = [1.0, 1.125, 1.25, 1.333, 1.5, 1.667, 1.875, 2.0]
+freqs = [196.0, 293.7, 440.0, 659.3]
+ratios = [1.0, 1.5, 2.0, 3.0]
+wtypes = ['line', 'phasor', 'sine', 'tri', 'impulse', 'phasor']
+poem = ''
+crword = []
def read(poem):
""" Ignore whitespeace and read words and lines """
@@ -37,12 +17,94 @@ def read(poem):
for i, line in enumerate(poem):
line = line.split(' ')
line = [word.strip() for word in line]
+ line = [re.sub('[\W_]+', '', word) for word in line]
poem[i] = [word for word in line if line is not '']
return poem
+def readline(linestart=0):
+ global poem
+
+ if poem == '':
+ load()
+
+ linelog = open('linepos.txt', 'r+')
+ cpos = int(linelog.readline())
+
+ if cpos > len(poem) - 1:
+ cpos = 0
+
+ line = poem[cpos]
+
+ cpos += 1
+
+ linelog.seek(0)
+ linelog.write(str(cpos))
+ linelog.close()
+
+ return line
+
+def load(f='poems.txt'):
+ global poem
+ global poemlen
+ f = open(f, 'r')
+
+ poem = read(f.read())
+
+ return poem
+
+def rword(word, low=0.0, high=1.0, recurse=True):
+ global crword
+
+ if crword == []:
+ crword = list(word)
+
+ letter = translate(crword[0]) * (high - low) + low
+ crword.pop(0)
+
+ return letter
+
def numchars(line, count=0):
for word in line:
count += len(word)
return count
+
+def translate(letter):
+ """ Translate standard ASCII chars into 0 - 1 float values """
+
+ l = ord(letter)
+
+ # space, tab, new line, \r
+ if l == 32 or l == 9 or l == 10 or l == 13:
+ return 0
+
+ # symbols
+ if l >= 33 and l <= 47:
+ return (l - 32) / 32.0
+
+ if l >= 58 and l <= 64:
+ return (l - 57 + 15) / 32.0
+
+ if l >= 91 and l <= 96:
+ return (l - 90 + 15 + 7) / 32.0
+
+ if l >= 123 and l <= 126:
+ return (l - 122 + 15 + 7 + 6) / 32.0
+
+ # numerals
+ if l >= 48 and l <= 57:
+ return (l - 47) / 10.0
+
+ # uppercase alpha
+ if l >= 65 and l <= 90:
+ if l == 90:
+ return 1.0
+
+ return (l - 64) / 25.99
+
+ # lowercase alpha
+ if l >= 97 and l <= 122:
+ return (l - 96) / 26.0
+
+ return 0
Please sign in to comment.
Something went wrong with that request. Please try again.