@chromaprint ?= {}
NUM_BANDS = 12
log2 = Math.log(2)
freqToOctave = (freq, base = 440 / 16.0) ->
Math.log(freq / base) / log2
chroma = (minFreq, maxFreq, frameSize, sampleRate, interpolate) ->
notes = []
features = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
freqToIndex = (frq) -> Math.round(frameSize * frq / sampleRate)
indexToFreq = (idx) -> (idx * sampleRate) / frameSize
indexToOctave = (i) -> freqToOctave(indexToFreq(i))
minIndex = Math.max(1, freqToIndex(minFreq))
maxIndex = Math.min(frameSize / 2, freqToIndex(maxFreq))
for i in [minIndex...maxIndex]
octave = indexToOctave(i)
notes[i] = NUM_BANDS * (octave - Math.floor(octave))
(frame) ->
energy = (i) -> frame[i] ? 0
for i in [minIndex...maxIndex]
e = energy(i)
note = notes[i]
unit = Math.floor(note)
fraction = note - unit
if interpolate