def mstf(ms, r=None): if r is not None: ms = rand(ms, r) frames_in_ms = audio_params[2] / 1000.0 frames = ms * frames_in_ms return int(frames)
def cross(snds, length, maxlen=None): out = '' for i, snd in enumerate(snds): fadelen = length if maxlen is None else rand(length, maxlen) if i == 0: out = crosstwo(snds[i], snds[i+1], fadelen) elif i < len(snds) - 1: out = crosstwo(out, snds[i+1], fadelen) return out
def cross(snds, length, maxlen=None): out = '' for i, snd in enumerate(snds): fadelen = length if maxlen is None else rand(length, maxlen) if i == 0: out = crosstwo(snds[i], snds[i + 1], fadelen) elif i < len(snds) - 1: out = crosstwo(out, snds[i + 1], fadelen) return out
def bln(length, low=3000.0, high=7100.0, wform='sine2pi'): """ Time-domain band-limited (citation needed) noise generator. Generates a series of single cycles of a given wavetype at random frequences within the supplied range. Sounds nice & warm, if you ask me. """ outlen = 0 cycles = '' while outlen < length: acycle = cycle(rand(low, high), wform) outlen += len(acycle) cycles += acycle return cycles
def wavetable(wtype="sine", size=512, highval=1.0, lowval=0.0): """ The end is near. That'll do, wavetable() """ wtable = [] wave_types = [ "sine", "gauss", "cos", "line", "saw", "impulse", "phasor", "sine2pi", "cos2pi", "vary", "flat" ] if wtype == "random": wtype = wave_types[int(rand(0, len(wave_types) - 1))] if wtype == "sine": wtable = [ math.sin(i * math.pi) * (highval - lowval) + lowval for i in frange(size, 1.0, 0.0) ] elif wtype == "hann" or wtype == "hanning": wtable = [ 0.5 * (1 - math.cos((2 * math.pi * i) / (size - 1))) for i in range(size) ] elif wtype == "gauss": def gauss(x): # From: http://johndcook.com/python_phi.html # Prolly doing it wrong! a1 = 0.254829592 a2 = -0.284496736 a3 = 1.421413741 a4 = -1.453152027 a5 = 1.061405429 p = 0.3275911 sign = 1 if x < 0: sign = -1 x = abs(x) / math.sqrt(2.0) t = 1.0 / (1.0 + p * x) y = 1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * math.exp(-x * x) return abs(abs(sign * y) - 1.0) wtable = [ gauss(i) * (highval - lowval) + lowval for i in frange(size, 2.0, -2.0) ] elif wtype == "sine2pi": wtable = [ math.sin(i * math.pi * 2) * (highval - lowval) + lowval for i in frange(size, 1.0, 0.0) ] elif wtype == "cos2pi": wtable = [ math.cos(i * math.pi * 2) * (highval - lowval) + lowval for i in frange(size, 1.0, 0.0) ] elif wtype == "cos": wtable = [ math.cos(i * math.pi) * (highval - lowval) + lowval for i in frange(size, 1.0, 0.0) ] elif wtype == "itri": # Inverted triangle wtable = [ math.fabs(i) for i in frange(size, highval, lowval - highval) ] # Only really a triangle wave when centered on zero elif wtype == "tri": wtable = [(2.0 / (size + 1)) * ((size + 1) / 2.0 - math.fabs(i - ((size - 1) / 2.0))) for i in range(size)] elif wtype == "saw" or wtype == "line": wtable = [i for i in frange(size, highval, lowval)] elif wtype == "phasor": wtable = wavetable("line", size, highval, lowval) list.reverse(wtable) elif wtype == "impulse": wtable = [float(randint(-1, 1)) for i in range(size / randint(2, 12))] wtable.extend([0.0 for i in range(size - len(wtable))]) elif wtype == "vary": if size < 32: bsize = size else: bsize = size / int(rand(2, 16)) btable = [[ wave_types[int(rand(0, len(wave_types) - 1))], rand(lowval, highval) ] for i in range(bsize)] if len(btable) > 0: btable[0] = lowval else: btable = [lowval] wtable = breakpoint(btable, size) elif wtype == "flat": wtable = [highval for i in range(size)] return wtable
def stf(s, r=None): if r is not None: s = rand(s, r) ms = s * 1000.0 return mstf(ms)
def wavetable(wtype="sine", size=512, highval=1.0, lowval=0.0): """ The end is near. That'll do, wavetable() """ wtable = [] wave_types = ["sine", "gauss", "cos", "line", "saw", "impulse", "phasor", "sine2pi", "cos2pi", "vary", "flat"] if wtype == "random": wtype = wave_types[int(rand(0, len(wave_types) - 1))] if wtype == "sine": wtable = [math.sin(i * math.pi) * (highval - lowval) + lowval for i in frange(size, 1.0, 0.0)] elif wtype == "hann" or wtype == "hanning": wtable = [ 0.5 * ( 1 - math.cos((2 * math.pi * i) / (size - 1))) for i in range(size) ] elif wtype == "gauss": def gauss(x): # From: http://johndcook.com/python_phi.html # Prolly doing it wrong! a1 = 0.254829592 a2 = -0.284496736 a3 = 1.421413741 a4 = -1.453152027 a5 = 1.061405429 p = 0.3275911 sign = 1 if x < 0: sign = -1 x = abs(x)/math.sqrt(2.0) t = 1.0/(1.0 + p * x) y = 1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * math.exp(-x * x) return abs(abs(sign * y) - 1.0) wtable = [gauss(i) * (highval - lowval) + lowval for i in frange(size, 2.0, -2.0)] elif wtype == "sine2pi": wtable = [math.sin(i * math.pi * 2) * (highval - lowval) + lowval for i in frange(size, 1.0, 0.0)] elif wtype == "cos2pi": wtable = [math.cos(i * math.pi * 2) * (highval - lowval) + lowval for i in frange(size, 1.0, 0.0)] elif wtype == "cos": wtable = [math.cos(i * math.pi) * (highval - lowval) + lowval for i in frange(size, 1.0, 0.0)] elif wtype == "itri": # Inverted triangle wtable = [math.fabs(i) for i in frange(size, highval, lowval - highval)] # Only really a triangle wave when centered on zero elif wtype == "tri": wtable = [ (2.0 / (size + 1)) * ((size + 1) / 2.0 - math.fabs(i - ((size - 1) / 2.0))) for i in range(size) ] elif wtype == "saw" or wtype == "line": wtable = [i for i in frange(size, highval, lowval)] elif wtype == "phasor": wtable = wavetable("line", size, highval, lowval) list.reverse(wtable) elif wtype == "impulse": wtable = [float(randint(-1, 1)) for i in range(size / randint(2, 12))] wtable.extend([0.0 for i in range(size - len(wtable))]) elif wtype == "vary": if size < 32: bsize = size else: bsize = size / int(rand(2, 16)) btable = [ [wave_types[int(rand(0, len(wave_types)-1))], rand(lowval, highval)] for i in range(bsize) ] if len(btable) > 0: btable[0] = lowval else: btable = [lowval] wtable = breakpoint(btable, size) elif wtype == "flat": wtable = [highval for i in range(size)] return wtable