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_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 _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): 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_split_buffer(self): sound = SoundBuffer('tests/sounds/guitar1s.wav') length = random.randint(1, len(sound)) lengths = [] for grain in sound.grains(length): lengths += [ len(grain) ] # 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 lengths[:-1]: self.assertEqual(grain_length, length) # Check that the remainder grain is the correct length self.assertEqual(lengths[-1], len(sound) - sum(lengths[:-1])) # Check that all the grains add up self.assertEqual(sum(lengths), len(sound))