Mercurial > hg > qm-dsp
diff dsp/keydetection/GetKeyMode.h @ 509:3f0a96460c33
Switch to config-struct constructor; add frameOverlapFactor parameter
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Thu, 06 Jun 2019 14:20:53 +0100 |
parents | af5b7ef02aa7 |
children |
line wrap: on
line diff
--- a/dsp/keydetection/GetKeyMode.h Wed Jun 05 16:05:09 2019 +0100 +++ b/dsp/keydetection/GetKeyMode.h Thu Jun 06 14:20:53 2019 +0100 @@ -13,37 +13,64 @@ #ifndef QM_DSP_GETKEYMODE_H #define QM_DSP_GETKEYMODE_H - -#include "dsp/rateconversion/Decimator.h" -#include "dsp/chromagram/Chromagram.h" - +class Decimator; +class Chromagram; class GetKeyMode { public: - GetKeyMode( int sampleRate, float tuningFrequency, - double hpcpAverage, double medianAverage ); + struct Config { + double sampleRate; + float tuningFrequency; + double hpcpAverage; + double medianAverage; + int frameOverlapFactor; // 1 = none (default, fast, but means + // we skip a fair bit of input data); + // 8 = normal chroma overlap + int decimationFactor; + + Config(double _sampleRate, float _tuningFrequency) : + sampleRate(_sampleRate), + tuningFrequency(_tuningFrequency), + hpcpAverage(10), + medianAverage(10), + frameOverlapFactor(1), + decimationFactor(8) { + } + }; + + GetKeyMode(Config config); virtual ~GetKeyMode(); - int process( double* PCMData ); + /** + * Process a single time-domain input sample frame of length + * getBlockSize(). Successive calls should provide overlapped data + * with an advance of getHopSize() between frames. + * + * Return a key index in the range 0-24, where 0 indicates no key + * detected, 1 is C major, and 13 is C minor. + */ + int process(double *pcmData); - double krumCorr( const double *pDataNorm, const double *pProfileNorm, - int shiftProfile, int length ); + /** + * Return a pointer to an internal 24-element array containing the + * correlation of the chroma vector generated in the last + * process() call against the stored key profiles for the 12 major + * and 12 minor keys, where index 0 is C major and 12 is C minor. + */ + double *getKeyStrengths(); - int getBlockSize() { return m_chromaFrameSize * m_decimationFactor; } - int getHopSize() { return m_chromaHopSize * m_decimationFactor; } - - double* getChroma() { return m_chrPointer; } - int getChromaSize(); - - double* getMeanHPCP() { return m_meanHPCP; } - - double* getKeyStrengths(); - - bool isModeMinor( int key ); + int getBlockSize() { + return m_chromaFrameSize * m_decimationFactor; + } + int getHopSize() { + return m_chromaHopSize * m_decimationFactor; + } protected: + double krumCorr(const double *pDataNorm, const double *pProfileNorm, + int shiftProfile, int length); double m_hpcpAverage; double m_medianAverage; @@ -52,9 +79,6 @@ // Decimator (fixed) Decimator* m_decimator; - // Chroma configuration - ChromaConfig m_chromaConfig; - // Chromagram object Chromagram* m_chroma;