def phasevocoder(channels, speed=1., frame_length=2048, analysis_hop=None, synthesis_hop=None, phase_locking=PhaseLocking.IDENTITY): """Returns a :class:`~audiotsm.base.tsm.TSM` object implementing the phase vocoder time-scale modification procedure. In most cases, you should not need to set the ``frame_length``, the ``analysis_hop`` or the ``synthesis_hop``. If you want to fine tune these parameters, you can check the documentation of the :class:`~audiotsm.base.analysis_synthesis.AnalysisSynthesisTSM` class to see what they represent. :param channels: the number of channels of the input signal. :type channels: int :param speed: the speed ratio by which the speed of the signal will be multiplied (for example, if ``speed`` is set to 0.5, the output signal will be half as fast as the input signal). :type speed: float, optional :param frame_length: the length of the frames. :type frame_length: int, optional :param analysis_hop: the number of samples between two consecutive analysis frames (``speed * synthesis_hop`` by default). If ``analysis_hop`` is set, the ``speed`` parameter will be ignored. :type analysis_hop: int, optional :param synthesis_hop: the number of samples between two consecutive synthesis frames (``frame_length // 4`` by default). :type synthesis_hop: int, optional :param phase_locking: a phase locking strategy. :type phase_locking: :class:`PhaseLocking`, optional :returns: a :class:`audiotsm.base.tsm.TSM` object """ # pylint: disable=too-many-arguments if synthesis_hop is None: synthesis_hop = frame_length // 4 if analysis_hop is None: analysis_hop = int(synthesis_hop * speed) analysis_window = hanning(frame_length) synthesis_window = hanning(frame_length) if phase_locking == PhaseLocking.NONE: # No phase locking: all freqyency bins are considered to be peaks peak_finder = all_peaks elif phase_locking == PhaseLocking.IDENTITY: peak_finder = find_peaks else: raise ValueError( 'Invalid phase_locking value: "{}"'.format(phase_locking)) converter = PhaseVocoderConverter(channels, frame_length, analysis_hop, synthesis_hop, peak_finder) return AnalysisSynthesisTSM(converter, channels, frame_length, analysis_hop, synthesis_hop, analysis_window, synthesis_window)
def wsola(channels, speed=1., frame_length=1024, analysis_hop=None, synthesis_hop=None, tolerance=None): """Returns a :class:`~audiotsm.base.tsm.TSM` object implementing the WSOLA (Waveform Similarity-based Overlap-Add) time-scale modification procedure. In most cases, you should not need to set the ``frame_length``, the ``analysis_hop``, the ``synthesis_hop``, or the ``tolerance``. If you want to fine tune these parameters, you can check the documentation of the :class:`~audiotsm.base.analysis_synthesis.AnalysisSynthesisTSM` class to see what the first three represent. WSOLA works in the same way as OLA, with the exception that it allows slight shift (at most ``tolerance``) of the position of the analysis frames. :param channels: the number of channels of the input signal. :type channels: int :param speed: the speed ratio by which the speed of the signal will be multiplied (for example, if ``speed`` is set to 0.5, the output signal will be half as fast as the input signal). :type speed: float, optional :param frame_length: the length of the frames. :type frame_length: int, optional :param analysis_hop: the number of samples between two consecutive analysis frames (``speed * synthesis_hop`` by default). If ``analysis_hop`` is set, the ``speed`` parameter will be ignored. :type analysis_hop: int, optional :param synthesis_hop: the number of samples between two consecutive synthesis frames (``frame_length // 2`` by default). :type synthesis_hop: int, optional :param tolerance: the maximum number of samples that the analysis frame can be shifted. :type tolerance: int :returns: a :class:`audiotsm.base.tsm.TSM` object """ # pylint: disable=too-many-arguments if synthesis_hop is None: synthesis_hop = frame_length // 2 if analysis_hop is None: analysis_hop = int(synthesis_hop * speed) if tolerance is None: tolerance = frame_length // 2 analysis_window = None synthesis_window = hanning(frame_length) converter = WSOLAConverter(channels, frame_length, synthesis_hop, tolerance) return AnalysisSynthesisTSM(converter, channels, frame_length, analysis_hop, synthesis_hop, analysis_window, synthesis_window, tolerance, tolerance + synthesis_hop)
def ola(channels, speed=1., frame_length=256, analysis_hop=None, synthesis_hop=None): """Returns a :class:`~audiotsm.base.tsm.TSM` object implementing the OLA (Overlap-Add) time-scale modification procedure. In most cases, you should not need to set the ``frame_length``, the ``analysis_hop`` or the ``synthesis_hop``. If you want to fine tune these parameters, you can check the documentation of the :class:`~audiotsm.base.analysis_synthesis.AnalysisSynthesisTSM` class to see what they represent. :param channels: the number of channels of the input signal. :type channels: int :param speed: the speed ratio by which the speed of the signal will be multiplied (for example, if ``speed`` is set to 0.5, the output signal will be half as fast as the input signal). :type speed: float, optional :param frame_length: the length of the frames. :type frame_length: int, optional :param analysis_hop: the number of samples between two consecutive analysis frames (``speed * synthesis_hop`` by default). If ``analysis_hop`` is set, the ``speed`` parameter will be ignored. :type analysis_hop: int, optional :param synthesis_hop: the number of samples between two consecutive synthesis frames (``frame_length // 2`` by default). :type synthesis_hop: int, optional :returns: a :class:`audiotsm.base.tsm.TSM` object """ if synthesis_hop is None: synthesis_hop = frame_length // 2 if analysis_hop is None: analysis_hop = int(synthesis_hop * speed) analysis_window = None synthesis_window = hanning(frame_length) converter = OLAConverter() return AnalysisSynthesisTSM( converter, channels, frame_length, analysis_hop, synthesis_hop, analysis_window, synthesis_window)
def test_hanning(length, window): """Run tests for hanning.""" assert_almost_equal(windows.hanning(length), np.array(window))