Created
April 18, 2013 15:20
-
-
Save jacobjoaquin/5413575 to your computer and use it in GitHub Desktop.
Dynamically creates envelope tables, cycling through a user-specified range of table indexes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<CsoundSynthesizer> | |
<CsInstruments> | |
sr = 44100 | |
kr = 44100 | |
ksmps = 1 | |
nchnls = 1 | |
0dbfs = 1.0 | |
instr 1 | |
idur = p3 | |
iamp = p4 | |
ifreq = p5 | |
ienv_table = p6 | |
aenv oscil3 1, 1 / idur, ienv_table | |
a1 oscils iamp, ifreq, 0 | |
out a1 * aenv | |
endin | |
</CsInstruments> | |
<CsScore bin="python"> | |
from csd.pysco import PythonScore | |
from itertools import cycle | |
def note(dur, amp, freq, envelope_table): | |
score.i(1, 0, dur, amp, freq, envelope_table) | |
def gen_envelope(*args): | |
global table_cycler | |
table = table_cycler.next() | |
L = ["f", table, score.cue.now(), 8192, -7] + list(args) | |
score.write(" ".join(str(i) for i in L)) | |
return table | |
table_cycler = cycle(xrange(100, 120)) | |
freq_cycler = cycle([440, 262, 440, 440, 880, 100, 300, 777]) | |
envelope_cycler = cycle([[1, 8192, 0], | |
[0, 4096, 1, 4096, 0], | |
[0, 8092, 1, 100, 0], | |
[0, 1024, 1, 1024, 0.3, 6144, 0], | |
[0, 1024, 1, 6144, 1, 1024, 0]]); | |
score = PythonScore() | |
cue = score.cue | |
score.write('t 0 170') | |
with cue(0): note(4, 0.707, 1000, gen_envelope(0, 8092, 1, 100, 0)) | |
with cue(4): note(1, 0.707, 700, gen_envelope(0, 100, 1, 8191, 0)) | |
with cue(5): note(1, 0.707, 400, gen_envelope(1, 8192, 0)) | |
with cue(6): note(1, 0.707, 100, gen_envelope(0, 100, 1, 100, 1, 7991, 0)) | |
with cue(7): note(1, 0.707, 200, gen_envelope(0, 8092, 1, 100, 0)) | |
with cue(8): | |
for t in range(64): | |
with cue(t): | |
this_table = gen_envelope(*envelope_cycler.next()) | |
note(1, 0.707, freq_cycler.next(), this_table) | |
with cue(72): | |
for t in range(128): | |
with cue(t * 0.5): | |
this_table = gen_envelope(*envelope_cycler.next()) | |
note(0.5, 0.707, freq_cycler.next(), this_table) | |
score.end() | |
</CsScore> | |
</CsoundSynthesizer> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment