@cache(level=<NUM_LIT:10>)<EOL>def constant_q(sr, fmin=None, n_bins=<NUM_LIT>, bins_per_octave=<NUM_LIT:12>, tuning=<NUM_LIT:0.0>,<EOL>window='<STR_LIT>', filter_scale=<NUM_LIT:1>, pad_fft=True, norm=<NUM_LIT:1>,<EOL>dtype=np.complex64, **kwargs):
if fmin is None:<EOL><INDENT>fmin = note_to_hz('<STR_LIT>')<EOL><DEDENT>lengths = constant_q_lengths(sr, fmin,<EOL>n_bins=n_bins,<EOL>bins_per_octave=bins_per_octave,<EOL>tuning=tuning,<EOL>window=window,<EOL>filter_scale=filter_scale)<EOL>correction = <NUM_LIT>**(float(tuning) / bins_per_octave)<EOL>fmin = correction * fmin<EOL>Q = float(filter_scale) / (<NUM_LIT>**(<NUM_LIT:1.> / bins_per_octave) - <NUM_LIT:1>)<EOL>freqs = Q * sr / lengths<EOL>filters = []<EOL>for ilen, freq in zip(lengths, freqs):<EOL><INDENT>sig = np.exp(np.arange(-ilen//<NUM_LIT:2>, ilen//<NUM_LIT:2>, dtype=float) * <NUM_LIT> * <NUM_LIT:2> * np.pi * freq / sr)<EOL>sig = sig * __float_window(window)(len(sig))<EOL>sig = util.normalize(sig, norm=norm)<EOL>filters.append(sig)<EOL><DEDENT>max_len = max(lengths)<EOL>if pad_fft:<EOL><INDENT>max_len = int(<NUM_LIT>**(np.ceil(np.log2(max_len))))<EOL><DEDENT>else:<EOL><INDENT>max_len = int(np.ceil(max_len))<EOL><DEDENT>filters = np.asarray([util.pad_center(filt, max_len, **kwargs)<EOL>for filt in filters], dtype=dtype)<EOL>return filters, np.asarray(lengths)<EOL>
r'''Construct a constant-Q basis.

    This uses the filter bank described by [1]_.

    .. [1] McVicar, Matthew.
            "A machine learning approach to automatic chord extraction."
            Dissertation, University of Bristol. 2013.


    Parameters
    ----------
    sr : number > 0 [scalar]
        Audio sampling rate

    fmin : float > 0 [scalar]
        Minimum frequency bin. Defaults to `C1 ~= 32.70`

    n_bins : int > 0 [scalar]
        Number of frequencies.  Defaults to 7 octaves (84 bins).

    bins_per_octave : int > 0 [scalar]
        Number of bins per octave

    tuning : float in `[-0.5, +0.5)` [scalar]
        Tuning deviation from A440 in fractions of a bin

    window : string, tuple, number, or function
        Windowing function to apply to filters.

    filter_scale : float > 0 [scalar]
        Scale of filter windows.
        Small values (<1) use shorter windows for higher temporal resolution.

    pad_fft : boolean
        Center-pad all filters up to the nearest integral power of 2.

        By default, padding is done with zeros, but this can be overridden
        by setting the `mode=` field in *kwargs*.

    norm : {inf, -inf, 0, float > 0}
        Type of norm to use for basis function normalization.
        See librosa.util.normalize

    dtype : np.dtype
        The data type of the output basis.
        By default, uses 64-bit (single precision) complex floating point.

    kwargs : additional keyword arguments
        Arguments to `np.pad()` when `pad==True`.

    Returns
    -------
    filters : np.ndarray, `len(filters) == n_bins`
        `filters[i]` is `i`\ th time-domain CQT basis filter

    lengths : np.ndarray, `len(lengths) == n_bins`
        The (fractional) length of each filter

    Notes
    -----
    This function caches at level 10.

    See Also
    --------
    constant_q_lengths
    librosa.core.cqt
    librosa.util.normalize


    Examples
    --------
    Use a shorter window for each filter

    >>> basis, lengths = librosa.filters.constant_q(22050, filter_scale=0.5)

    Plot one octave of filters in time and frequency

    >>> import matplotlib.pyplot as plt
    >>> basis, lengths = librosa.filters.constant_q(22050)
    >>> plt.figure(figsize=(10, 6))
    >>> plt.subplot(2, 1, 1)
    >>> notes = librosa.midi_to_note(np.arange(24, 24 + len(basis)))
    >>> for i, (f, n) in enumerate(zip(basis, notes[:12])):
    ...     f_scale = librosa.util.normalize(f) / 2
    ...     plt.plot(i + f_scale.real)
    ...     plt.plot(i + f_scale.imag, linestyle=':')
    >>> plt.axis('tight')
    >>> plt.yticks(np.arange(len(notes[:12])), notes[:12])
    >>> plt.ylabel('CQ filters')
    >>> plt.title('CQ filters (one octave, time domain)')
    >>> plt.xlabel('Time (samples at 22050 Hz)')
    >>> plt.legend(['Real', 'Imaginary'], frameon=True, framealpha=0.8)
    >>> plt.subplot(2, 1, 2)
    >>> F = np.abs(np.fft.fftn(basis, axes=[-1]))
    >>> # Keep only the positive frequencies
    >>> F = F[:, :(1 + F.shape[1] // 2)]
    >>> librosa.display.specshow(F, x_axis='linear')
    >>> plt.yticks(np.arange(len(notes))[::12], notes[::12])
    >>> plt.ylabel('CQ filters')
    >>> plt.title('CQ filter magnitudes (frequency domain)')
    >>> plt.tight_layout()