예제 #1
0
    def test_Pipe(self):
        """Test process pipe (Quick and dirty)"""
        # TODO clean up and complete

        source = samples["sweep.wav"]

        pipe = timeside.core.processor.ProcessPipe()
        dec = FileDecoder(source)
        pipe.append_processor(dec)
        self.assertRaises(TypeError, pipe.append_processor, object())
        dec2 = FileDecoder(source)
        self.assertRaises(ValueError, pipe.append_processor, dec2)

        odf = timeside.plugins.analyzer.odf.OnsetDetectionFunction()
        odf2 = timeside.plugins.analyzer.odf.OnsetDetectionFunction()

        spectro2 = timeside.plugins.analyzer.spectrogram.Spectrogram()
        pipe2 = (dec | odf | spectro2 | odf2)

        self.assertEqual(pipe2, odf.process_pipe)
        self.assertEqual(pipe2, odf2.process_pipe)
        self.assertEqual(pipe2, spectro2.process_pipe)

        self.assertEqual(len(pipe2.processors), 4)
        # Release temporary buffers in Spectrogram
        for proc in pipe2.processors:
            proc.release()
예제 #2
0
    def tearDown(self):
        decoder = FileDecoder(self.source)

        encoder_cls = get_processor(self.encoder_id)

        file_extension = '.' + encoder_cls.file_extension()

        self.target = tmp_file_sink(prefix=self.__class__.__name__,
                                    suffix=file_extension)
        encoder = encoder_cls(self.target)
        (decoder | encoder).run()

        decoder_encoded = FileDecoder(self.target)

        pipe = ProcessPipe(decoder_encoded)
        pipe.run()

        os.unlink(self.target)

        #print decoder.channels(), decoder.samplerate(), written_frames
        #print media_channels

        if self.test_channels:
            self.assertEqual(decoder.channels(), decoder_encoded.channels())
        else:
            self.assertEqual(2, decoder_encoded.channels())  # voaacenc bug ?

        self.assertEqual(decoder.samplerate(),
                         decoder_encoded.samplerate())

        if self.test_duration:
            self.assertAlmostEqual(decoder.input_duration,
                                   decoder_encoded.input_duration,
                                   delta=0.2)
예제 #3
0
    def tearDown(self):
        decoder = FileDecoder(uri=self.source, start=self.start, duration=self.duration)

        decoder.setup(samplerate=self.samplerate, channels=self.channels, blocksize=self.blocksize)

        totalframes = 0

        while True:
            frames, eod = decoder.process()
            totalframes += frames.shape[0]
            if eod or decoder.eod:
                break
            self.assertEqual(frames.shape[0], decoder.blocksize())
            self.assertEqual(frames.shape[1], decoder.channels())

        ratio = decoder.output_samplerate / decoder.input_samplerate
        if 0:
            print "input / output_samplerate:", decoder.input_samplerate, "/", decoder.output_samplerate,
            print "ratio:", ratio
            print "input / output_channels:", decoder.input_channels, decoder.output_channels
            print "input_duration:", decoder.input_duration
            print "input_totalframes:", decoder.input_totalframes
            print "mime_type", decoder.mime_type()

        if self.channels:
            # when specified, check that the channels are the ones requested
            self.assertEqual(self.channels, decoder.output_channels)
        else:
            # otherwise check that the channels are preserved, if not specified
            self.assertEqual(decoder.input_channels, decoder.output_channels)
            # and if we know the expected channels, check the output match
            if self.expected_channels:
                self.assertEqual(self.expected_channels, decoder.output_channels)
        # do the same with the sampling rate
        if self.samplerate:
            self.assertEqual(self.samplerate, decoder.output_samplerate)
        else:
            self.assertEqual(decoder.input_samplerate, decoder.output_samplerate)
            if self.expected_samplerate:
                self.assertEqual(self.expected_samplerate, decoder.output_samplerate)

        self.assertEqual(decoder.mime_type(), self.expected_mime_type)

        expected_totalframes = int(decoder.input_duration * decoder.output_samplerate)

        input_duration = decoder.input_totalframes / decoder.input_samplerate
        output_duration = decoder.totalframes() / decoder.output_samplerate
        if self.test_exact_duration:
            self.assertEqual(input_duration, output_duration)
            self.assertEqual(input_duration, decoder.uri_duration)
            self.assertEqual(self.source_duration, decoder.uri_duration)
            self.assertEqual(totalframes, expected_totalframes)

        else:
            self.assertAlmostEqual(input_duration, output_duration, places=1)
            self.assertAlmostEqual(input_duration, decoder.uri_duration, places=1)
            self.assertAlmostEqual(self.source_duration, decoder.uri_duration, places=1)
            self.assertAlmostEqual(totalframes, expected_totalframes, delta=69)
예제 #4
0
 def tearDown(self):
     decoder = FileDecoder(self.source)
     (decoder | self.analyzer).run()
     self.assertAlmostEqual(
         self.analyzer.results['vamp_tuning'].data_object.value,
         440.0,
         places=1)
예제 #5
0
    def testResults(self):
        "Test decoder stack: test frames content"

        decoder = FileDecoder(uri=self.source,
                              start=self.start,
                              duration=self.duration,
                              stack=True)
        level = Level()
        pipe = (decoder | level)

        pipe.run()

        self.assertIsInstance(pipe.frames_stack, list)

        results_on_file = level.results['level.rms'].data.copy()

        # If the pipe is used for a second run, the processed frames stored
        # in the stack are passed to the other processors
        # without decoding the audio source again.

        pipe.results = {}  # to be sure the previous results are deleted
        pipe.run()

        # to assert that the frames passed to the two analyzers are the same,
        # we check that the results of these analyzers are equivalent:
        results_on_stack = level.results['level.rms'].data

        self.assertEqual(results_on_stack, results_on_file)
예제 #6
0
 def tearDown(self):
     decoder = FileDecoder(self.source)
     (decoder | self.analyzer).run()
     results = self.analyzer.results
     for result_id in self.expected.keys():
         result = results[result_id]
         self.assertEqual(result.data_object.value,
                          self.expected[result_id])
예제 #7
0
 def tearDown(self):
     decoder = FileDecoder(self.source)
     (decoder | self.analyzer).run()
     results = self.analyzer.results
     #print results
     results.to_yaml()
     results.to_json()
     results.to_xml()
예제 #8
0
    def tearDown(self):
        decoder = FileDecoder(self.source)

        encoder_cls = get_processor(self.encoder_id)

        file_extension = '.' + encoder_cls.file_extension()

        self.target = tmp_file_sink(prefix=self.__class__.__name__,
                                    suffix=file_extension)
        encoder = encoder_cls(self.target)
        (decoder | encoder).run()

        decoder_encoded = FileDecoder(self.target)

        pipe = ProcessPipe(decoder_encoded)
        pipe.run()

        os.unlink(self.target)

        #print decoder.channels(), decoder.samplerate(), written_frames
        #print media_channels

        if self.test_channels:
            self.assertEqual(decoder.channels(), decoder_encoded.channels())
        else:
            self.assertEqual(2, decoder_encoded.channels())  # voaacenc bug ?

        self.assertEqual(decoder.samplerate(),
                         decoder_encoded.samplerate())

        if self.test_duration:
            self.assertAlmostEqual(decoder.input_duration,
                                   decoder_encoded.input_duration,
                                   delta=0.2)
예제 #9
0
    def tearDown(self):
        decoder = FileDecoder(self.source)
        encoder_cls = get_processor(self.encoder_id)

        file_extension = '.' + encoder_cls.file_extension()

        self.target_filesink = tmp_file_sink(prefix=self.__class__.__name__,
                                             suffix=file_extension)

        self.target_appsink = tmp_file_sink(prefix=self.__class__.__name__,
                                            suffix=file_extension)

        encoder = encoder_cls(self.target_filesink, streaming=True)
        pipe = (decoder | encoder)

        with open(self.target_appsink, 'w') as f:
            for chunk in pipe.stream():
                f.write(chunk)

        decoder_encoded = FileDecoder(self.target_filesink)

        pipe2 = ProcessPipe(decoder_encoded)
        pipe2.run()

        import os
        filesink_size = os.path.getsize(self.target_filesink)
        appsink_size = os.path.getsize(self.target_appsink)

        os.unlink(self.target_filesink)
        os.unlink(self.target_appsink)
        #print decoder.channels(), decoder.samplerate(), written_frames
        #print media_channels

        if self.test_channels:
            self.assertEqual(decoder.channels(), decoder_encoded.channels())
        else:
            self.assertEqual(2, decoder_encoded.channels())  # voaacenc bug ?

        if not self.expected_sample_rate:
            self.expected_sample_rate = decoder.samplerate()
        self.assertEqual(self.expected_sample_rate,
                         decoder_encoded.samplerate())

        if self.test_duration:
            self.assertAlmostEqual(decoder.input_duration,
                                   decoder_encoded.input_duration,
                                   delta=0.2)
        self.assertAlmostEqual(filesink_size,
                               appsink_size,
                               delta=self.filesize_delta)
예제 #10
0
    def testEmptyFile(self):
        "Test decoding empty file"
        import tempfile
        self.tmpfile = tempfile.NamedTemporaryFile(delete=True)
        self.source = self.tmpfile.name
        with self.assertRaises(IOError):
            FileDecoder(self.source)

        self.tmpfile.close()
예제 #11
0
 def tearDown(self):
     decoder = FileDecoder(self.source)
     (decoder | self.fx | self.level).run()
     results = self.level.results
     for result_id in self.expected.keys():
         result = results[result_id]
         self.assertAlmostEquals(result.data_object.value,
                                 self.expected[result_id],
                                 places=2)
예제 #12
0
 def tearDown(self):
     decoder = FileDecoder(self.source)
     (decoder | self.analyzer_dissonance
      | self.analyzer_dissonance_value).run()
     self.assertAlmostEqual(
         self.analyzer_dissonance.results['essentia_dissonance'].
         data_object.value.mean(),
         0.003,
         places=3)
     self.assertAlmostEqual(
         self.analyzer_dissonance_value.
         results['essentia_dissonance_value'].data_object.value,
         0.109,
         places=2)
    def tearDown(self):
        decoder = FileDecoder(self.source)
        encoder_cls = get_processor(self.encoder_id)

        file_extension = '.' + encoder_cls.file_extension()

        self.target_filesink = tmp_file_sink(prefix=self.__class__.__name__,
                                             suffix=file_extension)

        self.target_appsink = tmp_file_sink(prefix=self.__class__.__name__,
                                            suffix=file_extension)

        encoder = encoder_cls(self.target_filesink, streaming=True)
        pipe = (decoder | encoder)

        with open(self.target_appsink, 'w') as f:
            for chunk in pipe.stream():
                f.write(chunk)

        decoder_encoded = FileDecoder(self.target_filesink)

        pipe2 = ProcessPipe(decoder_encoded)
        pipe2.run()

        import os
        filesink_size = os.path.getsize(self.target_filesink)
        appsink_size = os.path.getsize(self.target_appsink)

        os.unlink(self.target_filesink)
        os.unlink(self.target_appsink)
        #print decoder.channels(), decoder.samplerate(), written_frames
        #print media_channels

        if self.test_channels:
            self.assertEqual(decoder.channels(), decoder_encoded.channels())
        else:
            self.assertEqual(2, decoder_encoded.channels())  # voaacenc bug ?

        if not self.expected_sample_rate:
            self.expected_sample_rate = decoder.samplerate()
        self.assertEqual(self.expected_sample_rate,
                         decoder_encoded.samplerate())

        if self.test_duration:
            self.assertAlmostEqual(decoder.input_duration,
                                   decoder_encoded.input_duration,
                                   delta=0.2)
        self.assertAlmostEqual(filesink_size, appsink_size,
                               delta=self.filesize_delta)
예제 #14
0
 def _perform_test(self, analyzer_cls, source_file):
     """Internal function that test if there is NaN in the results
     of a given analyzer"""
     decoder = FileDecoder(source_file)
     analyzer = analyzer_cls()
     pipe = (decoder | analyzer)
     pipe.run()
     for result in analyzer.results.values():
         if 'value' in result.data_object.keys():
             # Test for NaN
             self.assertFalse(np.any(np.isnan(result.data)),
                              'NaN in %s data value' % result.name)
             # Test for Inf
             self.assertFalse(np.any(np.isinf(result.data)),
                              'Inf in %s data value' % result.name)
     # Try to serialize as hdf5
     h5_file = tempfile.NamedTemporaryFile(suffix='.h5', delete=True)
     analyzer.results.to_hdf5(h5_file.name)
예제 #15
0
    def testProcess(self):
        "Test decoder stack: test process"
        decoder = FileDecoder(uri=self.source,
                              start=self.start,
                              duration=self.duration,
                              stack=True)
        self.assertTrue(decoder.stack)
        self.assertFalse(decoder.from_stack)

        pipe = ProcessPipe(decoder)

        pipe.run()

        self.assertFalse(decoder.stack)
        self.assertTrue(decoder.from_stack)

        self.assertEqual(len(pipe.frames_stack), 44)

        pipe.run()
예제 #16
0
    def setUp(self):
        source = samples["C4_scale.wav"]

        self.decoder = FileDecoder(source)
예제 #17
0
 def testNoAudioStream(self):
     "Test decoding file withouth audio stream"
     self.source = __file__
     with self.assertRaises(IOError):
         FileDecoder(self.source)
예제 #18
0
 def tearDown(self):
     decoder = FileDecoder(self.source)
     (decoder | self.analyzer).run()
     self.assertEqual(
         self.analyzer.results['vamp_constantq'].data_object.value.shape[1],
         48)
예제 #19
0
 def tearDown(self):
     decoder = FileDecoder(self.source)
     (decoder | self.grapher).run()
     self.grapher.render(self.image)
     self.assertGreater(os.path.getsize(self.image.name), 0)
     self.image.close()
예제 #20
0
    def tearDown(self):
        decoder = FileDecoder(uri=self.source,
                              start=self.start,
                              duration=self.duration)

        decoder.setup(samplerate=self.samplerate,
                      channels=self.channels,
                      blocksize=self.blocksize)

        totalframes = 0

        while True:
            frames, eod = decoder.process()
            totalframes += frames.shape[0]
            if eod or decoder.eod:
                break
            self.assertEqual(frames.shape[0], decoder.blocksize())
            self.assertEqual(frames.shape[1], decoder.channels())

        ratio = decoder.output_samplerate / decoder.input_samplerate
        if 0:
            print "input / output_samplerate:", decoder.input_samplerate, '/', decoder.output_samplerate,
            print "ratio:", ratio
            print "input / output_channels:", decoder.input_channels, decoder.output_channels
            print "input_duration:", decoder.input_duration
            print "input_totalframes:", decoder.input_totalframes
            print "mime_type", decoder.mime_type()

        if self.channels:
            # when specified, check that the channels are the ones requested
            self.assertEqual(self.channels, decoder.output_channels)
        else:
            # otherwise check that the channels are preserved, if not specified
            self.assertEqual(decoder.input_channels, decoder.output_channels)
            # and if we know the expected channels, check the output match
            if self.expected_channels:
                self.assertEqual(self.expected_channels,
                                 decoder.output_channels)
        # do the same with the sampling rate
        if self.samplerate:
            self.assertEqual(self.samplerate, decoder.output_samplerate)
        else:
            self.assertEqual(decoder.input_samplerate,
                             decoder.output_samplerate)
            if self.expected_samplerate:
                self.assertEqual(self.expected_samplerate,
                                 decoder.output_samplerate)

        self.assertEqual(decoder.mime_type(), self.expected_mime_type)

        expected_totalframes = int(decoder.input_duration *
                                   decoder.output_samplerate)

        input_duration = decoder.input_totalframes / decoder.input_samplerate
        output_duration = decoder.totalframes() / decoder.output_samplerate
        if self.test_exact_duration:
            self.assertEqual(input_duration, output_duration)
            self.assertEqual(input_duration, decoder.uri_duration)
            self.assertEqual(self.source_duration, decoder.uri_duration)
            self.assertEqual(totalframes, expected_totalframes)

        else:
            self.assertAlmostEqual(input_duration, output_duration, places=1)
            self.assertAlmostEqual(input_duration,
                                   decoder.uri_duration,
                                   places=1)
            self.assertAlmostEqual(self.source_duration,
                                   decoder.uri_duration,
                                   places=1)
            self.assertAlmostEqual(totalframes, expected_totalframes, delta=69)
예제 #21
0
 def tearDown(self):
     decoder = FileDecoder(self.source)
     decoder.output_samplerate = self.samplerate
     (decoder | self.analyzer).run()
     results = self.analyzer.results
     self.assertEquals(self.result_length, len(results))
예제 #22
0
 def test_bad_duration_value(self):
     "Test decoding segment with a too large duration value argument"
     decoder = FileDecoder(self.source, duration=10)
     pipe = ProcessPipe(decoder)
     self.assertRaises(ValueError, pipe.run)
예제 #23
0
class TestForceSampleRate(unittest.TestCase):

    class Dummy_Processor(Processor):
        implements(IProcessor)

        @staticmethod
        @interfacedoc
        def id():
            return 'dummy_proc'

    class Dummy_Processor_withSampleRate(Dummy_Processor):
        implements(IProcessor)

        @staticmethod
        @interfacedoc
        def id():
            return 'dummy_proc_samplerate'

        @property
        def force_samplerate(self):
            return SAMPLE_RATE_FORCED

    class Dummy_Processor_withSampleRate2(Dummy_Processor):
        implements(IProcessor)

        @staticmethod
        @interfacedoc
        def id():
            return 'dummy_proc_samplerate_2'

        @property
        def force_samplerate(self):
            return OTHER_SAMPLE_RATE

    def setUp(self):
        self.source = samples['sweep.wav']
        self.source_samplerate = 44100
        self.decoder = FileDecoder(uri=self.source)

    def testWithoutForceSampleRate(self):
        "Processor not overwritting source SampleRate"
        processor = self.Dummy_Processor()
        pipe = (self.decoder | processor)
        pipe.run()

    def testWithForceSampleRate(self):
        "Processor overwritting source SampleRate"
        processor = self.Dummy_Processor_withSampleRate()
        pipe = (self.decoder | processor)
        pipe.run()
        self.assertEqual(self.decoder.samplerate(), SAMPLE_RATE_FORCED)

    def testWithForceSampleRatePipe(self):
        "Processor overwritting pipe SampleRate"
        processor = self.Dummy_Processor_withSampleRate()
        pipe = (self.decoder | processor)
        self.assertRaises(ValueError, pipe.run, [],
                          {'samplerate': OTHER_SAMPLE_RATE})

    def testWithForceSampleRateTwoProc(self):
        "Two Processors overwritting source SampleRate"
        processor1 = self.Dummy_Processor_withSampleRate()
        processor2 = self.Dummy_Processor_withSampleRate2()

        pipe = (self.decoder | processor1 | processor2)
        self.assertRaises(ValueError, pipe.run)
예제 #24
0
 def tearDown(self):
     decoder = FileDecoder(self.source)
     (decoder | self.analyzer).run()
     self.assertEqual(self.analyzer.results['loudness_itu.block_loudness'].data_object.value.shape[0], 91)
     self.assertAlmostEqual(self.analyzer.results['loudness_itu.block_loudness'].data_object.value.mean(), -64.06, places=1)
예제 #25
0
 def testDevNull(self):
     "Test decoding dev null"
     self.source = "/dev/null"
     with self.assertRaises(IOError):
         FileDecoder(self.source)
예제 #26
0
 def tearDown(self):
     decoder = FileDecoder(self.source)
     (decoder | self.analyzer).run()
     results = self.analyzer.results
예제 #27
0
 def tearDown(self):
     decoder = FileDecoder(self.source)
     decoder.output_samplerate = self.samplerate
     (decoder | self.analyzer).run()
     results = self.analyzer.results
     self.assertEquals(self.result_length, len(results))
예제 #28
0
 def setUp(self):
     self.source = samples['sweep.wav']
     self.source_samplerate = 44100
     self.decoder = FileDecoder(uri=self.source)
예제 #29
0
 def test_bad_start_value(self):
     "Test decoding segment with start value exceeding the media duration"
     decoder = FileDecoder(self.source, start=10)
     pipe = ProcessPipe(decoder)
     self.assertRaises(ValueError, pipe.run)