# Path: friture/signal/scipy_resample.py
# def resample(x, num, t=None, axis=0, window=None):
#     """
#     Resample `x` to `num` samples using Fourier method along the given axis.
# 
#     The resampled signal starts at the same value as `x` but is sampled
#     with a spacing of ``len(x) / num * (spacing of x)``.  Because a
#     Fourier method is used, the signal is assumed to be periodic.
# 
#     Parameters
#     ----------
#     x : array_like
#         The data to be resampled.
#     num : int
#         The number of samples in the resampled signal.
#     t : array_like, optional
#         If `t` is given, it is assumed to be the sample positions
#         associated with the signal data in `x`.
#     axis : int, optional
#         The axis of `x` that is resampled.  Default is 0.
#     window : array_like, callable, string, float, or tuple, optional
#         Specifies the window applied to the signal in the Fourier
#         domain.  See below for details.
# 
#     Returns
#     -------
#     resampled_x or (resampled_x, resampled_t)
#         Either the resampled array, or, if `t` was given, a tuple
#         containing the resampled array and the corresponding resampled
#         positions.
# 
#     Notes
#     -----
#     The argument `window` controls a Fourier-domain window that tapers
#     the Fourier spectrum before zero-padding to alleviate ringing in
#     the resampled values for sampled signals you didn't intend to be
#     interpreted as band-limited.
# 
#     If `window` is a function, then it is called with a vector of inputs
#     indicating the frequency bins (i.e. fftfreq(x.shape[axis]) ).
# 
#     If `window` is an array of the same length as `x.shape[axis]` it is
#     assumed to be the window to be applied directly in the Fourier
#     domain (with dc and low-frequency first).
# 
#     For any other type of `window`, the function `scipy.signal.get_window`
#     is called to generate the window.
# 
#     The first sample of the returned vector is the same as the first
#     sample of the input vector.  The spacing between samples is changed
#     from dx to:
# 
#         dx * len(x) / num
# 
#     If `t` is not None, then it represents the old sample positions,
#     and the new sample positions will be returned as well as the new
#     samples.
# 
#     """
#     x = asarray(x)
#     X = fft(x, axis=axis)
#     Nx = x.shape[axis]
#     if window is not None:
#         if callable(window):
#             W = window(fftfreq(Nx))
#         elif isinstance(window, ndarray) and window.shape == (Nx,):
#             W = window
#         else:
#             W = ifftshift(get_window(window, Nx))
#         newshape = [1] * x.ndim
#         newshape[axis] = len(W)
#         W.shape = newshape
#         X = X * W
#     sl = [slice(None)] * len(x.shape)
#     newshape = list(x.shape)
#     newshape[axis] = num
#     N = int(np.minimum(num, Nx))
#     Y = zeros(newshape, 'D')
#     sl[axis] = slice(0, (N + 1) // 2)
#     Y[tuple(sl)] = X[tuple(sl)]
#     sl[axis] = slice(-(N - 1) // 2, None)
#     Y[tuple(sl)] = X[tuple(sl)]
#     y = ifft(Y, axis=axis) * (float(num) / float(Nx))
# 
#     if x.dtype.char not in ['F', 'D']:
#         y = y.real
# 
#     if t is None:
#         return y
#     else:
#         new_t = arange(0, num) * (t[1] - t[0]) * Nx / float(num) + t[0]
#         return y, new_t


import numpy as np
from .scipy_resample import resample
from friture_extensions.linear_interp import pyx_linear_interp_2D
        self.decim_factor_M = decim_factor_M
        self.resampling_ratio = float(interp_factor_L) / decim_factor_M

        self.height = height

        self.orig_index = 0.
        self.resampled_index = 0.

        self.old_data = np.zeros((self.height))

        self.resampled_data = np.zeros((self.height, 1))

    def set_ratio(self, interp_factor_L, decim_factor_M):
        if self.interp_factor_L != interp_factor_L or self.decim_factor_M != decim_factor_M:
            self.interp_factor_L = interp_factor_L
            self.decim_factor_M = decim_factor_M
            self.resampling_ratio = float(interp_factor_L) / decim_factor_M

            self.orig_index = 0.
            self.resampled_index = 0.

    def set_height(self, height):
        if self.height != height:
            self.height = height

            self.orig_index = 0.
            self.resampled_index = 0.

            # we resample here instead of just restarting with zeros to avoid black vertical lines
            # in the spectrogram

# Path: friture/signal/scipy_resample.py
# def resample(x, num, t=None, axis=0, window=None):
#     """
#     Resample `x` to `num` samples using Fourier method along the given axis.
# 
#     The resampled signal starts at the same value as `x` but is sampled
#     with a spacing of ``len(x) / num * (spacing of x)``.  Because a
#     Fourier method is used, the signal is assumed to be periodic.
# 
#     Parameters
#     ----------
#     x : array_like
#         The data to be resampled.
#     num : int
#         The number of samples in the resampled signal.
#     t : array_like, optional
#         If `t` is given, it is assumed to be the sample positions
#         associated with the signal data in `x`.
#     axis : int, optional
#         The axis of `x` that is resampled.  Default is 0.
#     window : array_like, callable, string, float, or tuple, optional
#         Specifies the window applied to the signal in the Fourier
#         domain.  See below for details.
# 
#     Returns
#     -------
#     resampled_x or (resampled_x, resampled_t)
#         Either the resampled array, or, if `t` was given, a tuple
#         containing the resampled array and the corresponding resampled
#         positions.
# 
#     Notes
#     -----
#     The argument `window` controls a Fourier-domain window that tapers
#     the Fourier spectrum before zero-padding to alleviate ringing in
#     the resampled values for sampled signals you didn't intend to be
#     interpreted as band-limited.
# 
#     If `window` is a function, then it is called with a vector of inputs
#     indicating the frequency bins (i.e. fftfreq(x.shape[axis]) ).
# 
#     If `window` is an array of the same length as `x.shape[axis]` it is
#     assumed to be the window to be applied directly in the Fourier
#     domain (with dc and low-frequency first).
# 
#     For any other type of `window`, the function `scipy.signal.get_window`
#     is called to generate the window.
# 
#     The first sample of the returned vector is the same as the first
#     sample of the input vector.  The spacing between samples is changed
#     from dx to:
# 
#         dx * len(x) / num
# 
#     If `t` is not None, then it represents the old sample positions,
#     and the new sample positions will be returned as well as the new
#     samples.
# 
#     """
#     x = asarray(x)
#     X = fft(x, axis=axis)
#     Nx = x.shape[axis]
#     if window is not None:
#         if callable(window):
#             W = window(fftfreq(Nx))
#         elif isinstance(window, ndarray) and window.shape == (Nx,):
#             W = window
#         else:
#             W = ifftshift(get_window(window, Nx))
#         newshape = [1] * x.ndim
#         newshape[axis] = len(W)
#         W.shape = newshape
#         X = X * W
#     sl = [slice(None)] * len(x.shape)
#     newshape = list(x.shape)
#     newshape[axis] = num
#     N = int(np.minimum(num, Nx))
#     Y = zeros(newshape, 'D')
#     sl[axis] = slice(0, (N + 1) // 2)
#     Y[tuple(sl)] = X[tuple(sl)]
#     sl[axis] = slice(-(N - 1) // 2, None)
#     Y[tuple(sl)] = X[tuple(sl)]
#     y = ifft(Y, axis=axis) * (float(num) / float(Nx))
# 
#     if x.dtype.char not in ['F', 'D']:
#         y = y.real
# 
#     if t is None:
#         return y
#     else:
#         new_t = arange(0, num) * (t[1] - t[0]) * Nx / float(num) + t[0]
#         return y, new_t


# Path: friture/signal/online_linear_2D_resampler.py
import numpy as np
from .scipy_resample import resample
from friture_extensions.linear_interp import pyx_linear_interp_2D

        self.decim_factor_M = decim_factor_M
        self.resampling_ratio = float(interp_factor_L) / decim_factor_M

        self.height = height

        self.orig_index = 0.
        self.resampled_index = 0.

        self.old_data = np.zeros((self.height))

        self.resampled_data = np.zeros((self.height, 1))

    def set_ratio(self, interp_factor_L, decim_factor_M):
        if self.interp_factor_L != interp_factor_L or self.decim_factor_M != decim_factor_M:
            self.interp_factor_L = interp_factor_L
            self.decim_factor_M = decim_factor_M
            self.resampling_ratio = float(interp_factor_L) / decim_factor_M

            self.orig_index = 0.
            self.resampled_index = 0.

    def set_height(self, height):
        if self.height != height:
            self.height = height

            self.orig_index = 0.
            self.resampled_index = 0.

            # we resample here instead of just restarting with zeros to avoid black vertical lines
            # in the spectrogram

            self.old_data = resample(self.old_data, self.height)