Esempio n. 1
0
 def test_againstLIBROSA_testToySig3Pure(self):
     my_val = extractor.spectralSpread(signal3,
                                       win_length=n_fft / sr,
                                       decomposition=True)
     lib_val = librosa.feature.spectral_bandwidth(y=signal3,
                                                  n_fft=n_fft,
                                                  hop_length=n_fft / 2)
     corr = calculateZcorr(my_val, retrieveLibrosaValue(lib_val))
     assert corr >= 0.95  # assert 95% correlation b/w zscores
Esempio n. 2
0
    def spectralSpread(self, use_librosa=False, decomposition=True,
                       hop_length=None, n_fft=None):
        """
        Get spectral spread/bandwidth 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.
            - win_length : float. Window length for the frames in the
                time series analysis. [seconds]. Default is 0.05 s.
            - 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.spectral_bandwidth(y=self.audio,
                            sr=self.sr, n_fft=n_fft, hop_length=hop_length)
            self.insertFeature(tmp, 'spectralSpread', hop_length, full=False)
            self.insertExtractionParameters('spectralSpread',
                                            dict(hop_length=hop_length,
											n_fft=n_fft, librosa=use_librosa,
											decomposition=True))
        else:
            tmp = extractor.spectralSpread(self.audio,
                            sr=self.sr, n_fft=n_fft,
                            hop_length=hop_length, pad=self.pad,
                            decomposition=decomposition)
            self.insertFeature(tmp, 'spectralSpread', hop_length, full=not decomposition)
            self.insertExtractionParameters('spectralSpread',
                                            dict(hop_length=hop_length,
											n_fft=n_fft, librosa=use_librosa,
											decomposition=decomposition, pad=self.pad))
        return tmp
Esempio n. 3
0
 def test_againstMIR_test_alt(self):
     val = extractor.spectralSpread(test_alt, sr, decomposition=False)
     MIRVAL = 376.773
     assert np.abs(val - MIRVAL) <= 0.15 * MIRVAL
Esempio n. 4
0
 def test_againstMIR_beethoven(self):
     val = extractor.spectralSpread(beet, sr, decomposition=False)
     MIRVAL = 1359.8841
     assert np.abs(val - MIRVAL) <= 0.15 * MIRVAL