Exemple #1
0
    def _test_all_samples_flushed(self, case, duration):
        """Test all samples are outputted by onset slicer"""
        pipeline = Pipeline([
            AubioFileLoader(os.path.join(SOUND_DIR, case))
        ])

        results = pipeline.run()

        frame_durs = collections.defaultdict(int)
        for res in results:
            frame = res["frame"]
            self.assertEqual(frame.samples.shape[0], frame.duration)
            frame_durs[frame.channel] += frame.samples.shape[0]

        self.assertEqual(frame_durs[0], duration)
        self.assertEqual(frame_durs[1], duration)

        onset_slicer = AubioOnsetSlicer()

        pipeline = Pipeline([
            AubioFileLoader(os.path.join(SOUND_DIR, case)),
            onset_slicer
        ])

        results = pipeline.run()

        onset_durs = collections.defaultdict(int)
        for res in results:
            frame = res["frame"]
            self.assertEqual(frame.samples.shape[0], frame.duration)
            onset_durs[frame.channel] += frame.samples.shape[0]

        self.assertEqual(onset_durs[0], frame_durs[0])
        self.assertEqual(onset_durs[1], frame_durs[1])
Exemple #2
0
    def _test_iter_amount(self, name, num):
        path = os.path.join(SOUND_DIR, name)
        mediafile = add_mediafile(self.session, path, segmentation="beats")

        pipeline = Pipeline([UnitGenerator(mediafile, self.session), list])

        results = pipeline.run()
        self.assertEqual(len(results), num)
Exemple #3
0
    def test_channels_zero_indexed(self):
        """Test channels are zero indexed"""
        path = os.path.join(SOUND_DIR, "amen-stereo.wav")

        pipeline = Pipeline([self.FileLoader(path, hopsize=1024)])
        results = pipeline.run()

        channels = set([res["frame"].channel for res in results])
        self.assertEqual(channels, set([0, 1]))
Exemple #4
0
    def test_channels_zero_indexed(self):
        """Test channels are zero indexed"""
        path = os.path.join(SOUND_DIR, "amen-stereo.wav")

        pipeline = Pipeline([self.FileLoader(path, hopsize=1024)])
        results = pipeline.run()

        channels = set([res["frame"].channel for res in results])
        self.assertEqual(channels, set([0, 1]))
Exemple #5
0
    def test_duration_equal_samples_length(self):
        """Test duration is always equal to length of samples array"""
        path = os.path.join(SOUND_DIR, "cant_let_you_use_me.wav")

        pipeline = Pipeline([self.FileLoader(path)])
        results = pipeline.run()

        for res in results:
            frame = res["frame"]
            self.assertEqual(frame.duration, frame.samples.shape[0])
Exemple #6
0
    def test_duration_equal_samples_length(self):
        """Test duration is always equal to length of samples array"""
        path = os.path.join(SOUND_DIR, "cant_let_you_use_me.wav")

        pipeline = Pipeline([self.FileLoader(path)])
        results = pipeline.run()

        for res in results:
            frame = res["frame"]
            self.assertEqual(frame.duration, frame.samples.shape[0])
Exemple #7
0
    def _test_iter_amount(self, name, num):
        path = os.path.join(SOUND_DIR, name)
        mediafile = add_mediafile(self.session, path, segmentation="beats")

        pipeline = Pipeline([
            UnitGenerator(mediafile, self.session),
            list
        ])

        results = pipeline.run()
        self.assertEqual(len(results), num)
Exemple #8
0
    def test_concatenate_file(self):
        path = os.path.join(SOUND_DIR, "hot_tamales.wav")
        mediafile = add_mediafile(self.session, path, segmentation="beats")
        self.session.flush()

        concatenate = concatenator("clip", mediafile)

        pipeline = Pipeline([
            UnitGenerator(mediafile, self.session),
            UnitLoader(key=lambda state: state["unit"].mediafile.path),
            concatenate, list
        ])

        mediafile = pipeline.run()
    def test_concatenate_file(self):
        path = os.path.join(SOUND_DIR, "hot_tamales.wav")
        mediafile = add_mediafile(self.session, path, segmentation="beats")
        self.session.flush()

        concatenate = concatenator("clip", mediafile)

        pipeline = Pipeline([
            UnitGenerator(mediafile, self.session),
            UnitLoader(key=lambda state: state["unit"].mediafile.path),
            concatenate,
            list
        ])

        mediafile = pipeline.run()
Exemple #10
0
    def test_iterframes_in_order(self):
        path = os.path.join(SOUND_DIR, "amen-mono.wav")

        pipeline = Pipeline([self.FileLoader(path, hopsize=1024), list])

        result = pipeline.run()
        self.assertEqual(len(result), 69)

        previous = 0
        for pool in result:
            frame = pool["frame"]
            self.assertTrue(previous <= frame.index)
            self.assertEqual(frame.samplerate, 44100)
            previous = frame.index

        self.assertEqual(previous, 68)
Exemple #11
0
    def test_slice(self):
        path = os.path.join(SOUND_DIR, "amen-mono.wav")

        pipeline = Pipeline([
            FileLoader(path, hopsize=512),
            BeatSlicer(bpm=150, interval="1/16"),
            list
        ])

        results = pipeline.run()

        positions = [pool["frame"].position for pool in results]
        self.assertEqual(positions, [
            0, 4410, 8820, 13230, 17640, 22050, 26460, 30870, 35280, 39690,
            44100, 48510, 52920, 57330, 61740, 66150
        ])
Exemple #12
0
    def test_read_whole_file(self):
        bufsize = 1024
        path = os.path.join(SOUND_DIR, "amen-stereo.wav")
        unit = Unit(channel=0, position=0, duration=70560)

        self.assertEqual(unit.duration, 70560)
        self.assertEqual(unit.channel, 0)
        self.assertEqual(unit.position, 0)

        pipeline = Pipeline([self.UnitLoader(hopsize=bufsize), list])

        result = pipeline.run({"path": path, "unit": unit})

        self.assertEqual(len(result), 1)
        samples = result[0]["frame"].samples

        self.assertEqual(samples.shape, (70560, ))
        self.assertNotEqual(numpy.sum(samples), 0)
Exemple #13
0
    def _onset_test(self, path, channels, expected_onsets, expected_duration):
        path = os.path.join(SOUND_DIR, path)

        pipeline = Pipeline([
            AubioFileLoader(path, hopsize=1024),
            AubioOnsetSlicer(winsize=1024, threshold=0, method="default"), list
        ])

        result = pipeline.run()
        self.assertEqual(len(result) / channels, expected_onsets)

        for i in range(channels):
            pos = -(i + 1)
            self.assertEqual(
                expected_duration,
                result[pos]["frame"].position + result[pos]["frame"].duration)

        return result
Exemple #14
0
    def test_same_as_aubioonset(self):
        """Deteted onsets should be similar to those detected by aubioonset"""
        bufsize = 512
        hopsize = 256

        pipeline = Pipeline([
            AubioFileLoader(os.path.join(SOUND_DIR, "amen-mono.wav"),
                            hopsize=hopsize),
            AubioOnsetSlicer(winsize=bufsize,
                             hopsize=hopsize,
                             method="default"), list
        ])

        results = pipeline.run()

        # values from aubioonset & aubio/demos/demo_onset.py
        self.assertEqual(
            map(lambda r: r["frame"].position, results),
            [0, 8657, 17410, 26321, 30819, 35069, 39755, 43934, 52727, 61561])
Exemple #15
0
    def test_iterframes_in_order(self):
        path = os.path.join(SOUND_DIR, "amen-mono.wav")

        pipeline = Pipeline([
            self.FileLoader(path, hopsize=1024),
            list
        ])

        result = pipeline.run()
        self.assertEqual(len(result), 69)

        previous = 0
        for pool in result:
            frame = pool["frame"]
            self.assertTrue(previous <= frame.index)
            self.assertEqual(frame.samplerate, 44100)
            previous = frame.index

        self.assertEqual(previous, 68)
Exemple #16
0
    def test_read_whole_file(self):
        bufsize = 1024
        path = os.path.join(SOUND_DIR, "amen-stereo.wav")
        unit = Unit(channel=0, position=0, duration=70560)

        self.assertEqual(unit.duration, 70560)
        self.assertEqual(unit.channel, 0)
        self.assertEqual(unit.position, 0)

        pipeline = Pipeline([
            self.UnitLoader(hopsize=bufsize),
            list
        ])

        result = pipeline.run({"path": path, "unit": unit})

        self.assertEqual(len(result), 1)
        samples = result[0]["frame"].samples

        self.assertEqual(samples.shape, (70560,))
        self.assertNotEqual(numpy.sum(samples), 0)
Exemple #17
0
    def test_same_as_aubioonset(self):
        """Deteted onsets should be similar to those detected by aubioonset"""
        bufsize = 512
        hopsize = 256

        pipeline = Pipeline([
            AubioFileLoader(
                os.path.join(SOUND_DIR, "amen-mono.wav"),
                hopsize=hopsize),
            AubioOnsetSlicer(
                winsize=bufsize,
                hopsize=hopsize,
                method="default"),
            list
        ])

        results = pipeline.run()

        # values from aubioonset & aubio/demos/demo_onset.py
        self.assertEqual(map(lambda r: r["frame"].position, results), [
            0, 8657, 17410, 26321, 30819, 35069, 39755, 43934, 52727, 61561
        ])
Exemple #18
0
    def _onset_test(self, path, channels, expected_onsets, expected_duration):
        path = os.path.join(SOUND_DIR, path)

        pipeline = Pipeline([
            AubioFileLoader(path, hopsize=1024),
            AubioOnsetSlicer(
                winsize=1024,
                threshold=0,
                method="default"),
            list
        ])

        result = pipeline.run()
        self.assertEqual(len(result) / channels, expected_onsets)

        for i in range(channels):
            pos = -(i + 1)
            self.assertEqual(
                expected_duration,
                result[pos]["frame"].position + result[pos]["frame"].duration)

        return result
Exemple #19
0
    def test_multiple_reads(self):
        reads = 10
        bufsize = 1024
        path = os.path.join(SOUND_DIR, "amen-stereo.wav")
        unit = Unit(channel=0, position=0, duration=70560)

        self.assertEqual(unit.duration, 70560)
        self.assertEqual(unit.channel, 0)
        self.assertEqual(unit.position, 0)

        loader = self.UnitLoader(hopsize=bufsize)

        for index in range(reads):
            pipeline = Pipeline([loader, list])
            result = pipeline.run({"path": path, "unit": unit})

            self.assertEqual(len(result), 1)
            samples = result[0]["frame"].samples

            self.assertEqual(samples.shape, (70560, ))
            self.assertNotEqual(numpy.sum(samples), 0)

        self.assertEqual(index, reads - 1)
Exemple #20
0
    def test_multiple_reads(self):
        reads = 10
        bufsize = 1024
        path = os.path.join(SOUND_DIR, "amen-stereo.wav")
        unit = Unit(channel=0, position=0, duration=70560)

        self.assertEqual(unit.duration, 70560)
        self.assertEqual(unit.channel, 0)
        self.assertEqual(unit.position, 0)

        loader = self.UnitLoader(hopsize=bufsize)

        for index in range(reads):
            pipeline = Pipeline([loader, list])
            result = pipeline.run({"path": path, "unit": unit})

            self.assertEqual(len(result), 1)
            samples = result[0]["frame"].samples

            self.assertEqual(samples.shape, (70560,))
            self.assertNotEqual(numpy.sum(samples), 0)

        self.assertEqual(index, reads - 1)