Mercurial > hg > qm-dsp
comparison tests/TestChromagram.cpp @ 467:1db23b9a8da4
Fix mismatch between time- and frequency-domain versions of the
chromagram process method - the frequency-domain one expects fftshifted
input and the kernel is set up for that, but the time-domain one wasn't
doing it
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Wed, 29 May 2019 15:56:30 +0100 |
parents | 50a97c8d52ed |
children | dd132354ea02 |
comparison
equal
deleted
inserted
replaced
466:46375e6d1b54 | 467:1db23b9a8da4 |
---|---|
32 vector<double> generateSinusoid(double frequency, | 32 vector<double> generateSinusoid(double frequency, |
33 double sampleRate, | 33 double sampleRate, |
34 int length) | 34 int length) |
35 { | 35 { |
36 vector<double> buffer; | 36 vector<double> buffer; |
37 buffer.reserve(length); | |
38 for (int i = 0; i < length; ++i) { | 37 for (int i = 0; i < length; ++i) { |
39 buffer.push_back(sin((i * M_PI * 2.0 * frequency) / sampleRate)); | 38 buffer.push_back(sin((i * M_PI * 2.0 * frequency) / sampleRate)); |
40 } | 39 } |
41 | |
42 return buffer; | 40 return buffer; |
43 } | 41 } |
44 | 42 |
45 double frequencyForPitch(int midiPitch, double concertA) | 43 double frequencyForPitch(int midiPitch, double concertA) |
46 { | 44 { |
48 } | 46 } |
49 | 47 |
50 BOOST_AUTO_TEST_CASE(sinusoid_12tET) | 48 BOOST_AUTO_TEST_CASE(sinusoid_12tET) |
51 { | 49 { |
52 double concertA = 440.0; | 50 double concertA = 440.0; |
53 double sampleRate = 44100; | 51 double sampleRate = 44100.0; |
54 int bpo = 60; | 52 int bpo = 60; |
55 | 53 |
56 ChromaConfig config { | 54 ChromaConfig config { |
57 sampleRate, | 55 sampleRate, |
58 frequencyForPitch(36, concertA), | 56 frequencyForPitch(36, concertA), |
83 << expectedPeakBin << endl; | 81 << expectedPeakBin << endl; |
84 | 82 |
85 vector<double> signal = generateSinusoid(frequency, | 83 vector<double> signal = generateSinusoid(frequency, |
86 sampleRate, | 84 sampleRate, |
87 blockSize); | 85 blockSize); |
88 | 86 |
89 double *output = chroma.process(signal.data()); | 87 double *output = chroma.process(signal.data()); |
90 | 88 |
91 int peakBin = -1; | 89 int peakBin = -1; |
92 double peakValue = 0.0; | 90 double peakValue = 0.0; |
93 | 91 |
105 << (peakBin+1 < bpo ? output[peakBin+1] : output[0]) | 103 << (peakBin+1 < bpo ? output[peakBin+1] : output[0]) |
106 << ")" << endl; | 104 << ")" << endl; |
107 | 105 |
108 if (peakBin != expectedPeakBin) { | 106 if (peakBin != expectedPeakBin) { |
109 cout << "NOTE: peak bin " << peakBin << " does not match expected " << expectedPeakBin << endl; | 107 cout << "NOTE: peak bin " << peakBin << " does not match expected " << expectedPeakBin << endl; |
108 cout << "bin values are: "; | |
109 for (int i = 0; i < bpo; ++i) { | |
110 cout << i << ": " << output[i] << " "; | |
111 } | |
112 cout << endl; | |
110 } | 113 } |
111 } | 114 } |
112 } | 115 } |
113 | 116 |
114 BOOST_AUTO_TEST_SUITE_END() | 117 BOOST_AUTO_TEST_SUITE_END() |