예제 #1
0
    def seek_test(self):
        config.block_size = 441
        blocks = stream.read_wav(STEPS_MONO_16B, start=1.1, end=1.4)

        self.assertEqual(blocks.infos['frame_rate'], 44100)
        self.assertEqual(blocks.infos['channel_count'], 1)

        expected = numpy.ones([441, 1]) * 0.1
        samples = next(blocks)
        numpy.testing.assert_array_equal(expected.round(3), samples.round(3))

        blocks.seek(1.3)
        expected = numpy.ones([441, 1]) * 0.3
        samples = next(blocks)
        numpy.testing.assert_array_equal(expected.round(3), samples.round(3))

        blocks.seek(1.3)
        expected = numpy.ones([441, 1]) * 0.3
        samples = next(blocks)
        numpy.testing.assert_array_equal(expected.round(3), samples.round(3))

        blocks.seek(0)
        expected = numpy.ones([441, 1]) * -1
        samples = next(blocks)
        numpy.testing.assert_array_equal(expected.round(3), samples.round(3))
예제 #2
0
    def blocks_size_test(self):
        config.block_size = 50
        blocks = stream.read_wav(A440_STEREO_16B)
        self.assertEqual(blocks.infos['frame_rate'], 44100)
        self.assertEqual(blocks.infos['channel_count'], 2)

        blocks = list(blocks)
        self.assertEqual([len(b) for b in blocks], [50, 50, 50, 50, 50, 50, 50, 50, 41])
        self.assertEqual(blocks[0].shape, (50, 2))

        actual = numpy.concatenate(blocks)
        frame_rate, expected = sp_wavfile.read(A440_STEREO_16B)
        expected = expected / float(2**15)
        numpy.testing.assert_array_equal(expected.round(4), actual.round(4))
예제 #3
0
    def last_block_too_small_test(self):
        """
        Ommit end, not an exact count of block_size.
        """
        config.block_size = 20
        blocks = stream.read_wav(A440_MONO_16B, start=0.002)
        self.assertEqual(blocks.infos['frame_rate'], 44100)
        self.assertEqual(blocks.infos['channel_count'], 1)

        blocks = list(blocks)
        self.assertEqual([len(b) for b in blocks], [20] * 17 + [13])
        self.assertEqual(blocks[0].shape, (20, 1))

        actual = numpy.concatenate(blocks)
        frame_rate, expected = sp_wavfile.read(A440_MONO_16B)
        expected = numpy.array([expected[0.002*44100:] / float(2**15)]).transpose()
        numpy.testing.assert_array_equal(expected.round(4), actual.round(4))
예제 #4
0
    def block_size_bigger_than_slice_to_read_test(self):
        """
        Read only a segment of the file, block_size bigger than segment to read.
        """
        config.block_size = 1000
        blocks = stream.read_wav(A440_MONO_16B, start=0.002, end=0.004)
        self.assertEqual(blocks.infos['frame_rate'], 44100)
        self.assertEqual(blocks.infos['channel_count'], 1)

        blocks = list(blocks)
        self.assertEqual(len(blocks), 1)
        self.assertEqual(blocks[0].shape, (88, 1))

        actual = numpy.concatenate(blocks)
        frame_rate, expected = sp_wavfile.read(A440_MONO_16B)
        expected = numpy.array([expected[0.002*44100:0.004*44100] / float(2**15)]).transpose()
        numpy.testing.assert_array_equal(expected.round(4), actual.round(4))