Skip to content

Instantly share code, notes, and snippets.

@RicherMans
Created January 13, 2020 15:38
Show Gist options
  • Save RicherMans/d760c045e34e30e7d8c4d0de1843d79d to your computer and use it in GitHub Desktop.
Save RicherMans/d760c045e34e30e7d8c4d0de1843d79d to your computer and use it in GitHub Desktop.
import librosa
import scipy
import numpy as np
def cmc(y, sr, P=12, n_level=7, eps=1e-12, **kwargs):
log_abs_power_cqt = np.log(
np.abs(librosa.core.cqt(y=y, sr=sr, **kwargs))**2 + eps)
cmc_levels = []
for _ in range(n_level):
octave = scipy.fftpack.dct(log_abs_power_cqt,
norm='ortho',
axis=0,
type=2)
cmc = octave[:P]
log_abs_power_cqt = octave[P:] # residual to next dct
cmc_levels.append(cmc)
return np.concatenate(cmc_levels, 0).T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment