Mercurial > hg > qm-dsp
comparison dsp/chromagram/Chromagram.cpp @ 483:fdaa63607c15
Untabify, indent, tidy
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Fri, 31 May 2019 11:54:32 +0100 |
parents | a72d98f8baa3 |
children | 1bea13b8f951 |
comparison
equal
deleted
inserted
replaced
482:cbe668c7d724 | 483:fdaa63607c15 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ |
2 | |
3 /* | 2 /* |
4 QM DSP Library | 3 QM DSP Library |
5 | 4 |
6 Centre for Digital Music, Queen Mary, University of London. | 5 Centre for Digital Music, Queen Mary, University of London. |
7 This file 2005-2006 Christian Landone. | 6 This file 2005-2006 Christian Landone. |
25 { | 24 { |
26 initialise( Config ); | 25 initialise( Config ); |
27 } | 26 } |
28 | 27 |
29 int Chromagram::initialise( ChromaConfig Config ) | 28 int Chromagram::initialise( ChromaConfig Config ) |
30 { | 29 { |
31 m_FMin = Config.min; // min freq | 30 m_FMin = Config.min; // min freq |
32 m_FMax = Config.max; // max freq | 31 m_FMax = Config.max; // max freq |
33 m_BPO = Config.BPO; // bins per octave | 32 m_BPO = Config.BPO; // bins per octave |
34 m_normalise = Config.normalise; // if frame normalisation is required | 33 m_normalise = Config.normalise; // if frame normalisation is required |
35 | 34 |
36 // Extend range to a full octave | 35 // Extend range to a full octave |
37 double octaves = log(m_FMax / m_FMin) / log(2.0); | 36 double octaves = log(m_FMax / m_FMin) / log(2.0); |
38 m_FMax = m_FMin * pow(2.0, ceil(octaves)); | 37 m_FMax = m_FMin * pow(2.0, ceil(octaves)); |
48 ConstantQConfig.FS = Config.FS; | 47 ConstantQConfig.FS = Config.FS; |
49 ConstantQConfig.min = m_FMin; | 48 ConstantQConfig.min = m_FMin; |
50 ConstantQConfig.max = m_FMax; | 49 ConstantQConfig.max = m_FMax; |
51 ConstantQConfig.BPO = m_BPO; | 50 ConstantQConfig.BPO = m_BPO; |
52 ConstantQConfig.CQThresh = Config.CQThresh; | 51 ConstantQConfig.CQThresh = Config.CQThresh; |
53 | 52 |
54 // Initialise ConstantQ operator | 53 // Initialise ConstantQ operator |
55 m_ConstantQ = new ConstantQ( ConstantQConfig ); | 54 m_ConstantQ = new ConstantQ( ConstantQConfig ); |
56 | 55 |
57 // No. of constant Q bins | 56 // No. of constant Q bins |
58 m_uK = m_ConstantQ->getK(); | 57 m_uK = m_ConstantQ->getK(); |
59 | 58 |
60 // Initialise working arrays | 59 // Initialise working arrays |
61 m_frameSize = m_ConstantQ->getfftlength(); | 60 m_frameSize = m_ConstantQ->getfftlength(); |
62 m_hopSize = m_ConstantQ->gethop(); | 61 m_hopSize = m_ConstantQ->gethop(); |
63 | 62 |
64 // Initialise FFT object | 63 // Initialise FFT object |
65 m_FFT = new FFTReal(m_frameSize); | 64 m_FFT = new FFTReal(m_frameSize); |
66 | 65 |
67 m_FFTRe = new double[ m_frameSize ]; | 66 m_FFTRe = new double[ m_frameSize ]; |
68 m_FFTIm = new double[ m_frameSize ]; | 67 m_FFTIm = new double[ m_frameSize ]; |
69 m_CQRe = new double[ m_uK ]; | 68 m_CQRe = new double[ m_uK ]; |
109 | 108 |
110 | 109 |
111 void Chromagram::unityNormalise(double *src) | 110 void Chromagram::unityNormalise(double *src) |
112 { | 111 { |
113 double min, max; | 112 double min, max; |
114 | |
115 double val = 0; | 113 double val = 0; |
116 | 114 |
117 MathUtilities::getFrameMinMax( src, m_BPO, & min, &max ); | 115 MathUtilities::getFrameMinMax( src, m_BPO, & min, &max ); |
118 | 116 |
119 for (int i = 0; i < m_BPO; i++) | 117 for (int i = 0; i < m_BPO; i++) { |
120 { | 118 val = src[ i ] / max; |
121 val = src[ i ] / max; | 119 src[ i ] = val; |
122 | |
123 src[ i ] = val; | |
124 } | 120 } |
125 } | 121 } |
126 | 122 |
127 | 123 |
128 double *Chromagram::process(const double *data) | 124 double *Chromagram::process(const double *data) |
167 // initialise chromadata to 0 | 163 // initialise chromadata to 0 |
168 for (int i = 0; i < m_BPO; i++) m_chromadata[i] = 0; | 164 for (int i = 0; i < m_BPO; i++) m_chromadata[i] = 0; |
169 | 165 |
170 // Calculate ConstantQ frame | 166 // Calculate ConstantQ frame |
171 m_ConstantQ->process( real, imag, m_CQRe, m_CQIm ); | 167 m_ConstantQ->process( real, imag, m_CQRe, m_CQIm ); |
172 | 168 |
173 // add each octave of cq data into Chromagram | 169 // add each octave of cq data into Chromagram |
174 const int octaves = m_uK / m_BPO; | 170 const int octaves = m_uK / m_BPO; |
175 for (int octave = 0; octave < octaves; octave++) | 171 for (int octave = 0; octave < octaves; octave++) { |
176 { | 172 int firstBin = octave*m_BPO; |
177 int firstBin = octave*m_BPO; | 173 for (int i = 0; i < m_BPO; i++) { |
178 for (int i = 0; i < m_BPO; i++) | 174 m_chromadata[i] += kabs( m_CQRe[ firstBin + i ], |
179 { | 175 m_CQIm[ firstBin + i ]); |
180 m_chromadata[i] += kabs( m_CQRe[ firstBin + i ], m_CQIm[ firstBin + i ]); | 176 } |
181 } | |
182 } | 177 } |
183 | 178 |
184 MathUtilities::normalise(m_chromadata, m_BPO, m_normalise); | 179 MathUtilities::normalise(m_chromadata, m_BPO, m_normalise); |
185 | 180 |
186 return m_chromadata; | 181 return m_chromadata; |