예제 #1
0
    def __test(scale, n_fmt, over_sample, kind, y_orig, y_res, atol):

        # Make sure our signals preserve energy
        assert np.allclose(np.sum(y_orig**2), np.sum(y_res**2))

        # Scale-transform the original
        f_orig = librosa.fmt(y_orig,
                             t_min=0.5,
                             n_fmt=n_fmt,
                             over_sample=over_sample,
                             kind=kind)

        # Force to the same length
        n_fmt_res = 2 * len(f_orig) - 2

        # Scale-transform the new signal to match
        f_res = librosa.fmt(y_res,
                            t_min=scale * 0.5,
                            n_fmt=n_fmt_res,
                            over_sample=over_sample,
                            kind=kind)

        # Due to sampling alignment, we'll get some phase deviation here
        # The shape of the spectrum should be approximately preserved though.
        assert np.allclose(np.abs(f_orig), np.abs(f_res), atol=atol, rtol=1e-7)
예제 #2
0
    def __test(scale, n_fmt, over_sample, kind, y_orig, y_res, atol):

        # Make sure our signals preserve energy
        assert np.allclose(np.sum(y_orig**2), np.sum(y_res**2))

        # Scale-transform the original
        f_orig = librosa.fmt(y_orig,
                             t_min=0.5,
                             n_fmt=n_fmt,
                             over_sample=over_sample,
                             kind=kind)

        # Force to the same length
        n_fmt_res = 2 * len(f_orig) - 2

        # Scale-transform the new signal to match
        f_res = librosa.fmt(y_res,
                            t_min=scale * 0.5,
                            n_fmt=n_fmt_res,
                            over_sample=over_sample,
                            kind=kind)

        # Due to sampling alignment, we'll get some phase deviation here
        # The shape of the spectrum should be approximately preserved though.
        assert np.allclose(np.abs(f_orig), np.abs(f_res), atol=atol, rtol=1e-7)
예제 #3
0
def test_fmt_axis():

    y = np.random.randn(32, 32)

    f1 = librosa.fmt(y, axis=-1)
    f2 = librosa.fmt(y.T, axis=0).T

    assert np.allclose(f1, f2)
예제 #4
0
def test_fmt_axis():

    y = np.random.randn(32, 32)

    f1 = librosa.fmt(y, axis=-1)
    f2 = librosa.fmt(y.T, axis=0).T

    assert np.allclose(f1, f2)
예제 #5
0
 def __call__(self):
     self.on_launch()
     xdata = []
     ydata = []
     for x in np.arange(0, 10, 0.5):
         ydata = np.array([
             np.exp(-i**2) + 10 * np.exp(-(i - 7)**2)
             for i in range(0, 128)
         ])
         if (x % 2 == 0):
             ydata = np.abs(librosa.fmt(ydata, n_fmt=64))
         else:
             ydata = librosa.amplitude_to_db(librosa.stft(ydata),
                                             ref=np.max)
         xdata = np.array([i for i in range(0, ydata.size)])
         self.on_running(xdata, ydata)
         time.sleep(1)
     return xdata, ydata
예제 #6
0
    def transform_audio(self, y):
        '''Apply the scale transform to the tempogram

        Parameters
        ----------
        y : np.ndarray
            The audio buffer

        Returns
        -------
        data : dict
            data['temposcale'] : np.ndarray, shape=(n_frames, n_fmt)
                The scale transform magnitude coefficients
        '''
        data = super(TempoScale, self).transform_audio(y)
        data['temposcale'] = np.abs(
            fmt(data.pop('tempogram'), axis=1,
                n_fmt=self.n_fmt)).astype(np.float32)[self.idx]
        return data
예제 #7
0
def compute_stm(counts, nbins=300, ncycles=5):    
    start_ind = 0
    nsamples = nbins*ncycles
    end_ind = start_ind + nsamples
    n_acf = 1500
    n_stm = 750 #int(nsamples/4.)
    ac_all, scale_all = [], []

    while end_ind <= len(counts):
        ac = librosa.autocorrelate(counts[start_ind:end_ind], max_size=n_acf)
        ac = librosa.util.normalize(ac, norm=np.inf)
        ac_all.append(ac)

        scale = librosa.fmt(ac, n_fmt=n_stm)
        scale_all.append(scale)

        start_ind += nsamples
        end_ind += nsamples

    ac_all = np.array(ac_all)
    scale_all = np.array(scale_all)
    
    return ac_all, scale_all
예제 #8
0
 def __test(t_min, n_fmt, over_sample, y):
     librosa.fmt(y, t_min=t_min, n_fmt=n_fmt, over_sample=over_sample)
예제 #9
0
 def __test(t_min, n_fmt, over_sample, y):
     librosa.fmt(y, t_min=t_min, n_fmt=n_fmt, over_sample=over_sample)