def phase_vocoder(D, rate, hop_length=None):
n_fft = <NUM_LIT:2> * (D.shape[<NUM_LIT:0>] - <NUM_LIT:1>)<EOL>if hop_length is None:<EOL><INDENT>hop_length = int(n_fft // <NUM_LIT:4>)<EOL><DEDENT>time_steps = np.arange(<NUM_LIT:0>, D.shape[<NUM_LIT:1>], rate, dtype=np.float)<EOL>d_stretch = np.zeros((D.shape[<NUM_LIT:0>], len(time_steps)), D.dtype, order='<STR_LIT:F>')<EOL>phi_advance = np.linspace(<NUM_LIT:0>, np.pi * hop_length, D.shape[<NUM_LIT:0>])<EOL>phase_acc = np.angle(D[:, <NUM_LIT:0>])<EOL>D = np.pad(D, [(<NUM_LIT:0>, <NUM_LIT:0>), (<NUM_LIT:0>, <NUM_LIT:2>)], mode='<STR_LIT>')<EOL>for (t, step) in enumerate(time_steps):<EOL><INDENT>columns = D[:, int(step):int(step + <NUM_LIT:2>)]<EOL>alpha = np.mod(step, <NUM_LIT:1.0>)<EOL>mag = ((<NUM_LIT:1.0> - alpha) * np.abs(columns[:, <NUM_LIT:0>])<EOL>+ alpha * np.abs(columns[:, <NUM_LIT:1>]))<EOL>d_stretch[:, t] = mag * np.exp(<NUM_LIT> * phase_acc)<EOL>dphase = (np.angle(columns[:, <NUM_LIT:1>])<EOL>- np.angle(columns[:, <NUM_LIT:0>])<EOL>- phi_advance)<EOL>dphase = dphase - <NUM_LIT> * np.pi * np.round(dphase / (<NUM_LIT> * np.pi))<EOL>phase_acc += phi_advance + dphase<EOL><DEDENT>return d_stretch<EOL>
Phase vocoder.  Given an STFT matrix D, speed up by a factor of `rate`

    Based on the implementation provided by [1]_.

    .. [1] Ellis, D. P. W. "A phase vocoder in Matlab."
        Columbia University, 2002.
        http://www.ee.columbia.edu/~dpwe/resources/matlab/pvoc/

    Examples
    --------
    >>> # Play at double speed
    >>> y, sr   = librosa.load(librosa.util.example_audio_file())
    >>> D       = librosa.stft(y, n_fft=2048, hop_length=512)
    >>> D_fast  = librosa.phase_vocoder(D, 2.0, hop_length=512)
    >>> y_fast  = librosa.istft(D_fast, hop_length=512)

    >>> # Or play at 1/3 speed
    >>> y, sr   = librosa.load(librosa.util.example_audio_file())
    >>> D       = librosa.stft(y, n_fft=2048, hop_length=512)
    >>> D_slow  = librosa.phase_vocoder(D, 1./3, hop_length=512)
    >>> y_slow  = librosa.istft(D_slow, hop_length=512)

    Parameters
    ----------
    D : np.ndarray [shape=(d, t), dtype=complex]
        STFT matrix

    rate :  float > 0 [scalar]
        Speed-up factor: `rate > 1` is faster, `rate < 1` is slower.

    hop_length : int > 0 [scalar] or None
        The number of samples between successive columns of `D`.

        If None, defaults to `n_fft/4 = (D.shape[0]-1)/2`

    Returns
    -------
    D_stretched : np.ndarray [shape=(d, t / rate), dtype=complex]
        time-stretched STFT