Mercurial > hg > auditok
diff tests/test_io.py @ 129:fb31a7250402
Add tests for _load_wave with channel selection
author | Amine Sehili <amine.sehili@gmail.com> |
---|---|
date | Thu, 07 Feb 2019 20:26:33 +0100 |
parents | 3594fdb0703d |
children | 7c5f325dae7a |
line wrap: on
line diff
--- a/tests/test_io.py Wed Feb 06 20:28:31 2019 +0100 +++ b/tests/test_io.py Thu Feb 07 20:26:33 2019 +0100 @@ -17,6 +17,7 @@ _mix_audio_channels, _extract_selected_channel, _load_raw, + _load_wave, from_file, _save_raw, _save_wave, @@ -441,6 +442,32 @@ _load_raw("audio", srate, swidth, channels) @genty_dataset( + dafault_first_channel=(None, 400), + first_channel=(0, 400), + second_channel=(1, 800), + third_channel=(2, 1600), + negative_first_channel=(-3, 400), + negative_second_channel=(-2, 800), + negative_third_channel=(-1, 1600), + ) + def test_load_wave(self, use_channel, frequency): + filename = "tests/data/test_16KHZ_3channel_400-800-1600Hz.wav" + if use_channel is not None: + audio_source = _load_wave(filename, use_channel=use_channel) + else: + audio_source = _load_wave(filename) + self.assertIsInstance(audio_source, BufferAudioSource) + self.assertEqual(audio_source.sampling_rate, 16000) + self.assertEqual(audio_source.sample_width, 2) + self.assertEqual(audio_source.channels, 1) + # generate a pure sine wave tone of the given frequency + expected = PURE_TONE_DICT[frequency] + # compre with data read from file + fmt = DATA_FORMAT[2] + data = array(fmt, audio_source._buffer) + self.assertEqual(data, expected) + + @genty_dataset( mono=("mono_400Hz.wav", (400,)), three_channel=("3channel_400-800-1600Hz.wav", (400, 800, 1600)), )