class TestAudioFileReadMultiChannel(unittest.TestCase): def setUp(self): self.snd = AudioFile('audio/beat_5ch.wav') self.ref = self.snd._file.read(always_2d=True) def test_read_raw_multi(self): data = self.snd.read(norm=False, mono=False) self.assertTrue(np.array_equal(self.ref, data)) def test_read_raw_mono(self): ref = self.ref.sum(axis=1, keepdims=True) / self.ref.shape[1] data = self.snd.read(norm=False, mono=True) self.assertTrue(np.array_equal(ref, data)) def test_read_norm_multi(self): ref = self.ref / self.ref.max(axis=0, keepdims=True) data = self.snd.read(norm=True, mono=False) self.assertTrue(np.array_equal(ref, data)) def test_read_norm_mono(self): ref = self.ref.sum(axis=1, keepdims=True) / self.ref.shape[1] ref /= self.ref.max() data = self.snd.read(norm=True, mono=True) self.assertTrue(np.array_equal(ref, data)) def tearDown(self): self.snd.close()
def extract(self, path) -> pd.DataFrame: """Perform extraction. """ snd = AudioFile(path) if snd.fps != self.params.stft.fps: snd.close() raise ValueError('Sample rate of {snd!str} differs from init.') segs = self.cutter.transform(snd.data.squeeze()) sxx = self.stft.transform(segs) args = [(sxx.frqs, sxx.power), (sxx.frqs, sxx.power), (sxx.abs,), (sxx.d_frq, sxx.abs, 15000), (sxx.frqs, sxx.abs), (segs.data,), (segs.data,), (segs.data,)] kwargs = [{}, {}, {}, {}, {}, {}, self.params.corr_dim.to_dict(), self.params.corr_gram.to_dict()] out = np.zeros((segs.n_segs, self.n_features)) for i, (fun, arg, kwarg) in enumerate(zip(self.funcs, args, kwargs)): out[:, i] = self._worker(i, fun, arg, kwarg) snd.close() meta = TrackMeta(comsar.__version__, time_stamp(), snd.file_name) out = pd.DataFrame(data=out, columns=self.feature_names) return TrackResult(meta, self.params, out)
def setUp(self): self.snd = AudioFile('audio/beat.wav') self.osd = FluxOnsetDetector(self.snd.fps)
def setUp(self) -> None: self.snd = AudioFile('audio/beat_5ch.wav')
def setUp(self): self.snd = AudioFile('audio/beat.wav')
def setUp(self): self.snd = AudioFile('audio/beat_5ch.wav') self.ref = self.snd._file.read(always_2d=True)
def test_hash(self): snd2 = AudioFile('audio/beat.wav') self.assertEqual(self.snd.hash, snd2.hash)