def start_end_test(self): frame_rate, reference_samples = sp_wavfile.read(A440_MONO_16B) samples, infos = block_functions.read_wav(A440_MONO_16B, start=0.002, end=0.004) self.assertEqual(infos['frame_rate'], 44100) self.assertEqual(infos['channel_count'], 1) self.assertEqual(samples.shape, (88, 1)) expected = numpy.array([ reference_samples[0.002 * 44100:0.004 * 44100] / float(2**15) ]).transpose() numpy.testing.assert_array_equal(expected.round(4), samples.round(4)) samples, infos = block_functions.read_wav(A440_MONO_16B, start=0.002) self.assertEqual(samples.shape, (441 - 88, 1)) expected = numpy.array( [reference_samples[0.002 * 44100:] / float(2**15)]).transpose() numpy.testing.assert_array_equal(expected.round(4), samples.round(4)) samples, infos = block_functions.read_wav(A440_MONO_16B, end=0.002) self.assertEqual(samples.shape, (88, 1)) expected = numpy.array( [reference_samples[:0.002 * 44100] / float(2**15)]).transpose() numpy.testing.assert_array_equal(expected.round(4), samples.round(4))
def simple_file_test(self): samples, infos = block_functions.read_wav(STEPS_STEREO_16B) self.assertEqual(samples.shape, (92610, 2)) self.assertEqual(infos['frame_rate'], 44100) self.assertEqual(infos['channel_count'], 2) # Sanity check frame_rate, samples_test = sp_wavfile.read(open(STEPS_STEREO_16B, 'r')) numpy.testing.assert_array_equal(samples[:10,:].round(4), (samples_test[:10,:] / float(2**15)).round(4))
def start_end_test(self): frame_rate, reference_samples = sp_wavfile.read(A440_MONO_16B) samples, infos = block_functions.read_wav(A440_MONO_16B, start=0.002, end=0.004) self.assertEqual(infos['frame_rate'], 44100) self.assertEqual(infos['channel_count'], 1) self.assertEqual(samples.shape, (88, 1)) expected = numpy.array([reference_samples[0.002*44100:0.004*44100] / float(2**15)]).transpose() numpy.testing.assert_array_equal(expected.round(4), samples.round(4)) samples, infos = block_functions.read_wav(A440_MONO_16B, start=0.002) self.assertEqual(samples.shape, (441 - 88, 1)) expected = numpy.array([reference_samples[0.002*44100:] / float(2**15)]).transpose() numpy.testing.assert_array_equal(expected.round(4), samples.round(4)) samples, infos = block_functions.read_wav(A440_MONO_16B, end=0.002) self.assertEqual(samples.shape, (88, 1)) expected = numpy.array([reference_samples[:0.002*44100] / float(2**15)]).transpose() numpy.testing.assert_array_equal(expected.round(4), samples.round(4))
def simple_file_test(self): samples, infos = block_functions.read_wav(STEPS_STEREO_16B) self.assertEqual(samples.shape, (92610, 2)) self.assertEqual(infos['frame_rate'], 44100) self.assertEqual(infos['channel_count'], 2) # Sanity check frame_rate, samples_test = sp_wavfile.read(open(STEPS_STEREO_16B, 'r')) numpy.testing.assert_array_equal(samples[:10, :].round(4), (samples_test[:10, :] / float(2**15)).round(4))
def empty_read_test(self): samples, infos = block_functions.read_wav(A440_MONO_16B, start=0, end=0) self.assertEqual(samples.shape, (0, 1))
def start_is_after_eof_test(self): samples, infos = block_functions.read_wav(A440_MONO_16B, start=1000) self.assertEqual(samples.shape, (0, 1))
def read_after_eof_test(self): samples, infos = block_functions.read_wav(A440_MONO_16B, start=0.002, end=1000) self.assertEqual(samples.shape, (441 - 88, 1))