Ejemplo n.º 1
0
    def test_resampling(self):
        sound = Sound.from_array([-0.4, -0.2, 0.0, 0.2, 0.4], 5)

        self.assertEqual(
            Resampling(9).apply(sound),
            Sound.from_array([-0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4],
                             9))

        self.assertEqual(
            Resampling(3).apply(sound), Sound.from_array([-0.4, 0.0, 0.4], 3))
Ejemplo n.º 2
0
    def test_change_speed_minus(self):
        sound = Sound.from_array([-0.4, -0.2, 0.0, 0.2, 0.4], 5)

        self.assertEqual(
            ChangeSpeed(-5 / 9).apply(sound),
            Sound.from_array([0.4, 0.3, 0.2, 0.1, 0.0, -0.1, -0.2, -0.3, -0.4],
                             5))

        self.assertEqual(
            ChangeSpeed(-5 / 3).apply(sound),
            Sound.from_array([0.4, 0.0, -0.4], 5))
Ejemplo n.º 3
0
    def test_linear_fade_out(self):
        self.assertEqual(LinearFadeOut().apply(self.sound),
                         Sound.from_array([1.0, -0.75, 0.5, -0.25, 0.0], 1))

        self.assertEqual(
            LinearFadeOut(duration=2).apply(self.sound),
            Sound.from_array([1.0, -1.0, 1.0, -1.0, 0.0], 1))

        self.assertEqual(
            LinearFadeOut(duration=3).apply(self.sound),
            Sound.from_array([1.0, -1.0, 1.0, -0.5, 0.0], 1))
Ejemplo n.º 4
0
    def test_reverse_play(self):
        sound = Sound.from_array([-0.1, 0.0, 0.1, 0.2], 4)
        reverse = ReversePlay().apply(sound)

        self.assertEqual(reverse.samplerate, sound.samplerate)
        self.assertEqual(reverse.duration, sound.duration)
        self.assertEqual(tuple(reverse.data[:, 0]), (0.2, 0.1, 0.0, -0.1))

        self.assertEqual(sound >> ReversePlay() >> ReversePlay(), sound)
Ejemplo n.º 5
0
    def test_trim_between_by_end(self):
        sound = Sound.from_array([[0.0, 0.3], [0.1, 0.4], [0.2, 0.5]], 3)

        self.assertEqual(sound.duration, 1)
        self.assertEqual(sound.n_channels, 2)
        self.assertEqual(tuple(sound.data[:, 0]), (0.0, 0.1, 0.2))
        self.assertEqual(tuple(sound.data[:, 1]), (0.3, 0.4, 0.5))

        sound = Trim(start=-2 / 3, end=-1 / 3).apply(sound)

        self.assertEqual(sound.duration, 1 / 3)
        self.assertEqual(sound.n_channels, 2)
        self.assertEqual(tuple(sound.data[:, 0]), (0.1, ))
        self.assertEqual(tuple(sound.data[:, 1]), (0.4, ))
Ejemplo n.º 6
0
    def test_trim_head(self):
        sound = Sound.from_array([[0.0, 0.3], [0.1, 0.4], [0.2, 0.5]], 3)

        self.assertEqual(sound.duration, 1)
        self.assertEqual(sound.n_channels, 2)
        self.assertEqual(tuple(sound.data[:, 0]), (0.0, 0.1, 0.2))
        self.assertEqual(tuple(sound.data[:, 1]), (0.3, 0.4, 0.5))

        sound = Trim(end=2 / 3).apply(sound)

        self.assertEqual(sound.duration, 2 / 3)
        self.assertEqual(sound.n_channels, 2)
        self.assertEqual(tuple(sound.data[:, 0]), (0.0, 0.1))
        self.assertEqual(tuple(sound.data[:, 1]), (0.3, 0.4))

        sound = Trim(end=1 / 3).apply(sound)

        self.assertEqual(sound.duration, 1 / 3)
        self.assertEqual(sound.n_channels, 2)
        self.assertEqual(tuple(sound.data[:, 0]), (0.0, ))
        self.assertEqual(tuple(sound.data[:, 1]), (0.3, ))
Ejemplo n.º 7
0
 def setUp(self):
     self.sound = Sound.from_array([1, -1, 1, -1, 1], 1)