Mercurial > hg > qm-dsp
comparison 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 |
comparison
equal
deleted
inserted
replaced
508:855d862cf02b | 509:3f0a96460c33 |
---|---|
11 */ | 11 */ |
12 | 12 |
13 #ifndef QM_DSP_GETKEYMODE_H | 13 #ifndef QM_DSP_GETKEYMODE_H |
14 #define QM_DSP_GETKEYMODE_H | 14 #define QM_DSP_GETKEYMODE_H |
15 | 15 |
16 | 16 class Decimator; |
17 #include "dsp/rateconversion/Decimator.h" | 17 class Chromagram; |
18 #include "dsp/chromagram/Chromagram.h" | |
19 | |
20 | 18 |
21 class GetKeyMode | 19 class GetKeyMode |
22 { | 20 { |
23 public: | 21 public: |
24 GetKeyMode( int sampleRate, float tuningFrequency, | 22 struct Config { |
25 double hpcpAverage, double medianAverage ); | 23 double sampleRate; |
24 float tuningFrequency; | |
25 double hpcpAverage; | |
26 double medianAverage; | |
27 int frameOverlapFactor; // 1 = none (default, fast, but means | |
28 // we skip a fair bit of input data); | |
29 // 8 = normal chroma overlap | |
30 int decimationFactor; | |
31 | |
32 Config(double _sampleRate, float _tuningFrequency) : | |
33 sampleRate(_sampleRate), | |
34 tuningFrequency(_tuningFrequency), | |
35 hpcpAverage(10), | |
36 medianAverage(10), | |
37 frameOverlapFactor(1), | |
38 decimationFactor(8) { | |
39 } | |
40 }; | |
41 | |
42 GetKeyMode(Config config); | |
26 | 43 |
27 virtual ~GetKeyMode(); | 44 virtual ~GetKeyMode(); |
28 | 45 |
29 int process( double* PCMData ); | 46 /** |
47 * Process a single time-domain input sample frame of length | |
48 * getBlockSize(). Successive calls should provide overlapped data | |
49 * with an advance of getHopSize() between frames. | |
50 * | |
51 * Return a key index in the range 0-24, where 0 indicates no key | |
52 * detected, 1 is C major, and 13 is C minor. | |
53 */ | |
54 int process(double *pcmData); | |
30 | 55 |
31 double krumCorr( const double *pDataNorm, const double *pProfileNorm, | 56 /** |
32 int shiftProfile, int length ); | 57 * Return a pointer to an internal 24-element array containing the |
58 * correlation of the chroma vector generated in the last | |
59 * process() call against the stored key profiles for the 12 major | |
60 * and 12 minor keys, where index 0 is C major and 12 is C minor. | |
61 */ | |
62 double *getKeyStrengths(); | |
33 | 63 |
34 int getBlockSize() { return m_chromaFrameSize * m_decimationFactor; } | 64 int getBlockSize() { |
35 int getHopSize() { return m_chromaHopSize * m_decimationFactor; } | 65 return m_chromaFrameSize * m_decimationFactor; |
36 | 66 } |
37 double* getChroma() { return m_chrPointer; } | 67 int getHopSize() { |
38 int getChromaSize(); | 68 return m_chromaHopSize * m_decimationFactor; |
39 | 69 } |
40 double* getMeanHPCP() { return m_meanHPCP; } | |
41 | |
42 double* getKeyStrengths(); | |
43 | |
44 bool isModeMinor( int key ); | |
45 | 70 |
46 protected: | 71 protected: |
72 double krumCorr(const double *pDataNorm, const double *pProfileNorm, | |
73 int shiftProfile, int length); | |
47 | 74 |
48 double m_hpcpAverage; | 75 double m_hpcpAverage; |
49 double m_medianAverage; | 76 double m_medianAverage; |
50 int m_decimationFactor; | 77 int m_decimationFactor; |
51 | 78 |
52 // Decimator (fixed) | 79 // Decimator (fixed) |
53 Decimator* m_decimator; | 80 Decimator* m_decimator; |
54 | |
55 // Chroma configuration | |
56 ChromaConfig m_chromaConfig; | |
57 | 81 |
58 // Chromagram object | 82 // Chromagram object |
59 Chromagram* m_chroma; | 83 Chromagram* m_chroma; |
60 | 84 |
61 // Chromagram output pointer | 85 // Chromagram output pointer |