def test_morph(self): sound = SoundBuffer(filename='tests/sounds/linux.wav') tsound = SoundBuffer(filename='tests/sounds/guitar10s.wav') waveset = Waveset(sound) target = Waveset(tsound) out = waveset.morph(target, 'phasor') out.write('tests/renders/waveset_morph_phasor.wav')
def test_split_buffer(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') length = random.triangular(0.1, sound.dur) framelength = int(length * sound.samplerate) durations = [] for grain in sound.grains(length): durations += [grain.dur] # The final grain isn't padded with silence, # so it should only be the grain length if # it can be divided equally into the total # length. for grain_length in durations[:-1]: self.assertEqual(int(grain_length * sound.samplerate), framelength) # Check that the remainder grain is the correct length remainderframes = int( (sound.dur - sum(durations[:-1])) * sound.samplerate) self.assertEqual(int(durations[-1] * sound.samplerate), remainderframes) print(durations[-1], remainderframes) # Check that all the grains add up self.assertEqual(sum(durations), sound.dur)
def test_mix_operator(self): snd1 = SoundBuffer(filename='tests/sounds/guitar1s.wav') snd2 = SoundBuffer(filename='tests/sounds/LittleTikes-A1.wav') snd1 &= snd2 self.assertEqual(snd1.dur, snd2.dur)
def test_create_empty_buffer(self): sound = SoundBuffer() self.assertTrue(len(sound) == 0) self.assertTrue(not sound) sound = SoundBuffer(length=1) self.assertEqual(len(sound), 44100) self.assertTrue(sound)
def test_clip_soundbuffer(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') sound = sound.clip(-0.1, 0.1) self.assertEqual(len(sound), 44100) self.assertTrue(sound.samplerate == 44100) self.assertTrue(sound.max() <= 0.1)
def test_pan(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') for pan_method in ('linear', 'constant', 'gogins'): # Hard pan smoke test pan_left = sound.pan(0, method=pan_method) self.assertEqual(pan_left[random.randint(0, len(pan_left))][0], 0) pan_right = sound.pan(1, method=pan_method) self.assertEqual(pan_right[random.randint(0, len(pan_right))][1], 0)
def test_interleave(self): sound1 = SoundBuffer(filename='tests/sounds/linux.wav') sound2 = SoundBuffer(filename='tests/sounds/guitar10s.wav') waveset1 = Waveset(sound1, limit=10, offset=1000) waveset2 = Waveset(sound2, limit=10, offset=1000) waveset1.interleave(waveset2) out = waveset1.render() out.write('tests/renders/waveset_interleave.wav')
def test_stack_soundbuffer(self): snd1 = SoundBuffer(filename='tests/sounds/guitar1s.wav') snd2 = SoundBuffer(filename='tests/sounds/LittleTikes-A1.wav') channels = snd1.channels + snd2.channels length = max(len(snd1), len(snd2)) out = dsp.stack([snd1, snd2]) self.assertTrue(channels == out.channels) self.assertTrue(length == len(out)) self.assertTrue(snd1.samplerate == out.samplerate) out.write('tests/renders/soundbuffer_stack.wav')
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_pan(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') for pan_method in (dsp.LINEAR, dsp.CONSTANT, dsp.GOGINS): # Hard pan smoke test pan_left = sound.pan(0, method=pan_method) self.assertEqual(pan_left[random.randint(0, len(pan_left))][0], 0) pan_right = sound.pan(1, method=pan_method) self.assertEqual(pan_right[random.randint(0, len(pan_right))][1], 0)
def test_graincloud_with_length_lfo(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') grainlength = dsp.wt('hann', 0.01, 0.1) length = 10 framelength = int(length * sound.samplerate) out = sound.cloud(length, grainlength=grainlength) self.assertEqual(len(out), framelength) out.write('tests/renders/graincloud_with_length_lfo.wav')
def test_graincloud_with_length_lfo(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') grainlength = dsp.wt('hann', 0.01, 0.1) length = 10 framelength = int(length * sound.samplerate) out = sound.cloud(length, grainlength=grainlength) self.assertEqual(len(out), framelength) out.write('tests/renders/graincloud_with_length_lfo.wav')
def test_graincloud_with_extreme_speed_lfo(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') length = 30 speed = dsp.wt('hann', 1, 100) framelength = int(length * sound.samplerate) out = sound.cloud(length=length, speed=speed) self.assertEqual(len(out), framelength) out.write('tests/renders/graincloud_with_extreme_speed_lfo.wav')
def _split(length): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') total = 0 for grain in sound.grains(length): total += len(grain) # Check that the remainder grain is not 0 self.assertNotEqual(len(grain), 0) # Check that all the grains add up self.assertEqual(total, len(sound))
def test_random_split_buffer(self): sound = SoundBuffer('tests/sounds/guitar1s.wav') lengths = [] for grain in sound.grains(1, len(sound)): lengths += [ len(grain) ] # Check that the remainder grain is not 0 self.assertNotEqual(lengths[-1], 0) # Check that all the grains add up self.assertEqual(sum(lengths), len(sound))
def test_random_split_buffer(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') durations = [] for grain in sound.grains(0.001, sound.dur): durations += [grain.dur] # Check that the remainder grain is not 0 self.assertNotEqual(durations[-1], 0) # Check that all the grains add up self.assertEqual(sum(durations), sound.dur)
def test_dub_into_empty_sound(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') out = SoundBuffer(channels=sound.channels, samplerate=sound.samplerate) self.assertEqual(len(out), 0) self.assertEqual(len(sound), 44100) position = random.triangular(0.1, 1) out.dub(sound, pos=position) self.assertEqual(len(out), int((position * sound.samplerate) + len(sound))) self.assertEqual(sound.channels, out.channels)
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_random_split_buffer(self): for _ in range(100): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') total = 0 for grain in sound.grains(0.001, sound.dur): total += len(grain) # Check that the remainder grain is not 0 self.assertNotEqual(len(grain), 0) # Check that all the grains add up self.assertEqual(total, len(sound))
def test_dub_into_empty_sound(self): sound = SoundBuffer('tests/sounds/guitar1s.wav') original_length = len(sound) out = SoundBuffer(channels=sound.channels, samplerate=sound.samplerate) self.assertEqual(len(out), 0) self.assertEqual(len(sound), 44100) position = random.randint(100, 1000) out.dub(sound, pos=position) self.assertEqual(len(out), original_length + position) self.assertEqual(sound.channels, out.channels)
def test_transpose(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') speed = random.triangular(1, 10) out = sound.transpose(speed) self.assertEqual(len(out), len(sound)) speed = random.triangular(0, 1) out = sound.transpose(speed) self.assertEqual(len(out), len(sound)) speed = random.triangular(10, 100) out = sound.transpose(speed) self.assertEqual(len(out), len(sound))
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 test_read_streamed_blocks_from_ringbuffer(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') long_buf_length = int(len(sound) * random.triangular(2, 4)) short_buf_length = int(len(sound) * random.triangular(0.2, 0.9)) long_buf = RingBuffer(long_buf_length, sound.channels, sound.samplerate) short_buf = RingBuffer(short_buf_length, sound.channels, sound.samplerate) pos = 0 block_size = 64 elapsed = 0 while elapsed < len(sound): start = pos * block_size long_buf.write(sound.frames[start:start + block_size]) short_buf.write(sound.frames[start:start + block_size]) elapsed += block_size pos += 1 full_buffer = long_buf.read(len(sound)) part_buffer = short_buf.read(len(sound)) self.assertEqual(len(full_buffer), len(sound)) self.assertTrue(np.array_equal(full_buffer, sound.frames)) self.assertEqual(len(part_buffer), len(short_buf)) self.assertTrue( np.array_equal(part_buffer, sound.frames[-len(short_buf):]))
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 test_render(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') waveset = Waveset(sound) out = waveset.render(channels=1) out.write('tests/renders/waveset_render.wav') self.assertEqual(len(out), len(sound))
def test_retrograde(self): sound = SoundBuffer(filename='tests/sounds/linux.wav') for crossings in [3,30,100,300]: waveset = Waveset(sound, crossings=crossings) waveset.retrograde() out = waveset.render() out.write('tests/renders/waveset_retrograde_%s_crossings.wav' % crossings)
def test_substitute_reversed(self): sound = SoundBuffer(filename='tests/sounds/linux.wav') waveset = Waveset(sound) rev = waveset.reversed() out = waveset.replace(rev) out = fx.norm(out, 1) out.write('tests/renders/waveset_substitute_reversed.wav')
def test_harmonic(self): sound = SoundBuffer(filename='tests/sounds/guitar10s.wav') waveset = Waveset(sound) harmonics = [1, 2, 3] weights = [1, 0.5, 0.25] out = waveset.harmonic(harmonics, weights) out.write('tests/renders/waveset_harmonic_distortion.wav')
def test_create_sinewave(self): osc = Osc('sine', freq=200.0) length = 1 out = osc.play(length) out.write('tests/renders/osc_sinewave.wav') self.assertEqual(len(out), int(length * out.samplerate)) wtA = [random.random() for _ in range(random.randint(10, 1000))] osc = Osc(wtA, freq=200.0) length = 1 out = osc.play(length) out.write('tests/renders/osc_rand_list_wt.wav') self.assertEqual(len(out), int(length * out.samplerate)) wtB = dsp.wt( [random.random() for _ in range(random.randint(10, 1000))]) osc = Osc(wtB, freq=200.0) length = 1 out = osc.play(length) out.write('tests/renders/osc_rand_wt_wt.wav') self.assertEqual(len(out), int(length * out.samplerate)) wtC = SoundBuffer(filename='tests/sounds/guitar1s.wav') osc = Osc(wtC, freq=200.0) length = 1 out = osc.play(length) out.write('tests/renders/osc_guitar_wt.wav') self.assertEqual(len(out), int(length * out.samplerate))
def test_create_stereo_buffer_from_soundfile(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') self.assertEqual(len(sound), 44100) self.assertTrue(sound.samplerate == 44100) sound = dsp.read('tests/sounds/guitar1s.wav') self.assertEqual(len(sound), 44100) self.assertTrue(sound.samplerate == 44100)
def test_mix_mismatched_channels(self): snd1 = SoundBuffer(filename='tests/sounds/guitar1s.wav').remix(1) snd2 = SoundBuffer(filename='tests/sounds/LittleTikes-A1.wav') channels = max(snd1.channels, snd2.channels) out = snd1 & snd2 self.assertEqual(out.channels, channels) out = snd2 & snd1 self.assertEqual(out.channels, channels) snd2 &= snd1 self.assertEqual(snd2.channels, channels) self.assertEqual(snd1.channels, 1) # Right side should have no side effects snd1 &= snd2 self.assertEqual(snd1.channels, channels)
def test_pad_sound_with_silence(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') # Pad start original_length = len(sound) silence_length = random.triangular(0.001, 1) sound = sound.pad(silence_length) self.assertEqual(len(sound), int((sound.samplerate * silence_length) + original_length)) self.assertEqual(sound[0], (0,0)) # Pad end original_length = len(sound) silence_length = random.triangular(0.001, 1) sound = sound.pad(end=silence_length) self.assertEqual(len(sound), int((sound.samplerate * silence_length) + original_length)) self.assertEqual(sound[-1], (0,0))
def test_pulsed_graincloud(self): sound = SoundBuffer(filename='tests/sounds/guitar1s.wav') out = sound.cloud(10, grainlength=0.06, grid=0.12) out.write('tests/renders/graincloud_pulsed.wav')