Пример #1
0
 def test_againstMIR_testalt_sample_both(self):
     val = extractor.zcr(test_alt,
                         p='sample',
                         d='both',
                         decomposition=False)
     MIRVAL = 0.0243
     assert np.abs(val - MIRVAL) <= percentError * MIRVAL
Пример #2
0
 def test_againstLIBROSA_beethoven(self):
     my_val = extractor.zcr(beet, win_length=n_fft / sr, decomposition=True)
     lib_val = librosa.feature.zero_crossing_rate(y=beet,
                                                  frame_length=n_fft,
                                                  hop_length=n_fft / 2)
     corr = calculateZcorr(my_val, retrieveLibrosaValue(lib_val))
     assert corr >= 0.95  # assert 95% correlation b/w zscores
Пример #3
0
 def test_againstMIR_beethoven_sample_both(self):
     val = extractor.zcr(beet,
                         sr,
                         p='sample',
                         d='both',
                         decomposition=False)
     MIRVAL = 0.028678
     assert np.abs(val - MIRVAL) <= percentError * MIRVAL
Пример #4
0
    def zcr(self, use_librosa=False, decomposition=True, p='second', d='one',
            hop_length=None, n_fft=None):
        """
        Get the zero crossing rate feature.
        :parameters:
            - use_librosa : boolean. Whether to use librosa or extractor
                feature extraction function. Default False.
            - decomposition : boolean. Whether to look at a time-series or
                an overall root mean square analysis of the piece.
            - p : boolean. p='second' or p='sample'. Calculate zero crossing
                rate per these two units of time. Default is 'second'.
            - d : boolean. d='one' or d='both'. Calculate zero crossing rate
                from one direction or both directions of approach to x-axis.
                Default is 'one'
            - n_fft : integer. The window length [samples].
                Default 2048 [samples].
            - hop_length : float. Hop length (i.e. overlap) between the
                frames in the time series analysis [samples].
                Default is half-overlap.
            - n_fft : integer. The window length [samples]. For using with
                librosa. Default 2048 [samples].
        """

        if n_fft is None:
            n_fft = self.n_fft
        if hop_length is None:
            hop_length = int(n_fft / 2)

        if use_librosa:
            tmp = librosa.feature.zero_crossing_rate(self.audio,
                                    n_fft=n_fft, hop_length=hop_length)
            self.insertFeature(tmp, 'ZCR', hop_length, full=False)
            self.insertExtractionParameters('ZCR',
                                            dict(n_fft=n_fft, hop_length=hop_length,
											librosa=use_librosa, decomposition=True))
        else:
            tmp = extractor.zcr(self.audio, sr=self.sr, p=p,
                        d=d, n_fft=n_fft, hop_length=hop_length,
                        pad=self.pad, decomposition=decomposition)
            self.insertFeature(tmp, 'ZCR', hop_length, full=not decomposition)
            self.insertExtractionParameters('ZCR',
                                            dict(hop_length=hop_length,
											decomposition=decomposition, 
											n_fft=n_fft, per=p, direction=d,
											pad=self.pad, librosa=use_librosa))
        return tmp
Пример #5
0
 def test_againstMIR_testalt(self):
     val = extractor.zcr(test_alt, decomposition=False)
     MIRVAL = 536
     assert np.abs(val - MIRVAL) <= percentError * MIRVAL
Пример #6
0
 def test_againstMIR_beethoven(self):
     val = extractor.zcr(beet, decomposition=False)
     MIRVAL = 632.3395
     # within percent error of the MIR value
     assert np.abs(val - MIRVAL) <= percentError * MIRVAL
Пример #7
0
 def test_ones_and_minusones_sample_one(self):
     a = np.ones(10)
     a[1::2] = -1
     npt.assert_equal(extractor.zcr(a, p='sample', decomposition=False),
                      0.9 / 2)
Пример #8
0
 def test_ones_and_minusones_second_one(self):
     a = np.ones(10)
     a[1::2] = -1
     sr = 22050
     npt.assert_equal(extractor.zcr(a, sr=sr, decomposition=False),
                      0.9 * sr / 2)
Пример #9
0
 def test_ones_and_minusones_second_both(self):
     a = np.ones(10)
     a[1::2] = -1
     npt.assert_equal(extractor.zcr(a, sr=2, d='both', decomposition=False),
                      0.9 * 2)
Пример #10
0
 def test_ones(self):
     a = np.ones(10)
     npt.assert_equal(extractor.zcr(a, decomposition=False), 0.0)