Mercurial > hg > nnls-chroma
comparison NNLSChroma.cpp @ 117:5f3d3ea6aab6 monophonicness
rename variables for better readability
author | Matthias Mauch <mail@matthiasmauch.net> |
---|---|
date | Thu, 31 Mar 2011 14:37:06 +0100 |
parents | 9f7ba52207dc |
children | c4d1208e5ea9 |
comparison
equal
deleted
inserted
replaced
116:9f7ba52207dc | 117:5f3d3ea6aab6 |
---|---|
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 int index = 0; | 79 int index = 0; |
80 | 80 |
81 OutputDescriptor d1; | 81 OutputDescriptor logfreqspecOutput; |
82 d1.identifier = "logfreqspec"; | 82 logfreqspecOutput.identifier = "logfreqspec"; |
83 d1.name = "Log-Frequency Spectrum"; | 83 logfreqspecOutput.name = "Log-Frequency Spectrum"; |
84 d1.description = "A Log-Frequency Spectrum (constant Q) that is obtained by cosine filter mapping."; | 84 logfreqspecOutput.description = "A Log-Frequency Spectrum (constant Q) that is obtained by cosine filter mapping."; |
85 d1.unit = ""; | 85 logfreqspecOutput.unit = ""; |
86 d1.hasFixedBinCount = true; | 86 logfreqspecOutput.hasFixedBinCount = true; |
87 d1.binCount = nNote; | 87 logfreqspecOutput.binCount = nNote; |
88 d1.hasKnownExtents = false; | 88 logfreqspecOutput.hasKnownExtents = false; |
89 d1.isQuantized = false; | 89 logfreqspecOutput.isQuantized = false; |
90 d1.sampleType = OutputDescriptor::FixedSampleRate; | 90 logfreqspecOutput.sampleType = OutputDescriptor::FixedSampleRate; |
91 d1.hasDuration = false; | 91 logfreqspecOutput.hasDuration = false; |
92 d1.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; | 92 logfreqspecOutput.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; |
93 list.push_back(d1); | 93 list.push_back(logfreqspecOutput); |
94 m_outputLogSpec = index++; | 94 m_outputLogfreqspec = index++; |
95 | 95 |
96 OutputDescriptor d2; | 96 OutputDescriptor tunedlogfreqspecOutput; |
97 d2.identifier = "tunedlogfreqspec"; | 97 tunedlogfreqspecOutput.identifier = "tunedlogfreqspec"; |
98 d2.name = "Tuned Log-Frequency Spectrum"; | 98 tunedlogfreqspecOutput.name = "Tuned Log-Frequency Spectrum"; |
99 d2.description = "A Log-Frequency Spectrum (constant Q) that is obtained by cosine filter mapping, then its tuned using the estimated tuning frequency."; | 99 tunedlogfreqspecOutput.description = "A Log-Frequency Spectrum (constant Q) that is obtained by cosine filter mapping, then its tuned using the estimated tuning frequency."; |
100 d2.unit = ""; | 100 tunedlogfreqspecOutput.unit = ""; |
101 d2.hasFixedBinCount = true; | 101 tunedlogfreqspecOutput.hasFixedBinCount = true; |
102 d2.binCount = nNote; | 102 tunedlogfreqspecOutput.binCount = nNote; |
103 d2.hasKnownExtents = false; | 103 tunedlogfreqspecOutput.hasKnownExtents = false; |
104 d2.isQuantized = false; | 104 tunedlogfreqspecOutput.isQuantized = false; |
105 d2.sampleType = OutputDescriptor::FixedSampleRate; | 105 tunedlogfreqspecOutput.sampleType = OutputDescriptor::FixedSampleRate; |
106 d2.hasDuration = false; | 106 tunedlogfreqspecOutput.hasDuration = false; |
107 d2.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; | 107 tunedlogfreqspecOutput.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; |
108 list.push_back(d2); | 108 list.push_back(tunedlogfreqspecOutput); |
109 m_outputTunedSpec = index++; | 109 m_outputTunedlogfreqspec = index++; |
110 | 110 |
111 OutputDescriptor d3; | 111 OutputDescriptor semitonespectrumOutput; |
112 d3.identifier = "semitonespectrum"; | 112 semitonespectrumOutput.identifier = "semitonespectrum"; |
113 d3.name = "Semitone Spectrum"; | 113 semitonespectrumOutput.name = "Semitone Spectrum"; |
114 d3.description = "A semitone-spaced log-frequency spectrum derived from the third-of-a-semitone-spaced tuned log-frequency spectrum."; | 114 semitonespectrumOutput.description = "A semitone-spaced log-frequency spectrum derived from the third-of-a-semitone-spaced tuned log-frequency spectrum."; |
115 d3.unit = ""; | 115 semitonespectrumOutput.unit = ""; |
116 d3.hasFixedBinCount = true; | 116 semitonespectrumOutput.hasFixedBinCount = true; |
117 d3.binCount = 84; | 117 semitonespectrumOutput.binCount = 84; |
118 d3.hasKnownExtents = false; | 118 semitonespectrumOutput.hasKnownExtents = false; |
119 d3.isQuantized = false; | 119 semitonespectrumOutput.isQuantized = false; |
120 d3.sampleType = OutputDescriptor::FixedSampleRate; | 120 semitonespectrumOutput.sampleType = OutputDescriptor::FixedSampleRate; |
121 d3.hasDuration = false; | 121 semitonespectrumOutput.hasDuration = false; |
122 d3.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; | 122 semitonespectrumOutput.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; |
123 list.push_back(d3); | 123 list.push_back(semitonespectrumOutput); |
124 m_outputSemiSpec = index++; | 124 m_outputSemitonespectrum = index++; |
125 | 125 |
126 OutputDescriptor d4; | 126 OutputDescriptor chromaOutput; |
127 d4.identifier = "chroma"; | 127 chromaOutput.identifier = "chroma"; |
128 d4.name = "Chromagram"; | 128 chromaOutput.name = "Chromagram"; |
129 d4.description = "Tuning-adjusted chromagram from NNLS approximate transcription, with an emphasis on the medium note range."; | 129 chromaOutput.description = "Tuning-adjusted chromagram from NNLS approximate transcription, with an emphasis on the medium note range."; |
130 d4.unit = ""; | 130 chromaOutput.unit = ""; |
131 d4.hasFixedBinCount = true; | 131 chromaOutput.hasFixedBinCount = true; |
132 d4.binCount = 12; | 132 chromaOutput.binCount = 12; |
133 d4.binNames = chromanames; | 133 chromaOutput.binNames = chromanames; |
134 d4.hasKnownExtents = false; | 134 chromaOutput.hasKnownExtents = false; |
135 d4.isQuantized = false; | 135 chromaOutput.isQuantized = false; |
136 d4.sampleType = OutputDescriptor::FixedSampleRate; | 136 chromaOutput.sampleType = OutputDescriptor::FixedSampleRate; |
137 d4.hasDuration = false; | 137 chromaOutput.hasDuration = false; |
138 d4.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; | 138 chromaOutput.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; |
139 list.push_back(d4); | 139 list.push_back(chromaOutput); |
140 m_outputChroma = index++; | 140 m_outputChroma = index++; |
141 | 141 |
142 OutputDescriptor basschromaOutput; | 142 OutputDescriptor basschromaOutput; |
143 basschromaOutput.identifier = "basschroma"; | 143 basschromaOutput.identifier = "basschroma"; |
144 basschromaOutput.name = "Bass Chromagram"; | 144 basschromaOutput.name = "Bass Chromagram"; |
151 basschromaOutput.isQuantized = false; | 151 basschromaOutput.isQuantized = false; |
152 basschromaOutput.sampleType = OutputDescriptor::FixedSampleRate; | 152 basschromaOutput.sampleType = OutputDescriptor::FixedSampleRate; |
153 basschromaOutput.hasDuration = false; | 153 basschromaOutput.hasDuration = false; |
154 basschromaOutput.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; | 154 basschromaOutput.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; |
155 list.push_back(basschromaOutput); | 155 list.push_back(basschromaOutput); |
156 m_outputBassChroma = index++; | 156 m_outputBasschroma = index++; |
157 | 157 |
158 OutputDescriptor bothchromaOutput; | 158 OutputDescriptor bothchromaOutput; |
159 bothchromaOutput.identifier = "bothchroma"; | 159 bothchromaOutput.identifier = "bothchroma"; |
160 bothchromaOutput.name = "Chromagram and Bass Chromagram"; | 160 bothchromaOutput.name = "Chromagram and Bass Chromagram"; |
161 bothchromaOutput.description = "Tuning-adjusted chromagram and bass chromagram (stacked on top of each other) from NNLS approximate transcription."; | 161 bothchromaOutput.description = "Tuning-adjusted chromagram and bass chromagram (stacked on top of each other) from NNLS approximate transcription."; |
167 bothchromaOutput.isQuantized = false; | 167 bothchromaOutput.isQuantized = false; |
168 bothchromaOutput.sampleType = OutputDescriptor::FixedSampleRate; | 168 bothchromaOutput.sampleType = OutputDescriptor::FixedSampleRate; |
169 bothchromaOutput.hasDuration = false; | 169 bothchromaOutput.hasDuration = false; |
170 bothchromaOutput.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; | 170 bothchromaOutput.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; |
171 list.push_back(bothchromaOutput); | 171 list.push_back(bothchromaOutput); |
172 m_outputBothChroma = index++; | 172 m_outputBothchroma = index++; |
173 | 173 |
174 OutputDescriptor consonanceOutput; | 174 OutputDescriptor consonanceOutput; |
175 consonanceOutput.identifier = "consonance"; | 175 consonanceOutput.identifier = "consonance"; |
176 consonanceOutput.name = "Consonance estimate."; | 176 consonanceOutput.name = "Consonance estimate."; |
177 consonanceOutput.description = "A simple consonance value based on the convolution of a consonance profile with the semitone spectrum."; | 177 consonanceOutput.description = "A simple consonance value based on the convolution of a consonance profile with the semitone spectrum."; |
234 if (debug_on) cerr << "--> process" << endl; | 234 if (debug_on) cerr << "--> process" << endl; |
235 | 235 |
236 NNLSBase::baseProcess(inputBuffers, timestamp); | 236 NNLSBase::baseProcess(inputBuffers, timestamp); |
237 | 237 |
238 FeatureSet fs; | 238 FeatureSet fs; |
239 fs[m_outputLogSpec].push_back(m_logSpectrum[m_logSpectrum.size()-1]); | 239 fs[m_outputLogfreqspec].push_back(m_logSpectrum[m_logSpectrum.size()-1]); |
240 return fs; | 240 return fs; |
241 } | 241 } |
242 | 242 |
243 NNLSChroma::FeatureSet | 243 NNLSChroma::FeatureSet |
244 NNLSChroma::getRemainingFeatures() | 244 NNLSChroma::getRemainingFeatures() |
331 } | 331 } |
332 if (f2.values[i] < 0) { | 332 if (f2.values[i] < 0) { |
333 cerr << "ERROR: negative value in logfreq spectrum" << endl; | 333 cerr << "ERROR: negative value in logfreq spectrum" << endl; |
334 } | 334 } |
335 } | 335 } |
336 fsOut[m_outputTunedSpec].push_back(f2); | 336 fsOut[m_outputTunedlogfreqspec].push_back(f2); |
337 count++; | 337 count++; |
338 } | 338 } |
339 cerr << "done." << endl; | 339 cerr << "done." << endl; |
340 | 340 |
341 /** Semitone spectrum and chromagrams | 341 /** Semitone spectrum and chromagrams |
353 | 353 |
354 vector<float> oldchroma = vector<float>(12,0); | 354 vector<float> oldchroma = vector<float>(12,0); |
355 vector<float> oldbasschroma = vector<float>(12,0); | 355 vector<float> oldbasschroma = vector<float>(12,0); |
356 count = 0; | 356 count = 0; |
357 | 357 |
358 for (FeatureList::iterator it = fsOut[m_outputTunedSpec].begin(); it != fsOut[m_outputTunedSpec].end(); ++it) { | 358 for (FeatureList::iterator it = fsOut[m_outputTunedlogfreqspec].begin(); it != fsOut[m_outputTunedlogfreqspec].end(); ++it) { |
359 Feature f2 = *it; // logfreq spectrum | 359 Feature f2 = *it; // logfreq spectrum |
360 Feature f3; // semitone spectrum | 360 Feature f3; // semitone spectrum |
361 Feature f4; // treble chromagram | 361 Feature f4; // treble chromagram |
362 Feature f5; // bass chromagram | 362 Feature f5; // bass chromagram |
363 Feature f6; // treble and bass chromagram | 363 Feature f6; // treble and bass chromagram |
553 f6.values[i] /= chromanorm[2]; | 553 f6.values[i] /= chromanorm[2]; |
554 } | 554 } |
555 } | 555 } |
556 } | 556 } |
557 | 557 |
558 fsOut[m_outputSemiSpec].push_back(f3); | 558 fsOut[m_outputSemitonespectrum].push_back(f3); |
559 fsOut[m_outputChroma].push_back(f4); | 559 fsOut[m_outputChroma].push_back(f4); |
560 fsOut[m_outputBassChroma].push_back(f5); | 560 fsOut[m_outputBasschroma].push_back(f5); |
561 fsOut[m_outputBothChroma].push_back(f6); | 561 fsOut[m_outputBothchroma].push_back(f6); |
562 fsOut[m_outputConsonance].push_back(consonance); | 562 fsOut[m_outputConsonance].push_back(consonance); |
563 fsOut[m_outputMonophonicness].push_back(monophonicness); | 563 fsOut[m_outputMonophonicness].push_back(monophonicness); |
564 count++; | 564 count++; |
565 } | 565 } |
566 cerr << "done." << endl; | 566 cerr << "done." << endl; |