#NEWLINE# @ cache #NEWLINE# def chroma( sr , n_fft , n_chroma = 12 , A440 = 440.0 , ctroct = 5.0 , octwidth = 2 , norm = 2 , base_c = True ) : #NEWLINE# #INDENT# "Create a Filterbank matrix to convert STFT to chroma\n\n\n    Parameters\n    ----------\n    sr        : number > 0 [scalar]\n        audio sampling rate\n\n    n_fft     : int > 0 [scalar]\n        number of FFT bins\n\n    n_chroma  : int > 0 [scalar]\n        number of chroma bins\n\n    A440      : float > 0 [scalar]\n        Reference frequency for A440\n\n    ctroct    : float > 0 [scalar]\n\n    octwidth  : float > 0 or None [scalar]\n        `ctroct` and `octwidth` specify a dominance window -\n        a Gaussian weighting centered on `ctroct` (in octs, A0 = 27.5Hz)\n        and with a gaussian half-width of `octwidth`.\n        Set `octwidth` to `None` to use a flat weighting.\n\n    norm : float > 0 or np.inf\n        Normalization factor for each filter\n\n    base_c : bool\n        If True, the filter bank will start at 'C'.\n        If False, the filter bank will start at 'A'.\n    Returns\n    -------\n    wts : ndarray [shape=(n_chroma, 1 + n_fft / 2)]\n        Chroma filter matrix\n\n    See Also\n    --------\n    util.normalize\n    feature.chroma_stft\n\n    Examples\n    --------\n    Build a simple chroma filter bank\n\n    >>> chromafb = librosa.filters.chroma(22050, 4096)\n    array([[  1.689e-05,   3.024e-04, ...,   4.639e-17,   5.327e-17],\n           [  1.716e-05,   2.652e-04, ...,   2.674e-25,   3.176e-25],\n    ...,\n           [  1.578e-05,   3.619e-04, ...,   8.577e-06,   9.205e-06],\n           [  1.643e-05,   3.355e-04, ...,   1.474e-10,   1.636e-10]])\n\n    Use quarter-tones instead of semitones\n\n    >>> librosa.filters.chroma(22050, 4096, n_chroma=24)\n    array([[  1.194e-05,   2.138e-04, ...,   6.297e-64,   1.115e-63],\n           [  1.206e-05,   2.009e-04, ...,   1.546e-79,   2.929e-79],\n    ...,\n           [  1.162e-05,   2.372e-04, ...,   6.417e-38,   9.923e-38],\n           [  1.180e-05,   2.260e-04, ...,   4.697e-50,   7.772e-50]])\n\n\n    Equally weight all octaves\n\n    >>> librosa.filters.chroma(22050, 4096, octwidth=None)\n    array([[  3.036e-01,   2.604e-01, ...,   2.445e-16,   2.809e-16],\n           [  3.084e-01,   2.283e-01, ...,   1.409e-24,   1.675e-24],\n    ...,\n           [  2.836e-01,   3.116e-01, ...,   4.520e-05,   4.854e-05],\n           [  2.953e-01,   2.888e-01, ...,   7.768e-10,   8.629e-10]])\n\n    >>> import matplotlib.pyplot as plt\n    >>> plt.figure()\n    >>> librosa.display.specshow(chromafb, x_axis='linear')\n    >>> plt.ylabel('Chroma filter')\n    >>> plt.title('Chroma filter bank')\n    >>> plt.colorbar()\n    >>> plt.tight_layout()\n    " #NEWLINE# wts = np . zeros ( ( n_chroma , n_fft ) ) #NEWLINE# frequencies = np . linspace ( 0 , sr , n_fft , endpoint = False ) [ 1 : ] #NEWLINE# frqbins = ( n_chroma * hz_to_octs ( frequencies , A440 ) ) #NEWLINE# frqbins = np . concatenate ( ( [ ( frqbins [ 0 ] - ( 1.5 * n_chroma ) ) ] , frqbins ) ) #NEWLINE# binwidthbins = np . concatenate ( ( np . maximum ( ( frqbins [ 1 : ] - frqbins [ : ( - 1 ) ] ) , 1.0 ) , [ 1 ] ) ) #NEWLINE# D = np . subtract . outer ( frqbins , np . arange ( 0 , n_chroma , dtype = 'd' ) ) . T #NEWLINE# n_chroma2 = np . round ( ( float ( n_chroma ) / 2 ) ) #NEWLINE# D = ( np . remainder ( ( ( D + n_chroma2 ) + ( 10 * n_chroma ) ) , n_chroma ) - n_chroma2 ) #NEWLINE# wts = np . exp ( ( ( - 0.5 ) * ( ( ( 2 * D ) / np . tile ( binwidthbins , ( n_chroma , 1 ) ) ) ** 2 ) ) ) #NEWLINE# wts = util . normalize ( wts , norm = norm , axis = 0 ) #NEWLINE# if ( octwidth is not None ) : #NEWLINE# #INDENT# wts *= np . tile ( np . exp ( ( ( - 0.5 ) * ( ( ( ( frqbins / n_chroma ) - ctroct ) / octwidth ) ** 2 ) ) ) , ( n_chroma , 1 ) ) #NEWLINE# #UNINDENT# if base_c : #NEWLINE# #INDENT# wts = np . roll ( wts , ( - 3 ) , axis = 0 ) #NEWLINE# #UNINDENT# return np . ascontiguousarray ( wts [ : , : int ( ( 1 + ( n_fft / 2 ) ) ) ] )