def test_sandwich_board(self): l = dsp.read('tests/sounds/linux.wav') g = dsp.read('tests/sounds/guitar1s.wav') f = fx.crossover(l, dsp.win('phasor', 0, 1), dsp.rand(0.1, 0.3), dsp.win('rnd', 0, 1)).graph(fontsize=50, label='Weird FX') ws = Waveset(g).substitute('sine').graph(fontsize=50, label='Waveset Manipulation') ps = oscs.Pulsar2d(freq=dsp.rand(10, 80), pulsewidth=shapes.win('hann')).play(2).graph( fontsize=50, label='Pulsar Synthesis') wt = shapes.win('hann', length=0.4) * shapes.win('sine') * shapes.win('rnd') wt.graph( 'tests/renders/graph_sandwich_board.png', insets=[ps, ws, f], width=900, height=340, label='Pippi: Computer Music With Python', stroke=30, fontsize=30, ) # For the readme shutil.copy('tests/renders/graph_sandwich_board.png', 'banner.png')
def test_range(self): wt = dsp.win('sine') wt.graph('tests/renders/graph_sine_range--1-1.png', y=(-1, 1)) wt.graph('tests/renders/graph_sine_range--2-2.png', y=(-2, 2)) wt.graph('tests/renders/graph_sine_range-0-1.png', y=(0, 1)) wt.graph('tests/renders/graph_sine_range-0.5-2.png', y=(0.5, 2)) wt = dsp.win('sinc') wt.graph('tests/renders/graph_sinc_range--0.2-1.png', y=(-0.25, 1))
def test_widen(self): snd = dsp.read('tests/sounds/linux.wav') out = fx.widen(snd, dsp.win('phasor', 0, 1)) out.write('tests/renders/fx_widen_linux.wav') osc = oscs.Osc('sine', amp=0.2) out = osc.play(snd.dur) out = fx.widen(out, dsp.win('phasor', 0, 1)) out.write('tests/renders/fx_widen_sine.wav')
def test_rand_1000(self): dsp.seed(1000) for m in methods: dsp.randmethod(m) values = [] for _ in range(1000): values += [dsp.rand()] dsp.win(values).graph('tests/renders/rand_%s_1000values.png' % m) # teardown dsp.randmethod('normal')
def test_graincloud_grainsize(self): snd = dsp.read('tests/sounds/guitar1s.wav') out = snd.cloud( length=dsp.rand(8, 16), window='hann', grainlength=dsp.win('sinc', 0.2, 6), grid=dsp.win('hannout', 0.04, 1), spread=1, ) out.write('tests/renders/graincloud_grainsize.wav')
def test_crossover(self): snd = dsp.read('tests/sounds/linux.wav') amount = dsp.win('phasor', 0, 1) smooth = 0.3 fade = dsp.win('rsaw', 0, 1) out = fx.crossover(snd, amount, smooth, fade) out.write('tests/renders/fx_crossover_linux.wav') osc = oscs.Osc('sine', amp=0.2) out = osc.play(snd.dur) out = fx.crossover(out, amount, smooth, fade) out.write('tests/renders/fx_crossover_sine.wav')
def test_vpeed(self): sound = SoundBuffer(filename='tests/sounds/linux.wav') speed = dsp.win('hann', 0.5, 2) out = sound.vspeed(speed) out.write('tests/renders/soundbuffer_vspeed_0.5_2.wav') speed = dsp.win('hann', 0.15, 0.5) out = sound.vspeed(speed) out.write('tests/renders/soundbuffer_vspeed_0.15_0.5.wav') speed = dsp.win('hann', 5, 50) out = sound.vspeed(speed) out.write('tests/renders/soundbuffer_vspeed_5_50.wav')
def test_add_wavetables(self): win = dsp.win([1, 2, 3]) self.assertEqual(len(win), 3) self.assertEqual(win + 2, dsp.win([1, 2, 3, 2])) self.assertEqual(win, dsp.win([1, 2, 3])) self.assertEqual(win + dsp.win([1, 3, 5]), dsp.win([1, 2, 3, 1, 3, 5])) self.assertEqual(win, dsp.win([1, 2, 3])) self.assertEqual(dsp.win([1, 3, 5]) + win, dsp.win([1, 3, 5, 1, 2, 3])) self.assertEqual(win, dsp.win([1, 2, 3])) with self.assertRaises(TypeError): 2 + win self.assertEqual(win, dsp.win([1, 2, 3]))
def test_sub_wavetables(self): win = dsp.win([1, 2, 3]) self.assertEqual(len(win), 3) self.assertEqual(win - 2, dsp.win([-1, 0, 1])) self.assertEqual(win, dsp.win([1, 2, 3])) self.assertEqual(win - dsp.win([1, 3, 5]), dsp.win([0, -1, -2])) self.assertEqual(win, dsp.win([1, 2, 3])) self.assertEqual(dsp.win([1, 3, 5]) - win, dsp.win([0, 1, 2])) self.assertEqual(win, dsp.win([1, 2, 3])) with self.assertRaises(TypeError): 2 - win self.assertEqual(win, dsp.win([1, 2, 3]))
def test_mul_wavetables(self): win = dsp.win([1, 2, 3]) self.assertEqual(len(win), 3) self.assertEqual(win * 2, dsp.win([2, 4, 6])) self.assertEqual(win, dsp.win([1, 2, 3])) self.assertEqual(win * dsp.win([1, 3, 5]), dsp.win([1, 6, 15])) self.assertEqual(win, dsp.win([1, 2, 3])) self.assertEqual(dsp.win([1, 3, 5]) * win, dsp.win([1, 6, 15])) self.assertEqual(win, dsp.win([1, 2, 3])) with self.assertRaises(TypeError): 2 * win self.assertEqual(win, dsp.win([1, 2, 3]))
def test_long_graincloud(self): sound = SoundBuffer(filename='tests/sounds/linux.wav') length = 90 grainlength = dsp.win('hann', 0.01, 0.08) grid = dsp.win('hann', 0.01, 0.05) out = sound.cloud(length, grainlength=grainlength, grid=grid, spread=0.5, ) framelength = int(length * sound.samplerate) self.assertEqual(len(out), framelength) out.write('tests/renders/graincloud_long.wav')
def bass_and_lead(length, pos, total_length): numbeats = int(length//BEAT) maxbeats = dsp.randint(2, 16) layers = [] def bass(amp, length, oct=2): if amp == 0: return dsp.buffer(length=length) bass_note = dsp.choice(scale) * 0.25 stack = Waveset(rmx, limit=dsp.randint(5, 20), offset=dsp.randint(0, 100)) stack.normalize() out = oscs.Pulsar2d(stack, windows=['sine'], freq=bass_note).play(length) * dsp.rand(0.02, 0.2) out = fx.lpf(out, bass_note*2) return out.env('hannout').taper(dsp.MS*10) if dsp.rand() > 0.5: basses = bass(0.5, length, 1) else: bpat = drums.eu(numbeats, maxbeats) basses = drums.make(bass, bpat, [BEAT]*numbeats) layers += [ basses ] lead_note = dsp.choice(scale) stack = Waveset(rmx, limit=dsp.randint(5, 20), offset=dsp.randint(0, 100)) stack.normalize() lead = oscs.Pulsar2d(stack, windows=['tri'], freq=lead_note*2, pulsewidth=dsp.win('rnd', 0.1, 1)).play(length/dsp.rand(1,5)).env('hannout').taper(0.01) * dsp.rand(0.02, 0.2) layers += [ lead ] return fx.norm(dsp.mix(layers), 1)
def makekick(length=0.25): out = noise.bln('square', length, [dsp.rand(80, 100), dsp.rand(50, 100)], [dsp.rand(150, 200), dsp.rand(50, 70)]) out = fx.fold(out, amp=dsp.win('saw', 1, dsp.rand(6, 10))) out = fx.lpf(out, 200).vspeed([1, 0.5]) return out.env('pluckout').taper(0.02) * dsp.rand(0.6, 1)
def test_crushed(self): wt = dsp.win('sinc') wt.skew(0.65) wt.crush(10) wt.normalize(1) wt.graph( 'tests/renders/graph_skewed_crushed_normalized_sinc_window.png', stroke=3)
def test_vspeed(self): g = dsp.read('tests/sounds/guitar10s.wav') lfo = dsp.win('sine', 4096) snd = fx.vspeed(g, lfo, 0.5, 1) snd = fx.norm(snd, 1) g = dsp.read('tests/sounds/guitar10s.wav') snd = snd + g snd.write('tests/renders/fx_vspeed.wav')
def test_shape_pulsar(self): dsp.seed() for i in range(4): wts = [shapes.wt('sine', length=1) for _ in range(3)] wins = [shapes.win('sine', length=1) for _ in range(3)] wins = [w * dsp.win('hann') for w in wins] amp = shapes.win('sine', length=1) pw = dsp.win(shapes.win('sine', length=1), 0.1, 1) freq = dsp.win(shapes.win('sine', length=1), 20, 260) grid = dsp.win(shapes.win('sine', length=1), 0.001, 0.75) gl = dsp.win(shapes.win('sine', length=1), 0.03, 0.3) win = shapes.win('sine', length=1) * dsp.win('hann') out = oscs.Pulsar2d( wts, windows=wins, freq=freq, pulsewidth=pw, amp=amp, ).play(dsp.rand(0.2, 1)).cloud(length=20, window=win, grainlength=gl, grid=grid, speed=dsp.win( shapes.win('sine', length=1), 0.03, 2), spread='rnd', jitter='rnd') out.write('tests/renders/shape_pulsar%s.wav' % i)
def test_crush(self): snd = dsp.read('tests/sounds/linux.wav') out = fx.crush(snd) out.write('tests/renders/fx_crush_linux.wav') snd = dsp.read('tests/sounds/guitar10s.wav') out = fx.crush(snd) out.write('tests/renders/fx_crush_guitar.wav') out = fx.crush(snd, dsp.win('sine', 2, 16), 44100) out.write('tests/renders/fx_crush_guitar_vbitdepth.wav') out = fx.crush(snd, 16, dsp.win('sine', 200, 44100)) out.write('tests/renders/fx_crush_guitar_vsamplerate.wav') out = fx.crush(snd, dsp.win('hannin', 2, 16), dsp.win('sine', 200, 44100)) out.write('tests/renders/fx_crush_guitar_vboth.wav')
def theme_synth(length, pos, total_length): notes = [ rhodes.rhodes(dsp.rand(4, 7), freq, 0.3) for freq in scale ] themes = [ [ note.speed(dsp.choice(speeds)) for note in notes * 2 ] for theme in range(8) ] theme = dsp.choice(themes) theme_note = dsp.choice(theme) note = fx.crush(theme_note) return fx.lpf(fx.softclip(note), dsp.win('rnd', 1000, 5000))
def test_create_dss(self): out = DSS(10, ywidth=0.1, xwidth=0.001, freq=100).play(1) out.write('tests/renders/osc_dss-wdefault.wav') out = DSS(10, ywidth=dsp.win('hann', 0.01, 0.05), freq=200).play(1) out.write('tests/renders/osc_dss-whann-0.01-0.05.wav') out = DSS(10, ywidth=1, freq=200).play(1) out.write('tests/renders/osc_dss-w1.wav')
def test_mix_wavetables(self): win = dsp.win([1, 2, 3]) self.assertEqual(len(win), 3) self.assertEqual(win & dsp.win([2, 2, 2]), dsp.win([3, 4, 5])) self.assertEqual(win, dsp.win([1, 2, 3])) self.assertEqual(win & dsp.win([1, 3, 5]), dsp.win([2, 5, 8])) self.assertEqual(win, dsp.win([1, 2, 3]))
def play(ctx): freq = ctx.p.freq or 330.0 length = ctx.p.length or 0.1 amp = dsp.rand(0.1, 0.35) out = make_note(freq, amp, length) cld = out.cloud( length, window='sine', position='rnd', grid=dsp.win('rnd', 0.1, 2), grainlength=dsp.win('rnd', dsp.MS * 10, dsp.MS * 100), speed=dsp.win('rnd', 0.5, 2), ) out = dsp.mix([out, cld]) out = out.adsr(dsp.rand(0.01, 0.02), 0.01, 0.5, 0.1) yield out
def test_convolve_soundbuffer(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') impulse = SoundBuffer(filename='tests/sounds/LittleTikes-A1.wav') out = sound.convolve(impulse) out.write('tests/renders/soundbuffer_convolve_guitar_littletikes.wav') impulse = dsp.win('sinc') out = sound.convolve(impulse) out.write('tests/renders/soundbuffer_convolve_guitar_sinc.wav')
def test_fold(self): amp = dsp.win('hannin', 1, 10) snd = dsp.read('tests/sounds/guitar1s.wav') out = fx.fold(snd, amp) out.write('tests/renders/fx_fold_guitar.wav') snd = oscs.Osc('sine', freq=200).play(1) out = fx.fold(snd, amp) out.write('tests/renders/fx_fold_sine.wav')
def test_create_drunk(self): out = Drunk(10, freq=200).play(10) out.write('tests/renders/osc_drunk-wdefault.wav') out = Drunk(10, width=dsp.win('hann', 0.01, 0.05), freq=200).play(10) out.write('tests/renders/osc_drunk-whann-0.01-0.05.wav') out = Drunk(10, width=1, freq=200).play(10) out.write('tests/renders/osc_drunk-w1.wav') """
def test_convolve(self): sound = dsp.read('tests/sounds/guitar1s.wav') impulse = dsp.read('tests/sounds/LittleTikes-A1.wav') out = fx.convolve(sound, impulse) out.write('tests/renders/fx_convolve_guitar_littletikes.wav') impulse = dsp.win('sinc') out = fx.convolve(sound, impulse) out.write('tests/renders/fx_convolve_guitar_sinc.wav')
def test_graincloud_with_read_lfo(self): sound = SoundBuffer(filename='tests/sounds/linux.wav') cloud = grains.Cloud(sound, position=dsp.win('hann', 0, 1)) length = 30 framelength = int(length * sound.samplerate) out = cloud.play(length) self.assertEqual(len(out), framelength) out.write('tests/renders/graincloud_with_read_lfo.wav')
def test_create_dss(self): out = DSS(10, ywidth=0.1, xwidth=0.001, freq=100).play(10) out.write('tests/renders/osc_dss-wdefault.wav') out = DSS(10, ywidth=dsp.win('hann', 0.01, 0.05), freq=200).play(10) out.write('tests/renders/osc_dss-whann-0.01-0.05.wav') out = DSS(10, ywidth=1, freq=200).play(10) out.write('tests/renders/osc_dss-w1.wav') out = DSS(10, freq=[200,300,150,1500], freq_interpolator='trunc').play(10) out.write('tests/renders/osc_dss-freq-trunc.wav')
def test_create_drunk(self): out = Drunk(10, freq=200).play(10) out.write('tests/renders/osc_drunk-wdefault.wav') out = Drunk(10, width=dsp.win('hann', 0.01, 0.05), freq=200).play(10) out.write('tests/renders/osc_drunk-whann-0.01-0.05.wav') out = Drunk(10, freq=[200,300,400,600]*8, freq_interpolator='trunc' ).play(10) out.write('tests/renders/osc_drunk-trunc-freq.wav')
def test_create_tukey(self): length = 10 shape = dsp.win(shapes.win('sine', length=3), 0, 0.5) chord = tune.chord('i9', octave=2) out = dsp.buffer(length=length) for freq in chord: freq = dsp.wt('sinc', freq, freq*4) l = Tukey(freq=freq, shape=shape).play(length) l = l.pan(dsp.rand()) out.dub(l) out = fx.norm(out, 0.8) out.write('tests/renders/osc_tukey.wav')
def test_fft_process(self): snd = dsp.read('tests/sounds/guitar1s.wav') length = 2 def cb(pos, real, imag): mag, arg = fft.to_polar(real, imag) mag = fx.lpf(mag, pos * 5000 + 100) return fft.to_xy(mag, arg) bs = dsp.win(shapes.win('sine'), 0.05, 0.3) out = fft.process(snd, bs, length, callback=cb) out = fx.norm(out, 1) out.write('tests/renders/fft_process.wav')
def test_graph_rsaw_window(self): wt = dsp.win('rsaw') wt.graph('tests/renders/graph_rsaw_window.png', stroke=3)
def test_graph_hamm_window(self): wt = dsp.win('hamm') wt.graph('tests/renders/graph_hamm_window.png', stroke=3)
def test_graph_bart_window(self): wt = dsp.win('bart') wt.graph('tests/renders/graph_bart_window.png', stroke=3)
def test_graph_tri_window(self): wt = dsp.win('tri') wt.graph('tests/renders/graph_tri_window.png', stroke=3)
def test_crushed(self): wt = dsp.win('sinc') wt.skew(0.65) wt.crush(10) wt.normalize(1) wt.graph('tests/renders/graph_skewed_crushed_normalized_sinc_window.png', stroke=3)
def test_pong(self): win = dsp.win('hann', 0, 0.75).harmonics().skewed(0.08).rightpadded(0, mult=4) win = win + dsp.win('hannout', 0, 0.25, len(win)) win.graph('tests/renders/graph_pong.png', stroke=3)
def test_random_window(self): length = random.randint(1, 1000) win = dsp.win('rnd', wtsize=length) self.assertEqual(length, len(win))
def test_graph_kaiser_window(self): wt = dsp.win('kaiser') wt.graph('tests/renders/graph_kaiser_window.png', stroke=3)
def test_graph_sineout_window(self): wt = dsp.win('sineout') wt.graph('tests/renders/graph_sineout_window.png', stroke=3)