def test_join_with_operator(self): sound = Sound.from_sinwave(440) a = Resampling(88200) b = Resampling(44100) resampled = b << a << sound self.assertEqual(resampled.samplerate, sound.samplerate) resampled = sound >> a >> b self.assertEqual(resampled.samplerate, sound.samplerate) resampled = sound >> a >> b self.assertEqual(resampled.samplerate, sound.samplerate) resampled = (a >> b) << sound self.assertEqual(resampled.samplerate, sound.samplerate) resampled = (b << a) << sound self.assertEqual(resampled.samplerate, sound.samplerate) resampled = sound >> (a >> b) self.assertEqual(resampled.samplerate, sound.samplerate) resampled = sound >> (b << a) self.assertEqual(resampled.samplerate, sound.samplerate) resampled = a << sound >> b self.assertEqual(resampled.samplerate, sound.samplerate)
def test_same_samplerate(self): sound = Sound.from_sinwave(440, samplerate=44100) resample_to_same_rate = Resampling(sound.samplerate).apply(sound) self.assertIs(resample_to_same_rate, sound) self.assertTrue((resample_to_same_rate.data == sound.data).all())
def test_then_method(self): sound = Sound.from_sinwave(440) in_ = LinearFadeIn() out = LinearFadeOut() self.assertEqual( in_.then(out).apply(sound), in_.apply(out.apply(sound)))
def test_join_class(self): sound = Sound.from_sinwave(440) in_ = LinearFadeIn() out = LinearFadeOut() self.assertEqual( in_.then(out).apply(sound), JoinedEffect(in_, out).apply(sound))
def test_not_implemented_mask_effect(self): sound = Sound.from_sinwave(440) effect = MaskEffect() with self.assertRaises(NotImplementedError): effect.apply(sound) with self.assertRaises(NotImplementedError): effect.gen_mask(1)
def test_twice_resampling(self): sound = Sound.from_sinwave(440, samplerate=44100) resampled = sound >> Resampling(48000) >> Resampling(sound.samplerate) self.assertEqual(resampled.samplerate, sound.samplerate) self.assertIsNot(resampled, sound) self.assertFalse((resampled.data == sound.data).all()) self.assertTrue(numpy.allclose(resampled.data, sound.data, atol=0.01))
def setUp(self): self.a = Sound.from_sinwave(100, duration=0.1, volume=1 / 3, samplerate=60000) self.b = Sound.from_sinwave(200, duration=0.1, volume=1 / 3, samplerate=60000) self.c = Sound.from_sinwave(300, duration=0.1, volume=1 / 3, samplerate=60000) self.ab = overlay(self.a, self.b) self.bc = overlay(self.b, self.c) self.abc = overlay(self.a, self.b, self.c)
def test_volume_invalid(self): sound = Sound.from_sinwave(440) with self.assertRaises(InvalidVolumeError) as cm: ChangeVolume(-0.1) self.assertEqual(cm.exception.volume, -0.1) with self.assertRaises(InvalidVolumeError) as cm: ChangeVolume(1.1) self.assertEqual(cm.exception.volume, 1.1)
def test_trim_between_invalid(self): sound = Sound.from_sinwave(440) with self.assertRaises(InvalidDurationError) as cm: Trim(start=0.6, end=0.5) self.assertAlmostEqual(cm.exception.duration, -0.1) with self.assertRaises(InvalidDurationError) as cm: Trim(start=0.5, end=0.5) self.assertAlmostEqual(cm.exception.duration, 0) trim = Trim(start=2) with self.assertRaises(InvalidDurationError) as cm: trim.apply(sound) self.assertAlmostEqual(cm.exception.duration, 0)
def test_volume(self): sound = Sound.from_sinwave(440) self.assertAlmostEqual(sound.volume, 1, places=4) sound = ChangeVolume(0.8).apply(sound) self.assertAlmostEqual(sound.volume, 0.8, places=4) sound = ChangeVolume(0.3).apply(sound) self.assertAlmostEqual(sound.volume, 0.3, places=4) sound = ChangeVolume(1.0).apply(sound) self.assertAlmostEqual(sound.volume, 1, places=4) self.assertIs(ChangeVolume(1.0).apply(sound), sound)