示例#1
0
    def testSingle(self):
        gen = VectorInput(array([(0.9, 0.5)]))
        chGen = VectorInput([2])
        mixer = MonoMixer(type='mix')
        pool = Pool()

        gen.data >> mixer.audio
        mixer.audio >> (pool, "mix")
        chGen.data >> mixer.numberChannels
        chGen.push('data', 2)
        run(gen)
        self.assertAlmostEqual(sum(pool['mix']), (0.9 + 0.5) * 0.5)
示例#2
0
    def testMix(self):
        gen = VectorInput(self.clickTrack())
        chGen = VectorInput([2])
        mixer = MonoMixer(type='mix')
        pool = Pool()

        gen.data >> mixer.audio
        mixer.audio >> (pool, "mix")
        chGen.data >> mixer.numberChannels
        chGen.push('data', 2)
        run(gen)
        self.assertEqual(sum(pool['mix']), 19 * 0.5)
示例#3
0
    def testRight(self):
        gen = VectorInput(self.clickTrack())
        chGen = VectorInput([2])
        mixer = MonoMixer(type='right')
        pool = Pool()

        gen.data >> mixer.audio
        mixer.audio >> (pool, "mix")
        chGen.data >> mixer.numberChannels
        chGen.push('data', 2)
        run(gen)
        self.assertEqualVector(pool['mix'], self.right)
示例#4
0
    def testEmpty(self):
        inputFilename = join(testdata.audio_dir, 'generated', 'empty',
                             'empty.wav')
        loader = AudioLoader(filename=inputFilename)
        mixer = MonoMixer(type='left')
        pool = Pool()

        loader.audio >> mixer.audio
        mixer.audio >> (pool, "mix")
        loader.numberChannels >> mixer.numberChannels
        loader.sampleRate >> None
        run(loader)
        self.assertEqualVector(pool.descriptorNames(), [])
    def testEmpty(self):
        inputFilename = join(testdata.audio_dir, 'generated', 'empty',
                             'empty.aiff')
        # NOTE: AudioLoader will through exception on "empty.wav" complaining that
        # it cannot read stream info, using "empty.aiff" therefore...
        loader = AudioLoader(filename=inputFilename)
        mixer = MonoMixer(type='left')
        pool = Pool()

        loader.audio >> mixer.audio
        mixer.audio >> (pool, "mix")
        loader.numberChannels >> mixer.numberChannels
        loader.sampleRate >> None
        loader.md5 >> None
        run(loader)
        self.assertEqualVector(pool.descriptorNames(), [])
    def encoderTest(self, filename, bitrate=320, precision=1e-7):
        from math import sin, pi
        format = os.path.splitext(filename)[1].split('.')[1]
        sr = 44100
        sine = [i / 44100. * sin(2.0 * pi * 10.0 * i / sr) for i in range(sr)]
        #sine = [0.5*sin(2.0*pi*10.0*i/sr) for i in xrange(sr)]
        signal = array([[val, val] for val in sine])

        # write the audio file:
        gen = VectorInput(signal)
        writer = AudioWriter(filename=filename, format=format, bitrate=bitrate)
        gen.data >> writer.audio
        run(gen)

        # load the audio file and validate:
        loader = AudioLoader(filename=filename)
        mixer = MonoMixer(type='left')
        pool = Pool()
        loader.audio >> mixer.audio
        mixer.audio >> (pool, 'audio')
        loader.numberChannels >> mixer.numberChannels
        loader.sampleRate >> None
        loader.md5 >> None
        loader.bit_rate >> None
        loader.codec >> None
        run(loader)

        from essentia.standard import ZeroCrossingRate
        zcr = int(
            ZeroCrossingRate(threshold=0.001)(pool['audio']) *
            len(pool['audio']) + 0.5)
        expected = int(ZeroCrossingRate(threshold=0.0)(sine) * len(sine) + 0.5)
        # for debugging:
        #from pylab import show, plot, figure
        #from essentia.standard import MonoLoader
        #plot(sine)
        #plot(MonoLoader(filename=filename)())
        #show(figure)

        os.remove(filename)

        self.assertAlmostEqual(max(pool['audio']), max(sine), precision)
        self.assertEqual(
            zcr, expected)  # expected should be 20 (double the frequency)
示例#7
0
 def testInvalidParam(self):
     self.assertConfigureFails(MonoMixer(), {'type': 'unknown'})