def adsr(snd, a=10, d=50, s=1.0, r=100): sndlen = flen(snd) attack = mstf(a) decay = mstf(d) sustain_to = s release = mstf(r) if attack + decay + release > sndlen: sustain_length = sndlen - (attack + decay + release) else: sustain_length = 0 decay = sndlen - (attack + release) if attack + release > sndlen: attack = sndlen / 2 release = sndlen / 2 decay = 0 out = env(cut(snd, 0, attack), 'line') if decay > 0: decay = cut(snd, flen(out), decay) if sustain_to < 1 and sustain_length > 0: decaytable = wavetable('phasor', 1024, 1, sustain_to) out += benv(decay, decaytable) out += amp(cut(snd, flen(out), sustain_length), sustain_to) out += env(cut(snd, flen(out), release), 'phasor') return out
def benv(sound, points): chunksize = mstf(3) sounds = split(sound, chunksize) points = breakpoint(points, len(sounds)) return ''.join([amp(s, points[i]) for i, s in enumerate(sounds)])