Example #1
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)
Example #2
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()
Example #3
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)
Example #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)
    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)
Example #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])
Example #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()
Example #8
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)
Example #9
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()
Example #10
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 _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)
Example #12
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()
    def setUp(self):
        source = samples["C4_scale.wav"]

        self.decoder = FileDecoder(source)
Example #14
0
 def testDevNull(self):
     "Test decoding dev null"
     self.source = "/dev/null"
     with self.assertRaises(IOError):
         FileDecoder(self.source)
 def tearDown(self):
     decoder = FileDecoder(self.source)
     (decoder | self.analyzer).run()
     self.assertEqual(
         self.analyzer.results['vamp_constantq'].data_object.value.shape[1],
         48)
Example #16
0
 def testNoAudioStream(self):
     "Test decoding file withouth audio stream"
     self.source = __file__
     with self.assertRaises(IOError):
         FileDecoder(self.source)
Example #17
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)
Example #18
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)
Example #19
0
 def tearDown(self):
     decoder = FileDecoder(self.source)
     (decoder | self.analyzer).run()
     results = self.analyzer.results
Example #20
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)
Example #21
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()
Example #22
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))
 def setUp(self):
     self.source = samples['sweep.wav']
     self.source_samplerate = 44100
     self.decoder = FileDecoder(uri=self.source)
Example #24
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)