Mercurial > hg > nnls-chroma
changeset 35:cf8898a0174c matthiasm-plugin
* Split out NNLSChroma plugin into three plugins (chroma, chordino, tuning) with a common base class.
There's still quite a lot of duplication between the getRemainingFeatures functions.
Also add copyright / copying headers, etc.
author | Chris Cannam |
---|---|
date | Fri, 22 Oct 2010 11:30:21 +0100 |
parents | 8edcf48f4031 |
children | 7409ab74c63b |
files | COPYING Chordino.cpp Chordino.h Makefile Makefile.cc-linux NNLSBase.cpp NNLSBase.h NNLSChroma.cpp NNLSChroma.h Tuning.cpp Tuning.h chromamethods.cpp chromamethods.h nnls.c plugins.cpp |
diffstat | 15 files changed, 2391 insertions(+), 913 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/COPYING Fri Oct 22 11:30:21 2010 +0100 @@ -0,0 +1,280 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Chordino.cpp Fri Oct 22 11:30:21 2010 +0100 @@ -0,0 +1,541 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + NNLS-Chroma / Chordino + + Audio feature extraction plugins for chromagram and chord + estimation. + + Centre for Digital Music, Queen Mary University of London. + This file copyright 2008-2010 Matthias Mauch and QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include "Chordino.h" + +#include "chromamethods.h" + +#include <cstdlib> +#include <fstream> +#include <cmath> + +#include <algorithm> + +const bool debug_on = false; + +const vector<float> hw(hammingwind, hammingwind+19); + +Chordino::Chordino(float inputSampleRate) : + NNLSBase(inputSampleRate) +{ + if (debug_on) cerr << "--> Chordino" << endl; +} + +Chordino::~Chordino() +{ + if (debug_on) cerr << "--> ~Chordino" << endl; +} + +string +Chordino::getIdentifier() const +{ + if (debug_on) cerr << "--> getIdentifier" << endl; + return "chordino"; +} + +string +Chordino::getName() const +{ + if (debug_on) cerr << "--> getName" << endl; + return "Chordino"; +} + +string +Chordino::getDescription() const +{ + if (debug_on) cerr << "--> getDescription" << endl; + return "This plugin provides a number of features derived from a log-frequency amplitude spectrum of the DFT: some variants of the log-frequency spectrum, including a semitone spectrum derived from approximate transcription using the NNLS algorithm; based on this semitone spectrum, chroma features and a simple chord estimate."; +} + +Chordino::OutputList +Chordino::getOutputDescriptors() const +{ + if (debug_on) cerr << "--> getOutputDescriptors" << endl; + OutputList list; + + int index = 0; + + OutputDescriptor d7; + d7.identifier = "simplechord"; + d7.name = "Simple Chord Estimate"; + d7.description = "A simple chord estimate based on the inner product of chord templates with the smoothed chroma."; + d7.unit = ""; + d7.hasFixedBinCount = true; + d7.binCount = 0; + d7.hasKnownExtents = false; + d7.isQuantized = false; + d7.sampleType = OutputDescriptor::VariableSampleRate; + d7.hasDuration = false; + d7.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; + list.push_back(d7); + m_outputChords = index++; + + OutputDescriptor d8; + d8.identifier = "harmonicchange"; + d8.name = "Harmonic change value"; + d8.description = "Harmonic change."; + d8.unit = ""; + d8.hasFixedBinCount = true; + d8.binCount = 1; + d8.hasKnownExtents = true; + d8.minValue = 0.0; + d8.maxValue = 0.999; + d8.isQuantized = false; + d8.sampleType = OutputDescriptor::FixedSampleRate; + d8.hasDuration = false; + // d8.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; + list.push_back(d8); + m_outputHarmonicChange = index++; + + return list; +} + +bool +Chordino::initialise(size_t channels, size_t stepSize, size_t blockSize) +{ + if (debug_on) { + cerr << "--> initialise"; + } + + if (!NNLSBase::initialise(channels, stepSize, blockSize)) { + return false; + } + + return true; +} + +void +Chordino::reset() +{ + if (debug_on) cerr << "--> reset"; + NNLSBase::reset(); +} + +Chordino::FeatureSet +Chordino::process(const float *const *inputBuffers, Vamp::RealTime timestamp) +{ + if (debug_on) cerr << "--> process" << endl; + + NNLSBase::baseProcess(inputBuffers, timestamp); + + return FeatureSet(); +} + +Chordino::FeatureSet +Chordino::getRemainingFeatures() +{ + if (debug_on) cerr << "--> getRemainingFeatures" << endl; + FeatureSet fsOut; + if (m_logSpectrum.size() == 0) return fsOut; + int nChord = m_chordnames.size(); + // + /** Calculate Tuning + calculate tuning from (using the angle of the complex number defined by the + cumulative mean real and imag values) + **/ + float meanTuningImag = sinvalue * m_meanTuning1 - sinvalue * m_meanTuning2; + float meanTuningReal = m_meanTuning0 + cosvalue * m_meanTuning1 + cosvalue * m_meanTuning2; + float cumulativetuning = 440 * pow(2,atan2(meanTuningImag, meanTuningReal)/(24*M_PI)); + float normalisedtuning = atan2(meanTuningImag, meanTuningReal)/(2*M_PI); + int intShift = floor(normalisedtuning * 3); + float intFactor = normalisedtuning * 3 - intShift; // intFactor is a really bad name for this + + char buffer0 [50]; + + sprintf(buffer0, "estimated tuning: %0.1f Hz", cumulativetuning); + + + /** Tune Log-Frequency Spectrogram + calculate a tuned log-frequency spectrogram (f2): use the tuning estimated above (kinda f0) to + perform linear interpolation on the existing log-frequency spectrogram (kinda f1). + **/ + cerr << endl << "[Chordino Plugin] Tuning Log-Frequency Spectrogram ... "; + + float tempValue = 0; + float dbThreshold = 0; // relative to the background spectrum + float thresh = pow(10,dbThreshold/20); + // cerr << "tune local ? " << m_tuneLocal << endl; + int count = 0; + + FeatureList tunedSpec; + + for (FeatureList::iterator i = m_logSpectrum.begin(); i != m_logSpectrum.end(); ++i) { + Feature f1 = *i; + Feature f2; // tuned log-frequency spectrum + f2.hasTimestamp = true; + f2.timestamp = f1.timestamp; + f2.values.push_back(0.0); f2.values.push_back(0.0); // set lower edge to zero + + if (m_tuneLocal) { + intShift = floor(m_localTuning[count] * 3); + intFactor = m_localTuning[count] * 3 - intShift; // intFactor is a really bad name for this + } + + // cerr << intShift << " " << intFactor << endl; + + for (unsigned k = 2; k < f1.values.size() - 3; ++k) { // interpolate all inner bins + tempValue = f1.values[k + intShift] * (1-intFactor) + f1.values[k+intShift+1] * intFactor; + f2.values.push_back(tempValue); + } + + f2.values.push_back(0.0); f2.values.push_back(0.0); f2.values.push_back(0.0); // upper edge + vector<float> runningmean = SpecialConvolution(f2.values,hw); + vector<float> runningstd; + for (int i = 0; i < 256; i++) { // first step: squared values into vector (variance) + runningstd.push_back((f2.values[i] - runningmean[i]) * (f2.values[i] - runningmean[i])); + } + runningstd = SpecialConvolution(runningstd,hw); // second step convolve + for (int i = 0; i < 256; i++) { + runningstd[i] = sqrt(runningstd[i]); // square root to finally have running std + if (runningstd[i] > 0) { + // f2.values[i] = (f2.values[i] / runningmean[i]) > thresh ? + // (f2.values[i] - runningmean[i]) / pow(runningstd[i],m_paling) : 0; + f2.values[i] = (f2.values[i] - runningmean[i]) > 0 ? + (f2.values[i] - runningmean[i]) / pow(runningstd[i],m_paling) : 0; + } + if (f2.values[i] < 0) { + cerr << "ERROR: negative value in logfreq spectrum" << endl; + } + } + tunedSpec.push_back(f2); + count++; + } + cerr << "done." << endl; + + /** Semitone spectrum and chromagrams + Semitone-spaced log-frequency spectrum derived from the tuned log-freq spectrum above. the spectrum + is inferred using a non-negative least squares algorithm. + Three different kinds of chromagram are calculated, "treble", "bass", and "both" (which means + bass and treble stacked onto each other). + **/ + if (m_dictID == 1) { + cerr << "[Chordino Plugin] Mapping to semitone spectrum and chroma ... "; + } else { + cerr << "[Chordino Plugin] Performing NNLS and mapping to chroma ... "; + } + + + vector<vector<float> > chordogram; + vector<vector<int> > scoreChordogram; + vector<float> chordchange = vector<float>(tunedSpec.size(),0); + count = 0; + + FeatureList chromaList; + + for (FeatureList::iterator it = tunedSpec.begin(); it != tunedSpec.end(); ++it) { + Feature f2 = *it; // logfreq spectrum + Feature f6; // treble and bass chromagram + + f6.hasTimestamp = true; + f6.timestamp = f2.timestamp; + + float b[256]; + + bool some_b_greater_zero = false; + float sumb = 0; + for (int i = 0; i < 256; i++) { + // b[i] = m_dict[(256 * count + i) % (256 * 84)]; + b[i] = f2.values[i]; + sumb += b[i]; + if (b[i] > 0) { + some_b_greater_zero = true; + } + } + + // here's where the non-negative least squares algorithm calculates the note activation x + + vector<float> chroma = vector<float>(12, 0); + vector<float> basschroma = vector<float>(12, 0); + float currval; + unsigned iSemitone = 0; + + if (some_b_greater_zero) { + if (m_dictID == 1) { + for (unsigned iNote = 2; iNote < nNote - 2; iNote += 3) { + currval = 0; + currval += b[iNote + 1 + -1] * 0.5; + currval += b[iNote + 1 + 0] * 1.0; + currval += b[iNote + 1 + 1] * 0.5; + chroma[iSemitone % 12] += currval * treblewindow[iSemitone]; + basschroma[iSemitone % 12] += currval * basswindow[iSemitone]; + iSemitone++; + } + + } else { + float x[84+1000]; + for (int i = 1; i < 1084; ++i) x[i] = 1.0; + vector<int> signifIndex; + int index=0; + sumb /= 84.0; + for (unsigned iNote = 2; iNote < nNote - 2; iNote += 3) { + float currval = 0; + currval += b[iNote + 1 + -1]; + currval += b[iNote + 1 + 0]; + currval += b[iNote + 1 + 1]; + if (currval > 0) signifIndex.push_back(index); + index++; + } + float rnorm; + float w[84+1000]; + float zz[84+1000]; + int indx[84+1000]; + int mode; + int dictsize = 256*signifIndex.size(); + float *curr_dict = new float[dictsize]; + for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { + for (unsigned iBin = 0; iBin < 256; iBin++) { + curr_dict[iNote * 256 + iBin] = 1.0 * m_dict[signifIndex[iNote] * 256 + iBin]; + } + } + nnls(curr_dict, nNote, nNote, signifIndex.size(), b, x, &rnorm, w, zz, indx, &mode); + delete [] curr_dict; + for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { + // cerr << mode << endl; + chroma[signifIndex[iNote] % 12] += x[iNote] * treblewindow[signifIndex[iNote]]; + basschroma[signifIndex[iNote] % 12] += x[iNote] * basswindow[signifIndex[iNote]]; + } + } + } + + vector<float> origchroma = chroma; + chroma.insert(chroma.begin(), basschroma.begin(), basschroma.end()); // just stack the both chromas + f6.values = chroma; + + if (m_doNormalizeChroma > 0) { + vector<float> chromanorm = vector<float>(3,0); + switch (int(m_doNormalizeChroma)) { + case 0: // should never end up here + break; + case 1: + chromanorm[0] = *max_element(origchroma.begin(), origchroma.end()); + chromanorm[1] = *max_element(basschroma.begin(), basschroma.end()); + chromanorm[2] = max(chromanorm[0], chromanorm[1]); + break; + case 2: + for (vector<float>::iterator it = chroma.begin(); it != chroma.end(); ++it) { + chromanorm[2] += *it; + } + break; + case 3: + for (vector<float>::iterator it = chroma.begin(); it != chroma.end(); ++it) { + chromanorm[2] += pow(*it,2); + } + chromanorm[2] = sqrt(chromanorm[2]); + break; + } + if (chromanorm[2] > 0) { + for (int i = 0; i < chroma.size(); i++) { + f6.values[i] /= chromanorm[2]; + } + } + } + + chromaList.push_back(f6); + + // local chord estimation + vector<float> currentChordSalience; + float tempchordvalue = 0; + float sumchordvalue = 0; + + for (int iChord = 0; iChord < nChord; iChord++) { + tempchordvalue = 0; + for (int iBin = 0; iBin < 12; iBin++) { + tempchordvalue += m_chorddict[24 * iChord + iBin] * chroma[iBin]; + } + for (int iBin = 12; iBin < 24; iBin++) { + tempchordvalue += m_chorddict[24 * iChord + iBin] * chroma[iBin]; + } + sumchordvalue+=tempchordvalue; + currentChordSalience.push_back(tempchordvalue); + } + if (sumchordvalue > 0) { + for (int iChord = 0; iChord < nChord; iChord++) { + currentChordSalience[iChord] /= sumchordvalue; + } + } else { + currentChordSalience[nChord-1] = 1.0; + } + chordogram.push_back(currentChordSalience); + + count++; + } + cerr << "done." << endl; + + + /* Simple chord estimation + I just take the local chord estimates ("currentChordSalience") and average them over time, then + take the maximum. Very simple, don't do this at home... + */ + cerr << "[Chordino Plugin] Chord Estimation ... "; + count = 0; + int halfwindowlength = m_inputSampleRate / m_stepSize; + vector<int> chordSequence; + + for (FeatureList::iterator it = chromaList.begin(); it != chromaList.end(); ++it) { // initialise the score chordogram + vector<int> temp = vector<int>(nChord,0); + scoreChordogram.push_back(temp); + } + + for (FeatureList::iterator it = chromaList.begin(); it < chromaList.end()-2*halfwindowlength-1; ++it) { + int startIndex = count + 1; + int endIndex = count + 2 * halfwindowlength; + + float chordThreshold = 2.5/nChord;//*(2*halfwindowlength+1); + + vector<int> chordCandidates; + for (unsigned iChord = 0; iChord < nChord-1; iChord++) { + // float currsum = 0; + // for (unsigned iFrame = startIndex; iFrame < endIndex; ++iFrame) { + // currsum += chordogram[iFrame][iChord]; + // } + // if (currsum > chordThreshold) chordCandidates.push_back(iChord); + for (unsigned iFrame = startIndex; iFrame < endIndex; ++iFrame) { + if (chordogram[iFrame][iChord] > chordThreshold) { + chordCandidates.push_back(iChord); + break; + } + } + } + chordCandidates.push_back(nChord-1); +// cerr << chordCandidates.size() << endl; + + float maxval = 0; // will be the value of the most salient *chord change* in this frame + float maxindex = 0; //... and the index thereof + unsigned bestchordL = nChord-1; // index of the best "left" chord + unsigned bestchordR = nChord-1; // index of the best "right" chord + + for (int iWF = 1; iWF < 2*halfwindowlength; ++iWF) { + // now find the max values on both sides of iWF + // left side: + float maxL = 0; + unsigned maxindL = nChord-1; + for (unsigned kChord = 0; kChord < chordCandidates.size(); kChord++) { + unsigned iChord = chordCandidates[kChord]; + float currsum = 0; + for (unsigned iFrame = 0; iFrame < iWF-1; ++iFrame) { + currsum += chordogram[count+iFrame][iChord]; + } + if (iChord == nChord-1) currsum *= 0.8; + if (currsum > maxL) { + maxL = currsum; + maxindL = iChord; + } + } + // right side: + float maxR = 0; + unsigned maxindR = nChord-1; + for (unsigned kChord = 0; kChord < chordCandidates.size(); kChord++) { + unsigned iChord = chordCandidates[kChord]; + float currsum = 0; + for (unsigned iFrame = iWF-1; iFrame < 2*halfwindowlength; ++iFrame) { + currsum += chordogram[count+iFrame][iChord]; + } + if (iChord == nChord-1) currsum *= 0.8; + if (currsum > maxR) { + maxR = currsum; + maxindR = iChord; + } + } + if (maxL+maxR > maxval) { + maxval = maxL+maxR; + maxindex = iWF; + bestchordL = maxindL; + bestchordR = maxindR; + } + + } +// cerr << "maxindex: " << maxindex << ", bestchordR is " << bestchordR << ", of frame " << count << endl; + // add a score to every chord-frame-point that was part of a maximum + for (unsigned iFrame = 0; iFrame < maxindex-1; ++iFrame) { + scoreChordogram[iFrame+count][bestchordL]++; + } + for (unsigned iFrame = maxindex-1; iFrame < 2*halfwindowlength; ++iFrame) { + scoreChordogram[iFrame+count][bestchordR]++; + } + if (bestchordL != bestchordR) chordchange[maxindex+count] += (halfwindowlength - abs(maxindex-halfwindowlength)) * 2.0 / halfwindowlength; + count++; + } +// cerr << "******* agent finished *******" << endl; + count = 0; + for (FeatureList::iterator it = chromaList.begin(); it != chromaList.end(); ++it) { + float maxval = 0; // will be the value of the most salient chord in this frame + float maxindex = 0; //... and the index thereof + for (unsigned iChord = 0; iChord < nChord; iChord++) { + if (scoreChordogram[count][iChord] > maxval) { + maxval = scoreChordogram[count][iChord]; + maxindex = iChord; + // cerr << iChord << endl; + } + } + chordSequence.push_back(maxindex); + // cerr << "before modefilter, maxindex: " << maxindex << endl; + count++; + } +// cerr << "******* mode filter done *******" << endl; + + + // mode filter on chordSequence + count = 0; + string oldChord = ""; + for (FeatureList::iterator it = chromaList.begin(); it != chromaList.end(); ++it) { + Feature f6 = *it; + Feature f7; // chord estimate + f7.hasTimestamp = true; + f7.timestamp = f6.timestamp; + Feature f8; // chord estimate + f8.hasTimestamp = true; + f8.timestamp = f6.timestamp; + + vector<int> chordCount = vector<int>(nChord,0); + int maxChordCount = 0; + int maxChordIndex = nChord-1; + string maxChord; + int startIndex = max(count - halfwindowlength/2,0); + int endIndex = min(int(chordogram.size()), count + halfwindowlength/2); + for (int i = startIndex; i < endIndex; i++) { + chordCount[chordSequence[i]]++; + if (chordCount[chordSequence[i]] > maxChordCount) { + // cerr << "start index " << startIndex << endl; + maxChordCount++; + maxChordIndex = chordSequence[i]; + maxChord = m_chordnames[maxChordIndex]; + } + } + // chordSequence[count] = maxChordIndex; + // cerr << maxChordIndex << endl; + f8.values.push_back(chordchange[count]/(halfwindowlength*2)); + // cerr << chordchange[count] << endl; + fsOut[m_outputHarmonicChange].push_back(f8); + if (oldChord != maxChord) { + oldChord = maxChord; + f7.label = m_chordnames[maxChordIndex]; + fsOut[m_outputChords].push_back(f7); + } + count++; + } + Feature f7; // last chord estimate + f7.hasTimestamp = true; + f7.timestamp = chromaList[chromaList.size()-1].timestamp; + f7.label = "N"; + fsOut[m_outputChords].push_back(f7); + cerr << "done." << endl; + + return fsOut; + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Chordino.h Fri Oct 22 11:30:21 2010 +0100 @@ -0,0 +1,53 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + NNLS-Chroma / Chordino + + Audio feature extraction plugins for chromagram and chord + estimation. + + Centre for Digital Music, Queen Mary University of London. + This file copyright 2008-2010 Matthias Mauch and QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef _CHORDINO_ +#define _CHORDINO_ + +#include "NNLSBase.h" + +using namespace std; + + +class Chordino : public NNLSBase +{ +public: + Chordino(float inputSampleRate); + virtual ~Chordino(); + + string getIdentifier() const; + string getName() const; + string getDescription() const; + + OutputList getOutputDescriptors() const; + + FeatureSet process(const float *const *inputBuffers, + Vamp::RealTime timestamp); + FeatureSet getRemainingFeatures(); + + bool initialise(size_t channels, size_t stepSize, size_t blockSize); + void reset(); + +protected: + mutable int m_outputChords; + mutable int m_outputHarmonicChange; +}; + + + +#endif
--- a/Makefile Fri Oct 22 16:19:40 2010 +0900 +++ b/Makefile Fri Oct 22 11:30:21 2010 +0100 @@ -2,13 +2,12 @@ # Edit this to list one .o file for each .cpp file in your plugin project # -PLUGIN_CODE_OBJECTS = NNLSChroma.o plugins.o nnls.o chromamethods.o +PLUGIN_CODE_OBJECTS = NNLSBase.o NNLSChroma.o Chordino.o Tuning.o plugins.o nnls.o chromamethods.o # Edit this to the location of the Vamp plugin SDK, relative to your # project directory # VAMP_SDK_DIR = ../vamp-plugin-sdk -QMDSP_DIR = ../qm-dsp/build/osx/20091028 BOOST_ROOT = ../boost_1_44_0 @@ -24,11 +23,21 @@ $(PLUGIN): $(PLUGIN_CODE_OBJECTS) $(CXX) -o $@ $^ $(LDFLAGS) -NNLSChroma.o: NNLSChroma.h -plugins.o: NNLSChroma.h - nnls.o: nnls.c # not nnls.f clean: rm -f *.o +# DO NOT DELETE + +nnls.o: nnls.h +Chordino.o: Chordino.h NNLSBase.h chromamethods.h nnls.h +chromamethods.o: chromamethods.h nnls.h chorddict.cpp +NNLSBase.o: NNLSBase.h chromamethods.h nnls.h +NNLSChroma.o: NNLSChroma.h NNLSBase.h chromamethods.h nnls.h +plugins.o: NNLSChroma.h NNLSBase.h Chordino.h Tuning.h +Tuning.o: Tuning.h NNLSBase.h chromamethods.h nnls.h +Chordino.o: NNLSBase.h +chromamethods.o: nnls.h +NNLSChroma.o: NNLSBase.h +Tuning.o: NNLSBase.h
--- a/Makefile.cc-linux Fri Oct 22 16:19:40 2010 +0900 +++ b/Makefile.cc-linux Fri Oct 22 11:30:21 2010 +0100 @@ -1,33 +1,13 @@ -## Skeleton Makefile for Vamp plugin builds using command-line tools. -## -## Rename this to Makefile, and edit as appropriate. -## This Makefile WILL NOT WORK until you have edited it as described -## below -- the Makefile as supplied does nothing useful at all! -## -## Various sets of options are provided, commented out -- just uncomment -## (remove the '#' characters for) the set that most closely resembles -## your own situation, and adjust to taste. Then run "make". -## -## (For Windows builds using MS Visual Studio, start instead with the -## VampExamplePlugins project found in the build directory of the SDK.) - - -# Edit this to the base name of your plugin library -# PLUGIN_LIBRARY_NAME = nnls-chroma -# Edit this to list one .o file for each .cpp file in your plugin project -# -PLUGIN_CODE_OBJECTS = chromamethods.o NNLSChroma.o plugins.o nnls.o +PLUGIN_CODE_OBJECTS = chromamethods.o NNLSBase.o NNLSChroma.o Chordino.o Tuning.o plugins.o nnls.o -# Edit this to the location of the Vamp plugin SDK, relative to your -# project directory -# VAMP_SDK_DIR = ../vamp-plugin-sdk ARCHFLAGS = -O3 -ftree-vectorize -ffast-math +#ARCHFLAGS = -g CFLAGS = $(ARCHFLAGS) -I$(VAMP_SDK_DIR) -Wall -fPIC CXXFLAGS = $(ARCHFLAGS) -I$(VAMP_SDK_DIR) -Wall -fPIC @@ -43,6 +23,21 @@ $(PLUGIN): $(PLUGIN_CODE_OBJECTS) $(CXX) -o $@ $^ $(LDFLAGS) +nnls.o: nnls.c # not nnls.f + clean: rm -f *.o +# DO NOT DELETE + +nnls.o: nnls.h +Chordino.o: Chordino.h NNLSBase.h chromamethods.h nnls.h +chromamethods.o: chromamethods.h nnls.h chorddict.cpp +NNLSBase.o: NNLSBase.h chromamethods.h nnls.h +NNLSChroma.o: NNLSChroma.h NNLSBase.h chromamethods.h nnls.h +plugins.o: NNLSChroma.h NNLSBase.h Chordino.h Tuning.h +Tuning.o: Tuning.h NNLSBase.h chromamethods.h nnls.h +Chordino.o: NNLSBase.h +chromamethods.o: nnls.h +NNLSChroma.o: NNLSBase.h +Tuning.o: NNLSBase.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NNLSBase.cpp Fri Oct 22 11:30:21 2010 +0100 @@ -0,0 +1,1021 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + NNLS-Chroma / Chordino + + Audio feature extraction plugins for chromagram and chord + estimation. + + Centre for Digital Music, Queen Mary University of London. + This file copyright 2008-2010 Matthias Mauch and QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include "NNLSBase.h" + +#include "chromamethods.h" + +#include <cstdlib> +#include <fstream> +#include <cmath> + +#include <algorithm> + +const bool debug_on = false; + +const vector<float> hw(hammingwind, hammingwind+19); + +NNLSBase::NNLSBase(float inputSampleRate) : + Plugin(inputSampleRate), + m_logSpectrum(0), + m_blockSize(0), + m_stepSize(0), + m_lengthOfNoteIndex(0), + m_meanTuning0(0), + m_meanTuning1(0), + m_meanTuning2(0), + m_localTuning0(0), + m_localTuning1(0), + m_localTuning2(0), + m_paling(1.0), + m_preset(0.0), + m_localTuning(0), + m_kernelValue(0), + m_kernelFftIndex(0), + m_kernelNoteIndex(0), + m_dict(0), + m_tuneLocal(false), + m_dictID(0), + m_chorddict(0), + m_chordnames(0), + m_doNormalizeChroma(0), + m_rollon(0.01) +{ + if (debug_on) cerr << "--> NNLSBase" << endl; + + // make the *note* dictionary matrix + m_dict = new float[nNote * 84]; + for (unsigned i = 0; i < nNote * 84; ++i) m_dict[i] = 0.0; + dictionaryMatrix(m_dict); + + // get the *chord* dictionary from file (if the file exists) + m_chordnames = chordDictionary(&m_chorddict); +} + + +NNLSBase::~NNLSBase() +{ + if (debug_on) cerr << "--> ~NNLSBase" << endl; + delete [] m_dict; +} + +string +NNLSBase::getMaker() const +{ + if (debug_on) cerr << "--> getMaker" << endl; + // Your name here + return "Matthias Mauch"; +} + +int +NNLSBase::getPluginVersion() const +{ + if (debug_on) cerr << "--> getPluginVersion" << endl; + // Increment this each time you release a version that behaves + // differently from the previous one + return 1; +} + +string +NNLSBase::getCopyright() const +{ + if (debug_on) cerr << "--> getCopyright" << endl; + // This function is not ideally named. It does not necessarily + // need to say who made the plugin -- getMaker does that -- but it + // should indicate the terms under which it is distributed. For + // example, "Copyright (year). All Rights Reserved", or "GPL" + return "GPL"; +} + +NNLSBase::InputDomain +NNLSBase::getInputDomain() const +{ + if (debug_on) cerr << "--> getInputDomain" << endl; + return FrequencyDomain; +} + +size_t +NNLSBase::getPreferredBlockSize() const +{ + if (debug_on) cerr << "--> getPreferredBlockSize" << endl; + return 16384; // 0 means "I can handle any block size" +} + +size_t +NNLSBase::getPreferredStepSize() const +{ + if (debug_on) cerr << "--> getPreferredStepSize" << endl; + return 2048; // 0 means "anything sensible"; in practice this + // means the same as the block size for TimeDomain + // plugins, or half of it for FrequencyDomain plugins +} + +size_t +NNLSBase::getMinChannelCount() const +{ + if (debug_on) cerr << "--> getMinChannelCount" << endl; + return 1; +} + +size_t +NNLSBase::getMaxChannelCount() const +{ + if (debug_on) cerr << "--> getMaxChannelCount" << endl; + return 1; +} + +NNLSBase::ParameterList +NNLSBase::getParameterDescriptors() const +{ + if (debug_on) cerr << "--> getParameterDescriptors" << endl; + ParameterList list; + + ParameterDescriptor d3; + d3.identifier = "preset"; + d3.name = "preset"; + d3.description = "Spectral paling: no paling - 0; whitening - 1."; + d3.unit = ""; + d3.isQuantized = true; + d3.quantizeStep = 1; + d3.minValue = 0.0; + d3.maxValue = 3.0; + d3.defaultValue = 0.0; + d3.valueNames.push_back("polyphonic pop"); + d3.valueNames.push_back("polyphonic pop (fast)"); + d3.valueNames.push_back("solo keyboard"); + d3.valueNames.push_back("manual"); + list.push_back(d3); + + ParameterDescriptor d5; + d5.identifier = "rollon"; + d5.name = "spectral roll-on"; + d5.description = "The bins below the spectral roll-on quantile will be set to 0."; + d5.unit = ""; + d5.minValue = 0; + d5.maxValue = 1; + d5.defaultValue = 0; + d5.isQuantized = false; + list.push_back(d5); + + // ParameterDescriptor d0; + // d0.identifier = "notedict"; + // d0.name = "note dictionary"; + // d0.description = "Notes in different note dictionaries differ by their spectral shapes."; + // d0.unit = ""; + // d0.minValue = 0; + // d0.maxValue = 1; + // d0.defaultValue = 0; + // d0.isQuantized = true; + // d0.valueNames.push_back("s = 0.6"); + // d0.valueNames.push_back("no NNLS"); + // d0.quantizeStep = 1.0; + // list.push_back(d0); + + ParameterDescriptor d1; + d1.identifier = "tuningmode"; + d1.name = "tuning mode"; + d1.description = "Tuning can be performed locally or on the whole extraction segment. Local tuning is only advisable when the tuning is likely to change over the audio, for example in podcasts, or in a cappella singing."; + d1.unit = ""; + d1.minValue = 0; + d1.maxValue = 1; + d1.defaultValue = 0; + d1.isQuantized = true; + d1.valueNames.push_back("global tuning"); + d1.valueNames.push_back("local tuning"); + d1.quantizeStep = 1.0; + list.push_back(d1); + + // ParameterDescriptor d2; + // d2.identifier = "paling"; + // d2.name = "spectral paling"; + // d2.description = "Spectral paling: no paling - 0; whitening - 1."; + // d2.unit = ""; + // d2.isQuantized = true; + // // d2.quantizeStep = 0.1; + // d2.minValue = 0.0; + // d2.maxValue = 1.0; + // d2.defaultValue = 1.0; + // d2.isQuantized = false; + // list.push_back(d2); + ParameterDescriptor d4; + d4.identifier = "chromanormalize"; + d4.name = "chroma normalization"; + d4.description = "How shall the chroma vector be normalized?"; + d4.unit = ""; + d4.minValue = 0; + d4.maxValue = 3; + d4.defaultValue = 0; + d4.isQuantized = true; + d4.valueNames.push_back("none"); + d4.valueNames.push_back("maximum norm"); + d4.valueNames.push_back("L1 norm"); + d4.valueNames.push_back("L2 norm"); + d4.quantizeStep = 1.0; + list.push_back(d4); + + return list; +} + +float +NNLSBase::getParameter(string identifier) const +{ + if (debug_on) cerr << "--> getParameter" << endl; + if (identifier == "notedict") { + return m_dictID; + } + + if (identifier == "paling") { + return m_paling; + } + + if (identifier == "rollon") { + return m_rollon; + } + + if (identifier == "tuningmode") { + if (m_tuneLocal) { + return 1.0; + } else { + return 0.0; + } + } + if (identifier == "preset") { + return m_preset; + } + if (identifier == "chromanormalize") { + return m_doNormalizeChroma; + } + return 0; + +} + +void +NNLSBase::setParameter(string identifier, float value) +{ + if (debug_on) cerr << "--> setParameter" << endl; + if (identifier == "notedict") { + m_dictID = (int) value; + } + + if (identifier == "paling") { + m_paling = value; + } + + if (identifier == "tuningmode") { + m_tuneLocal = (value > 0) ? true : false; + // cerr << "m_tuneLocal :" << m_tuneLocal << endl; + } + if (identifier == "preset") { + m_preset = value; + if (m_preset == 0.0) { + m_tuneLocal = false; + m_paling = 1.0; + m_dictID = 0.0; + } + if (m_preset == 1.0) { + m_tuneLocal = false; + m_paling = 1.0; + m_dictID = 1.0; + } + if (m_preset == 2.0) { + m_tuneLocal = false; + m_paling = 0.7; + m_dictID = 0.0; + } + } + if (identifier == "chromanormalize") { + m_doNormalizeChroma = value; + } + + if (identifier == "rollon") { + m_rollon = value; + } +} + +NNLSBase::ProgramList +NNLSBase::getPrograms() const +{ + if (debug_on) cerr << "--> getPrograms" << endl; + ProgramList list; + + // If you have no programs, return an empty list (or simply don't + // implement this function or getCurrentProgram/selectProgram) + + return list; +} + +string +NNLSBase::getCurrentProgram() const +{ + if (debug_on) cerr << "--> getCurrentProgram" << endl; + return ""; // no programs +} + +void +NNLSBase::selectProgram(string name) +{ + if (debug_on) cerr << "--> selectProgram" << endl; +} + + +bool +NNLSBase::initialise(size_t channels, size_t stepSize, size_t blockSize) +{ + if (debug_on) { + cerr << "--> initialise"; + } + + if (channels < getMinChannelCount() || + channels > getMaxChannelCount()) return false; + m_blockSize = blockSize; + m_stepSize = stepSize; + m_frameCount = 0; + int tempn = 256 * m_blockSize/2; + // cerr << "length of tempkernel : " << tempn << endl; + float *tempkernel; + + tempkernel = new float[tempn]; + + logFreqMatrix(m_inputSampleRate, m_blockSize, tempkernel); + m_kernelValue.clear(); + m_kernelFftIndex.clear(); + m_kernelNoteIndex.clear(); + int countNonzero = 0; + for (unsigned iNote = 0; iNote < nNote; ++iNote) { // I don't know if this is wise: manually making a sparse matrix + for (unsigned iFFT = 0; iFFT < blockSize/2; ++iFFT) { + if (tempkernel[iFFT + blockSize/2 * iNote] > 0) { + m_kernelValue.push_back(tempkernel[iFFT + blockSize/2 * iNote]); + if (tempkernel[iFFT + blockSize/2 * iNote] > 0) { + countNonzero++; + } + m_kernelFftIndex.push_back(iFFT); + m_kernelNoteIndex.push_back(iNote); + } + } + } + // cerr << "nonzero count : " << countNonzero << endl; + delete [] tempkernel; +/* + ofstream myfile; + myfile.open ("matrix.txt"); + // myfile << "Writing this to a file.\n"; + for (int i = 0; i < nNote * 84; ++i) { + myfile << m_dict[i] << endl; + } + myfile.close(); +*/ + return true; +} + +void +NNLSBase::reset() +{ + if (debug_on) cerr << "--> reset"; + + // Clear buffers, reset stored values, etc + m_frameCount = 0; + m_dictID = 0; + m_logSpectrum.clear(); + m_meanTuning0 = 0; + m_meanTuning1 = 0; + m_meanTuning2 = 0; + m_localTuning0 = 0; + m_localTuning1 = 0; + m_localTuning2 = 0; + m_localTuning.clear(); +} + +void +NNLSBase::baseProcess(const float *const *inputBuffers, Vamp::RealTime timestamp) +{ + m_frameCount++; + float *magnitude = new float[m_blockSize/2]; + + const float *fbuf = inputBuffers[0]; + float energysum = 0; + // make magnitude + float maxmag = -10000; + for (size_t iBin = 0; iBin < m_blockSize/2; iBin++) { + magnitude[iBin] = sqrt(fbuf[2 * iBin] * fbuf[2 * iBin] + + fbuf[2 * iBin + 1] * fbuf[2 * iBin + 1]); + if (maxmag < magnitude[iBin]) maxmag = magnitude[iBin]; + if (m_rollon > 0) { + energysum += pow(magnitude[iBin],2); + } + } + + float cumenergy = 0; + if (m_rollon > 0) { + for (size_t iBin = 2; iBin < m_blockSize/2; iBin++) { + cumenergy += pow(magnitude[iBin],2); + if (cumenergy < energysum * m_rollon) magnitude[iBin-2] = 0; + else break; + } + } + + if (maxmag < 2) { + // cerr << "timestamp " << timestamp << ": very low magnitude, setting magnitude to all zeros" << endl; + for (size_t iBin = 0; iBin < m_blockSize/2; iBin++) { + magnitude[iBin] = 0; + } + } + + // note magnitude mapping using pre-calculated matrix + float *nm = new float[nNote]; // note magnitude + for (size_t iNote = 0; iNote < nNote; iNote++) { + nm[iNote] = 0; // initialise as 0 + } + int binCount = 0; + for (vector<float>::iterator it = m_kernelValue.begin(); it != m_kernelValue.end(); ++it) { + // cerr << "."; + nm[m_kernelNoteIndex[binCount]] += magnitude[m_kernelFftIndex[binCount]] * m_kernelValue[binCount]; + // cerr << m_kernelFftIndex[binCount] << " -- " << magnitude[m_kernelFftIndex[binCount]] << " -- "<< m_kernelValue[binCount] << endl; + binCount++; + } + // cerr << nm[20]; + // cerr << endl; + + + float one_over_N = 1.0/m_frameCount; + // update means of complex tuning variables + m_meanTuning0 *= float(m_frameCount-1)*one_over_N; + m_meanTuning1 *= float(m_frameCount-1)*one_over_N; + m_meanTuning2 *= float(m_frameCount-1)*one_over_N; + + for (int iTone = 0; iTone < 160; iTone = iTone + 3) { + m_meanTuning0 += nm[iTone + 0]*one_over_N; + m_meanTuning1 += nm[iTone + 1]*one_over_N; + m_meanTuning2 += nm[iTone + 2]*one_over_N; + float ratioOld = 0.997; + m_localTuning0 *= ratioOld; m_localTuning0 += nm[iTone + 0] * (1 - ratioOld); + m_localTuning1 *= ratioOld; m_localTuning1 += nm[iTone + 1] * (1 - ratioOld); + m_localTuning2 *= ratioOld; m_localTuning2 += nm[iTone + 2] * (1 - ratioOld); + } + + // if (m_tuneLocal) { + // local tuning + float localTuningImag = sinvalue * m_localTuning1 - sinvalue * m_localTuning2; + float localTuningReal = m_localTuning0 + cosvalue * m_localTuning1 + cosvalue * m_localTuning2; + float normalisedtuning = atan2(localTuningImag, localTuningReal)/(2*M_PI); + m_localTuning.push_back(normalisedtuning); + + Feature f1; // logfreqspec + f1.hasTimestamp = true; + f1.timestamp = timestamp; + for (size_t iNote = 0; iNote < nNote; iNote++) { + f1.values.push_back(nm[iNote]); + } + + // deletes + delete[] magnitude; + delete[] nm; + + m_logSpectrum.push_back(f1); // remember note magnitude +} + + +#ifdef NOT_DEFINED + +NNLSBase::FeatureSet +NNLSBase::getRemainingFeatures() +{ + if (debug_on) cerr << "--> getRemainingFeatures" << endl; + FeatureSet fsOut; + if (m_logSpectrum.size() == 0) return fsOut; + int nChord = m_chordnames.size(); + // + /** Calculate Tuning + calculate tuning from (using the angle of the complex number defined by the + cumulative mean real and imag values) + **/ + float meanTuningImag = sinvalue * m_meanTuning1 - sinvalue * m_meanTuning2; + float meanTuningReal = m_meanTuning0 + cosvalue * m_meanTuning1 + cosvalue * m_meanTuning2; + float cumulativetuning = 440 * pow(2,atan2(meanTuningImag, meanTuningReal)/(24*M_PI)); + float normalisedtuning = atan2(meanTuningImag, meanTuningReal)/(2*M_PI); + int intShift = floor(normalisedtuning * 3); + float intFactor = normalisedtuning * 3 - intShift; // intFactor is a really bad name for this + + char buffer0 [50]; + + sprintf(buffer0, "estimated tuning: %0.1f Hz", cumulativetuning); + + // cerr << "normalisedtuning: " << normalisedtuning << '\n'; + + // push tuning to FeatureSet fsOut + Feature f0; // tuning + f0.hasTimestamp = true; + f0.timestamp = Vamp::RealTime::frame2RealTime(0, lrintf(m_inputSampleRate));; + f0.label = buffer0; + fsOut[0].push_back(f0); + + /** Tune Log-Frequency Spectrogram + calculate a tuned log-frequency spectrogram (f2): use the tuning estimated above (kinda f0) to + perform linear interpolation on the existing log-frequency spectrogram (kinda f1). + **/ + cerr << endl << "[NNLS Chroma Plugin] Tuning Log-Frequency Spectrogram ... "; + + float tempValue = 0; + float dbThreshold = 0; // relative to the background spectrum + float thresh = pow(10,dbThreshold/20); + // cerr << "tune local ? " << m_tuneLocal << endl; + int count = 0; + + for (FeatureList::iterator i = m_logSpectrum.begin(); i != m_logSpectrum.end(); ++i) { + Feature f1 = *i; + Feature f2; // tuned log-frequency spectrum + f2.hasTimestamp = true; + f2.timestamp = f1.timestamp; + f2.values.push_back(0.0); f2.values.push_back(0.0); // set lower edge to zero + + if (m_tuneLocal) { + intShift = floor(m_localTuning[count] * 3); + intFactor = m_localTuning[count] * 3 - intShift; // intFactor is a really bad name for this + } + + // cerr << intShift << " " << intFactor << endl; + + for (unsigned k = 2; k < f1.values.size() - 3; ++k) { // interpolate all inner bins + tempValue = f1.values[k + intShift] * (1-intFactor) + f1.values[k+intShift+1] * intFactor; + f2.values.push_back(tempValue); + } + + f2.values.push_back(0.0); f2.values.push_back(0.0); f2.values.push_back(0.0); // upper edge + vector<float> runningmean = SpecialConvolution(f2.values,hw); + vector<float> runningstd; + for (int i = 0; i < 256; i++) { // first step: squared values into vector (variance) + runningstd.push_back((f2.values[i] - runningmean[i]) * (f2.values[i] - runningmean[i])); + } + runningstd = SpecialConvolution(runningstd,hw); // second step convolve + for (int i = 0; i < 256; i++) { + runningstd[i] = sqrt(runningstd[i]); // square root to finally have running std + if (runningstd[i] > 0) { + // f2.values[i] = (f2.values[i] / runningmean[i]) > thresh ? + // (f2.values[i] - runningmean[i]) / pow(runningstd[i],m_paling) : 0; + f2.values[i] = (f2.values[i] - runningmean[i]) > 0 ? + (f2.values[i] - runningmean[i]) / pow(runningstd[i],m_paling) : 0; + } + if (f2.values[i] < 0) { + cerr << "ERROR: negative value in logfreq spectrum" << endl; + } + } + fsOut[2].push_back(f2); + count++; + } + cerr << "done." << endl; + + /** Semitone spectrum and chromagrams + Semitone-spaced log-frequency spectrum derived from the tuned log-freq spectrum above. the spectrum + is inferred using a non-negative least squares algorithm. + Three different kinds of chromagram are calculated, "treble", "bass", and "both" (which means + bass and treble stacked onto each other). + **/ + if (m_dictID == 1) { + cerr << "[NNLS Chroma Plugin] Mapping to semitone spectrum and chroma ... "; + } else { + cerr << "[NNLS Chroma Plugin] Performing NNLS and mapping to chroma ... "; + } + + + vector<vector<float> > chordogram; + vector<vector<int> > scoreChordogram; + vector<float> chordchange = vector<float>(fsOut[2].size(),0); + vector<float> oldchroma = vector<float>(12,0); + vector<float> oldbasschroma = vector<float>(12,0); + count = 0; + + for (FeatureList::iterator it = fsOut[2].begin(); it != fsOut[2].end(); ++it) { + Feature f2 = *it; // logfreq spectrum + Feature f3; // semitone spectrum + Feature f4; // treble chromagram + Feature f5; // bass chromagram + Feature f6; // treble and bass chromagram + + f3.hasTimestamp = true; + f3.timestamp = f2.timestamp; + + f4.hasTimestamp = true; + f4.timestamp = f2.timestamp; + + f5.hasTimestamp = true; + f5.timestamp = f2.timestamp; + + f6.hasTimestamp = true; + f6.timestamp = f2.timestamp; + + float b[256]; + + bool some_b_greater_zero = false; + float sumb = 0; + for (int i = 0; i < 256; i++) { + // b[i] = m_dict[(256 * count + i) % (256 * 84)]; + b[i] = f2.values[i]; + sumb += b[i]; + if (b[i] > 0) { + some_b_greater_zero = true; + } + } + + // here's where the non-negative least squares algorithm calculates the note activation x + + vector<float> chroma = vector<float>(12, 0); + vector<float> basschroma = vector<float>(12, 0); + float currval; + unsigned iSemitone = 0; + + if (some_b_greater_zero) { + if (m_dictID == 1) { + for (unsigned iNote = 2; iNote < nNote - 2; iNote += 3) { + currval = 0; + currval += b[iNote + 1 + -1] * 0.5; + currval += b[iNote + 1 + 0] * 1.0; + currval += b[iNote + 1 + 1] * 0.5; + f3.values.push_back(currval); + chroma[iSemitone % 12] += currval * treblewindow[iSemitone]; + basschroma[iSemitone % 12] += currval * basswindow[iSemitone]; + iSemitone++; + } + + } else { + float x[84+1000]; + for (int i = 1; i < 1084; ++i) x[i] = 1.0; + vector<int> signifIndex; + int index=0; + sumb /= 84.0; + for (unsigned iNote = 2; iNote < nNote - 2; iNote += 3) { + float currval = 0; + currval += b[iNote + 1 + -1]; + currval += b[iNote + 1 + 0]; + currval += b[iNote + 1 + 1]; + if (currval > 0) signifIndex.push_back(index); + f3.values.push_back(0); // fill the values, change later + index++; + } + float rnorm; + float w[84+1000]; + float zz[84+1000]; + int indx[84+1000]; + int mode; + int dictsize = 256*signifIndex.size(); + // cerr << "dictsize is " << dictsize << "and values size" << f3.values.size()<< endl; + float *curr_dict = new float[dictsize]; + for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { + for (unsigned iBin = 0; iBin < 256; iBin++) { + curr_dict[iNote * 256 + iBin] = 1.0 * m_dict[signifIndex[iNote] * 256 + iBin]; + } + } + nnls(curr_dict, nNote, nNote, signifIndex.size(), b, x, &rnorm, w, zz, indx, &mode); + delete [] curr_dict; + for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { + f3.values[signifIndex[iNote]] = x[iNote]; + // cerr << mode << endl; + chroma[signifIndex[iNote] % 12] += x[iNote] * treblewindow[signifIndex[iNote]]; + basschroma[signifIndex[iNote] % 12] += x[iNote] * basswindow[signifIndex[iNote]]; + } + } + } + + + + + f4.values = chroma; + f5.values = basschroma; + chroma.insert(chroma.begin(), basschroma.begin(), basschroma.end()); // just stack the both chromas + f6.values = chroma; + + if (m_doNormalizeChroma > 0) { + vector<float> chromanorm = vector<float>(3,0); + switch (int(m_doNormalizeChroma)) { + case 0: // should never end up here + break; + case 1: + chromanorm[0] = *max_element(f4.values.begin(), f4.values.end()); + chromanorm[1] = *max_element(f5.values.begin(), f5.values.end()); + chromanorm[2] = max(chromanorm[0], chromanorm[1]); + break; + case 2: + for (vector<float>::iterator it = f4.values.begin(); it != f4.values.end(); ++it) { + chromanorm[0] += *it; + } + for (vector<float>::iterator it = f5.values.begin(); it != f5.values.end(); ++it) { + chromanorm[1] += *it; + } + for (vector<float>::iterator it = f6.values.begin(); it != f6.values.end(); ++it) { + chromanorm[2] += *it; + } + break; + case 3: + for (vector<float>::iterator it = f4.values.begin(); it != f4.values.end(); ++it) { + chromanorm[0] += pow(*it,2); + } + chromanorm[0] = sqrt(chromanorm[0]); + for (vector<float>::iterator it = f5.values.begin(); it != f5.values.end(); ++it) { + chromanorm[1] += pow(*it,2); + } + chromanorm[1] = sqrt(chromanorm[1]); + for (vector<float>::iterator it = f6.values.begin(); it != f6.values.end(); ++it) { + chromanorm[2] += pow(*it,2); + } + chromanorm[2] = sqrt(chromanorm[2]); + break; + } + if (chromanorm[0] > 0) { + for (int i = 0; i < f4.values.size(); i++) { + f4.values[i] /= chromanorm[0]; + } + } + if (chromanorm[1] > 0) { + for (int i = 0; i < f5.values.size(); i++) { + f5.values[i] /= chromanorm[1]; + } + } + if (chromanorm[2] > 0) { + for (int i = 0; i < f6.values.size(); i++) { + f6.values[i] /= chromanorm[2]; + } + } + + } + + // local chord estimation + vector<float> currentChordSalience; + float tempchordvalue = 0; + float sumchordvalue = 0; + + for (int iChord = 0; iChord < nChord; iChord++) { + tempchordvalue = 0; + for (int iBin = 0; iBin < 12; iBin++) { + tempchordvalue += m_chorddict[24 * iChord + iBin] * chroma[iBin]; + } + for (int iBin = 12; iBin < 24; iBin++) { + tempchordvalue += m_chorddict[24 * iChord + iBin] * chroma[iBin]; + } + sumchordvalue+=tempchordvalue; + currentChordSalience.push_back(tempchordvalue); + } + if (sumchordvalue > 0) { + for (int iChord = 0; iChord < nChord; iChord++) { + currentChordSalience[iChord] /= sumchordvalue; + } + } else { + currentChordSalience[nChord-1] = 1.0; + } + chordogram.push_back(currentChordSalience); + + fsOut[3].push_back(f3); + fsOut[4].push_back(f4); + fsOut[5].push_back(f5); + fsOut[6].push_back(f6); + count++; + } + cerr << "done." << endl; + + + /* Simple chord estimation + I just take the local chord estimates ("currentChordSalience") and average them over time, then + take the maximum. Very simple, don't do this at home... + */ + cerr << "[NNLS Chroma Plugin] Chord Estimation ... "; + count = 0; + int halfwindowlength = m_inputSampleRate / m_stepSize; + vector<int> chordSequence; + for (FeatureList::iterator it = fsOut[6].begin(); it != fsOut[6].end(); ++it) { // initialise the score chordogram + vector<int> temp = vector<int>(nChord,0); + scoreChordogram.push_back(temp); + } + for (FeatureList::iterator it = fsOut[6].begin(); it < fsOut[6].end()-2*halfwindowlength-1; ++it) { + int startIndex = count + 1; + int endIndex = count + 2 * halfwindowlength; + + float chordThreshold = 2.5/nChord;//*(2*halfwindowlength+1); + + vector<int> chordCandidates; + for (unsigned iChord = 0; iChord < nChord-1; iChord++) { + // float currsum = 0; + // for (unsigned iFrame = startIndex; iFrame < endIndex; ++iFrame) { + // currsum += chordogram[iFrame][iChord]; + // } + // if (currsum > chordThreshold) chordCandidates.push_back(iChord); + for (unsigned iFrame = startIndex; iFrame < endIndex; ++iFrame) { + if (chordogram[iFrame][iChord] > chordThreshold) { + chordCandidates.push_back(iChord); + break; + } + } + } + chordCandidates.push_back(nChord-1); + // cerr << chordCandidates.size() << endl; + + float maxval = 0; // will be the value of the most salient *chord change* in this frame + float maxindex = 0; //... and the index thereof + unsigned bestchordL = nChord-1; // index of the best "left" chord + unsigned bestchordR = nChord-1; // index of the best "right" chord + + for (int iWF = 1; iWF < 2*halfwindowlength; ++iWF) { + // now find the max values on both sides of iWF + // left side: + float maxL = 0; + unsigned maxindL = nChord-1; + for (unsigned kChord = 0; kChord < chordCandidates.size(); kChord++) { + unsigned iChord = chordCandidates[kChord]; + float currsum = 0; + for (unsigned iFrame = 0; iFrame < iWF-1; ++iFrame) { + currsum += chordogram[count+iFrame][iChord]; + } + if (iChord == nChord-1) currsum *= 0.8; + if (currsum > maxL) { + maxL = currsum; + maxindL = iChord; + } + } + // right side: + float maxR = 0; + unsigned maxindR = nChord-1; + for (unsigned kChord = 0; kChord < chordCandidates.size(); kChord++) { + unsigned iChord = chordCandidates[kChord]; + float currsum = 0; + for (unsigned iFrame = iWF-1; iFrame < 2*halfwindowlength; ++iFrame) { + currsum += chordogram[count+iFrame][iChord]; + } + if (iChord == nChord-1) currsum *= 0.8; + if (currsum > maxR) { + maxR = currsum; + maxindR = iChord; + } + } + if (maxL+maxR > maxval) { + maxval = maxL+maxR; + maxindex = iWF; + bestchordL = maxindL; + bestchordR = maxindR; + } + + } + // cerr << "maxindex: " << maxindex << ", bestchordR is " << bestchordR << ", of frame " << count << endl; + // add a score to every chord-frame-point that was part of a maximum + for (unsigned iFrame = 0; iFrame < maxindex-1; ++iFrame) { + scoreChordogram[iFrame+count][bestchordL]++; + } + for (unsigned iFrame = maxindex-1; iFrame < 2*halfwindowlength; ++iFrame) { + scoreChordogram[iFrame+count][bestchordR]++; + } + if (bestchordL != bestchordR) chordchange[maxindex+count] += (halfwindowlength - abs(maxindex-halfwindowlength)) * 2.0 / halfwindowlength; + count++; + } + // cerr << "******* agent finished *******" << endl; + count = 0; + for (FeatureList::iterator it = fsOut[6].begin(); it != fsOut[6].end(); ++it) { + float maxval = 0; // will be the value of the most salient chord in this frame + float maxindex = 0; //... and the index thereof + for (unsigned iChord = 0; iChord < nChord; iChord++) { + if (scoreChordogram[count][iChord] > maxval) { + maxval = scoreChordogram[count][iChord]; + maxindex = iChord; + // cerr << iChord << endl; + } + } + chordSequence.push_back(maxindex); + // cerr << "before modefilter, maxindex: " << maxindex << endl; + count++; + } + // cerr << "******* mode filter done *******" << endl; + + + // mode filter on chordSequence + count = 0; + string oldChord = ""; + for (FeatureList::iterator it = fsOut[6].begin(); it != fsOut[6].end(); ++it) { + Feature f6 = *it; + Feature f7; // chord estimate + f7.hasTimestamp = true; + f7.timestamp = f6.timestamp; + Feature f8; // chord estimate + f8.hasTimestamp = true; + f8.timestamp = f6.timestamp; + + vector<int> chordCount = vector<int>(nChord,0); + int maxChordCount = 0; + int maxChordIndex = nChord-1; + string maxChord; + int startIndex = max(count - halfwindowlength/2,0); + int endIndex = min(int(chordogram.size()), count + halfwindowlength/2); + for (int i = startIndex; i < endIndex; i++) { + chordCount[chordSequence[i]]++; + if (chordCount[chordSequence[i]] > maxChordCount) { + // cerr << "start index " << startIndex << endl; + maxChordCount++; + maxChordIndex = chordSequence[i]; + maxChord = m_chordnames[maxChordIndex]; + } + } + // chordSequence[count] = maxChordIndex; + // cerr << maxChordIndex << endl; + f8.values.push_back(chordchange[count]/(halfwindowlength*2)); + // cerr << chordchange[count] << endl; + fsOut[9].push_back(f8); + if (oldChord != maxChord) { + oldChord = maxChord; + + // char buffer1 [50]; + // if (maxChordIndex < nChord - 1) { + // sprintf(buffer1, "%s%s", notenames[maxChordIndex % 12 + 12], chordtypes[maxChordIndex]); + // } else { + // sprintf(buffer1, "N"); + // } + // f7.label = buffer1; + f7.label = m_chordnames[maxChordIndex]; + fsOut[7].push_back(f7); + } + count++; + } + Feature f7; // last chord estimate + f7.hasTimestamp = true; + f7.timestamp = fsOut[6][fsOut[6].size()-1].timestamp; + f7.label = "N"; + fsOut[7].push_back(f7); + cerr << "done." << endl; + // // musicity + // count = 0; + // int oldlabeltype = 0; // start value is 0, music is 1, speech is 2 + // vector<float> musicityValue; + // for (FeatureList::iterator it = fsOut[4].begin(); it != fsOut[4].end(); ++it) { + // Feature f4 = *it; + // + // int startIndex = max(count - musicitykernelwidth/2,0); + // int endIndex = min(int(chordogram.size()), startIndex + musicitykernelwidth - 1); + // float chromasum = 0; + // float diffsum = 0; + // for (int k = 0; k < 12; k++) { + // for (int i = startIndex + 1; i < endIndex; i++) { + // chromasum += pow(fsOut[4][i].values[k],2); + // diffsum += abs(fsOut[4][i-1].values[k] - fsOut[4][i].values[k]); + // } + // } + // diffsum /= chromasum; + // musicityValue.push_back(diffsum); + // count++; + // } + // + // float musicityThreshold = 0.44; + // if (m_stepSize == 4096) { + // musicityThreshold = 0.74; + // } + // if (m_stepSize == 4410) { + // musicityThreshold = 0.77; + // } + // + // count = 0; + // for (FeatureList::iterator it = fsOut[4].begin(); it != fsOut[4].end(); ++it) { + // Feature f4 = *it; + // Feature f8; // musicity + // Feature f9; // musicity segmenter + // + // f8.hasTimestamp = true; + // f8.timestamp = f4.timestamp; + // f9.hasTimestamp = true; + // f9.timestamp = f4.timestamp; + // + // int startIndex = max(count - musicitykernelwidth/2,0); + // int endIndex = min(int(chordogram.size()), startIndex + musicitykernelwidth - 1); + // int musicityCount = 0; + // for (int i = startIndex; i <= endIndex; i++) { + // if (musicityValue[i] > musicityThreshold) musicityCount++; + // } + // bool isSpeech = (2 * musicityCount > endIndex - startIndex + 1); + // + // if (isSpeech) { + // if (oldlabeltype != 2) { + // f9.label = "Speech"; + // fsOut[9].push_back(f9); + // oldlabeltype = 2; + // } + // } else { + // if (oldlabeltype != 1) { + // f9.label = "Music"; + // fsOut[9].push_back(f9); + // oldlabeltype = 1; + // } + // } + // f8.values.push_back(musicityValue[count]); + // fsOut[8].push_back(f8); + // count++; + // } + return fsOut; + +} + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NNLSBase.h Fri Oct 22 11:30:21 2010 +0100 @@ -0,0 +1,86 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + NNLS-Chroma / Chordino + + Audio feature extraction plugins for chromagram and chord + estimation. + + Centre for Digital Music, Queen Mary University of London. + This file copyright 2008-2010 Matthias Mauch and QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef _NNLS_BASE_ +#define _NNLS_BASE_ + +#include <vamp-sdk/Plugin.h> +#include <list> + +using namespace std; + +class NNLSBase : public Vamp::Plugin +{ +public: + virtual ~NNLSBase(); + + string getMaker() const; + int getPluginVersion() const; + string getCopyright() const; + + InputDomain getInputDomain() const; + size_t getPreferredBlockSize() const; + size_t getPreferredStepSize() const; + size_t getMinChannelCount() const; + size_t getMaxChannelCount() const; + + ParameterList getParameterDescriptors() const; + float getParameter(string identifier) const; + void setParameter(string identifier, float value); + + ProgramList getPrograms() const; + string getCurrentProgram() const; + void selectProgram(string name); + + bool initialise(size_t channels, size_t stepSize, size_t blockSize); + void reset(); + +protected: + NNLSBase(float inputSampleRate); + void baseProcess(const float *const *inputBuffers, + Vamp::RealTime timestamp); + + int m_frameCount; + FeatureList m_logSpectrum; + size_t m_blockSize; + size_t m_stepSize; + int m_lengthOfNoteIndex; + float m_meanTuning0; + float m_meanTuning1; + float m_meanTuning2; + float m_localTuning0; + float m_localTuning1; + float m_localTuning2; + float m_paling; + float m_preset; + vector<float> m_localTuning; + vector<float> m_kernelValue; + vector<int> m_kernelFftIndex; + vector<int> m_kernelNoteIndex; + float *m_dict; + bool m_tuneLocal; + int m_dictID; + vector<float> m_chorddict; + vector<string> m_chordnames; + float m_doNormalizeChroma; + float m_rollon; +}; + + + +#endif
--- a/NNLSChroma.cpp Fri Oct 22 16:19:40 2010 +0900 +++ b/NNLSChroma.cpp Fri Oct 22 11:30:21 2010 +0100 @@ -1,5 +1,21 @@ /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ +/* + NNLS-Chroma / Chordino + + Audio feature extraction plugins for chromagram and chord + estimation. + + Centre for Digital Music, Queen Mary University of London. + This file copyright 2008-2010 Matthias Mauch and QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + #include "NNLSChroma.h" #include "chromamethods.h" @@ -15,49 +31,14 @@ const vector<float> hw(hammingwind, hammingwind+19); NNLSChroma::NNLSChroma(float inputSampleRate) : - Plugin(inputSampleRate), - m_fl(0), - m_blockSize(0), - m_stepSize(0), - m_lengthOfNoteIndex(0), - m_meanTuning0(0), - m_meanTuning1(0), - m_meanTuning2(0), - m_localTuning0(0), - m_localTuning1(0), - m_localTuning2(0), - m_paling(1.0), - m_preset(0.0), - m_localTuning(0), - m_kernelValue(0), - m_kernelFftIndex(0), - m_kernelNoteIndex(0), - m_dict(0), - m_tuneLocal(false), - m_dictID(0), - m_chorddict(0), - m_chordnames(0), - m_doNormalizeChroma(0), - m_rollon(0.01) + NNLSBase(inputSampleRate) { if (debug_on) cerr << "--> NNLSChroma" << endl; - - // make the *note* dictionary matrix - m_dict = new float[nNote * 84]; - for (unsigned i = 0; i < nNote * 84; ++i) m_dict[i] = 0.0; - dictionaryMatrix(m_dict); - - // get the *chord* dictionary from file (if the file exists) - m_chordnames = chordDictionary(&m_chorddict); } - NNLSChroma::~NNLSChroma() { if (debug_on) cerr << "--> ~NNLSChroma" << endl; - delete [] m_dict; - // delete [] m_chorddict; - // delete m_chordnames; } string @@ -77,270 +58,10 @@ string NNLSChroma::getDescription() const { - // Return something helpful here! if (debug_on) cerr << "--> getDescription" << endl; return "This plugin provides a number of features derived from a log-frequency amplitude spectrum of the DFT: some variants of the log-frequency spectrum, including a semitone spectrum derived from approximate transcription using the NNLS algorithm; based on this semitone spectrum, chroma features and a simple chord estimate."; } -string -NNLSChroma::getMaker() const -{ - if (debug_on) cerr << "--> getMaker" << endl; - // Your name here - return "Matthias Mauch"; -} - -int -NNLSChroma::getPluginVersion() const -{ - if (debug_on) cerr << "--> getPluginVersion" << endl; - // Increment this each time you release a version that behaves - // differently from the previous one - return 1; -} - -string -NNLSChroma::getCopyright() const -{ - if (debug_on) cerr << "--> getCopyright" << endl; - // This function is not ideally named. It does not necessarily - // need to say who made the plugin -- getMaker does that -- but it - // should indicate the terms under which it is distributed. For - // example, "Copyright (year). All Rights Reserved", or "GPL" - return "Copyright (2010). All rights reserved."; -} - -NNLSChroma::InputDomain -NNLSChroma::getInputDomain() const -{ - if (debug_on) cerr << "--> getInputDomain" << endl; - return FrequencyDomain; -} - -size_t -NNLSChroma::getPreferredBlockSize() const -{ - if (debug_on) cerr << "--> getPreferredBlockSize" << endl; - return 16384; // 0 means "I can handle any block size" -} - -size_t -NNLSChroma::getPreferredStepSize() const -{ - if (debug_on) cerr << "--> getPreferredStepSize" << endl; - return 2048; // 0 means "anything sensible"; in practice this - // means the same as the block size for TimeDomain - // plugins, or half of it for FrequencyDomain plugins -} - -size_t -NNLSChroma::getMinChannelCount() const -{ - if (debug_on) cerr << "--> getMinChannelCount" << endl; - return 1; -} - -size_t -NNLSChroma::getMaxChannelCount() const -{ - if (debug_on) cerr << "--> getMaxChannelCount" << endl; - return 1; -} - -NNLSChroma::ParameterList -NNLSChroma::getParameterDescriptors() const -{ - if (debug_on) cerr << "--> getParameterDescriptors" << endl; - ParameterList list; - - ParameterDescriptor d3; - d3.identifier = "preset"; - d3.name = "preset"; - d3.description = "Spectral paling: no paling - 0; whitening - 1."; - d3.unit = ""; - d3.isQuantized = true; - d3.quantizeStep = 1; - d3.minValue = 0.0; - d3.maxValue = 3.0; - d3.defaultValue = 0.0; - d3.valueNames.push_back("polyphonic pop"); - d3.valueNames.push_back("polyphonic pop (fast)"); - d3.valueNames.push_back("solo keyboard"); - d3.valueNames.push_back("manual"); - list.push_back(d3); - - ParameterDescriptor d5; - d5.identifier = "rollon"; - d5.name = "spectral roll-on"; - d5.description = "The bins below the spectral roll-on quantile will be set to 0."; - d5.unit = ""; - d5.minValue = 0; - d5.maxValue = 1; - d5.defaultValue = 0; - d5.isQuantized = false; - list.push_back(d5); - - // ParameterDescriptor d0; - // d0.identifier = "notedict"; - // d0.name = "note dictionary"; - // d0.description = "Notes in different note dictionaries differ by their spectral shapes."; - // d0.unit = ""; - // d0.minValue = 0; - // d0.maxValue = 1; - // d0.defaultValue = 0; - // d0.isQuantized = true; - // d0.valueNames.push_back("s = 0.6"); - // d0.valueNames.push_back("no NNLS"); - // d0.quantizeStep = 1.0; - // list.push_back(d0); - - ParameterDescriptor d1; - d1.identifier = "tuningmode"; - d1.name = "tuning mode"; - d1.description = "Tuning can be performed locally or on the whole extraction segment. Local tuning is only advisable when the tuning is likely to change over the audio, for example in podcasts, or in a cappella singing."; - d1.unit = ""; - d1.minValue = 0; - d1.maxValue = 1; - d1.defaultValue = 0; - d1.isQuantized = true; - d1.valueNames.push_back("global tuning"); - d1.valueNames.push_back("local tuning"); - d1.quantizeStep = 1.0; - list.push_back(d1); - - // ParameterDescriptor d2; - // d2.identifier = "paling"; - // d2.name = "spectral paling"; - // d2.description = "Spectral paling: no paling - 0; whitening - 1."; - // d2.unit = ""; - // d2.isQuantized = true; - // // d2.quantizeStep = 0.1; - // d2.minValue = 0.0; - // d2.maxValue = 1.0; - // d2.defaultValue = 1.0; - // d2.isQuantized = false; - // list.push_back(d2); - ParameterDescriptor d4; - d4.identifier = "chromanormalize"; - d4.name = "chroma normalization"; - d4.description = "How shall the chroma vector be normalized?"; - d4.unit = ""; - d4.minValue = 0; - d4.maxValue = 3; - d4.defaultValue = 0; - d4.isQuantized = true; - d4.valueNames.push_back("none"); - d4.valueNames.push_back("maximum norm"); - d4.valueNames.push_back("L1 norm"); - d4.valueNames.push_back("L2 norm"); - d4.quantizeStep = 1.0; - list.push_back(d4); - - return list; -} - -float -NNLSChroma::getParameter(string identifier) const -{ - if (debug_on) cerr << "--> getParameter" << endl; - if (identifier == "notedict") { - return m_dictID; - } - - if (identifier == "paling") { - return m_paling; - } - - if (identifier == "rollon") { - return m_rollon; - } - - if (identifier == "tuningmode") { - if (m_tuneLocal) { - return 1.0; - } else { - return 0.0; - } - } - if (identifier == "preset") { - return m_preset; - } - if (identifier == "chromanormalize") { - return m_doNormalizeChroma; - } - return 0; - -} - -void -NNLSChroma::setParameter(string identifier, float value) -{ - if (debug_on) cerr << "--> setParameter" << endl; - if (identifier == "notedict") { - m_dictID = (int) value; - } - - if (identifier == "paling") { - m_paling = value; - } - - if (identifier == "tuningmode") { - m_tuneLocal = (value > 0) ? true : false; - // cerr << "m_tuneLocal :" << m_tuneLocal << endl; - } - if (identifier == "preset") { - m_preset = value; - if (m_preset == 0.0) { - m_tuneLocal = false; - m_paling = 1.0; - m_dictID = 0.0; - } - if (m_preset == 1.0) { - m_tuneLocal = false; - m_paling = 1.0; - m_dictID = 1.0; - } - if (m_preset == 2.0) { - m_tuneLocal = false; - m_paling = 0.7; - m_dictID = 0.0; - } - } - if (identifier == "chromanormalize") { - m_doNormalizeChroma = value; - } - - if (identifier == "rollon") { - m_rollon = value; - } -} - -NNLSChroma::ProgramList -NNLSChroma::getPrograms() const -{ - if (debug_on) cerr << "--> getPrograms" << endl; - ProgramList list; - - // If you have no programs, return an empty list (or simply don't - // implement this function or getCurrentProgram/selectProgram) - - return list; -} - -string -NNLSChroma::getCurrentProgram() const -{ - if (debug_on) cerr << "--> getCurrentProgram" << endl; - return ""; // no programs -} - -void -NNLSChroma::selectProgram(string name) -{ - if (debug_on) cerr << "--> selectProgram" << endl; -} - - NNLSChroma::OutputList NNLSChroma::getOutputDescriptors() const { @@ -357,26 +78,8 @@ } } - // int nNote = 84; + int index = 0; - // See OutputDescriptor documentation for the possibilities here. - // Every plugin must have at least one output. - - OutputDescriptor d0; - d0.identifier = "tuning"; - d0.name = "Tuning"; - d0.description = "The concert pitch."; - d0.unit = "Hz"; - d0.hasFixedBinCount = true; - d0.binCount = 0; - d0.hasKnownExtents = true; - d0.minValue = 427.47; - d0.maxValue = 452.89; - d0.isQuantized = false; - d0.sampleType = OutputDescriptor::VariableSampleRate; - d0.hasDuration = false; - list.push_back(d0); - OutputDescriptor d1; d1.identifier = "logfreqspec"; d1.name = "Log-Frequency Spectrum"; @@ -390,6 +93,7 @@ d1.hasDuration = false; d1.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; list.push_back(d1); + m_outputLogSpec = index++; OutputDescriptor d2; d2.identifier = "tunedlogfreqspec"; @@ -404,6 +108,7 @@ d2.hasDuration = false; d2.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; list.push_back(d2); + m_outputTunedSpec = index++; OutputDescriptor d3; d3.identifier = "semitonespectrum"; @@ -418,6 +123,7 @@ d3.hasDuration = false; d3.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; list.push_back(d3); + m_outputSemiSpec = index++; OutputDescriptor d4; d4.identifier = "chroma"; @@ -433,6 +139,7 @@ d4.hasDuration = false; d4.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; list.push_back(d4); + m_outputChroma = index++; OutputDescriptor d5; d5.identifier = "basschroma"; @@ -448,6 +155,7 @@ d5.hasDuration = false; d5.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; list.push_back(d5); + m_outputBassChroma = index++; OutputDescriptor d6; d6.identifier = "bothchroma"; @@ -463,69 +171,7 @@ d6.hasDuration = false; d6.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; list.push_back(d6); - - OutputDescriptor d7; - d7.identifier = "simplechord"; - d7.name = "Simple Chord Estimate"; - d7.description = "A simple chord estimate based on the inner product of chord templates with the smoothed chroma."; - d7.unit = ""; - d7.hasFixedBinCount = true; - d7.binCount = 0; - d7.hasKnownExtents = false; - d7.isQuantized = false; - d7.sampleType = OutputDescriptor::VariableSampleRate; - d7.hasDuration = false; - d7.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; - list.push_back(d7); - - // - // OutputDescriptor d9; - // d9.identifier = "inconsistencysegment"; - // d9.name = "Harmonic inconsistency segmenter"; - // d9.description = "Segments the audio based on the harmonic inconsistency value into speech and music."; - // d9.unit = ""; - // d9.hasFixedBinCount = true; - // d9.binCount = 0; - // d9.hasKnownExtents = true; - // d9.minValue = 0.1; - // d9.maxValue = 0.9; - // d9.isQuantized = false; - // d9.sampleType = OutputDescriptor::VariableSampleRate; - // d9.hasDuration = false; - // d9.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; - // list.push_back(d9); - // - OutputDescriptor d10; - d10.identifier = "localtuning"; - d10.name = "Local tuning"; - d10.description = "Tuning based on the history up to this timestamp."; - d10.unit = "Hz"; - d10.hasFixedBinCount = true; - d10.binCount = 1; - d10.hasKnownExtents = true; - d10.minValue = 427.47; - d10.maxValue = 452.89; - d10.isQuantized = false; - d10.sampleType = OutputDescriptor::FixedSampleRate; - d10.hasDuration = false; - // d10.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; - list.push_back(d10); - - OutputDescriptor d8; - d8.identifier = "harmonicchange"; - d8.name = "Harmonic change value"; - d8.description = "Harmonic change."; - d8.unit = ""; - d8.hasFixedBinCount = true; - d8.binCount = 1; - d8.hasKnownExtents = true; - d8.minValue = 0.0; - d8.maxValue = 0.999; - d8.isQuantized = false; - d8.sampleType = OutputDescriptor::FixedSampleRate; - d8.hasDuration = false; - // d8.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; - list.push_back(d8); + m_outputBothChroma = index++; return list; } @@ -537,44 +183,11 @@ if (debug_on) { cerr << "--> initialise"; } - - if (channels < getMinChannelCount() || - channels > getMaxChannelCount()) return false; - m_blockSize = blockSize; - m_stepSize = stepSize; - frameCount = 0; - int tempn = 256 * m_blockSize/2; - // cerr << "length of tempkernel : " << tempn << endl; - float *tempkernel; - tempkernel = new float[tempn]; + if (!NNLSBase::initialise(channels, stepSize, blockSize)) { + return false; + } - logFreqMatrix(m_inputSampleRate, m_blockSize, tempkernel); - m_kernelValue.clear(); - m_kernelFftIndex.clear(); - m_kernelNoteIndex.clear(); - int countNonzero = 0; - for (unsigned iNote = 0; iNote < nNote; ++iNote) { // I don't know if this is wise: manually making a sparse matrix - for (unsigned iFFT = 0; iFFT < blockSize/2; ++iFFT) { - if (tempkernel[iFFT + blockSize/2 * iNote] > 0) { - m_kernelValue.push_back(tempkernel[iFFT + blockSize/2 * iNote]); - if (tempkernel[iFFT + blockSize/2 * iNote] > 0) { - countNonzero++; - } - m_kernelFftIndex.push_back(iFFT); - m_kernelNoteIndex.push_back(iNote); - } - } - } - // cerr << "nonzero count : " << countNonzero << endl; - delete [] tempkernel; - ofstream myfile; - myfile.open ("matrix.txt"); - // myfile << "Writing this to a file.\n"; - for (int i = 0; i < nNote * 84; ++i) { - myfile << m_dict[i] << endl; - } - myfile.close(); return true; } @@ -582,122 +195,18 @@ NNLSChroma::reset() { if (debug_on) cerr << "--> reset"; - - // Clear buffers, reset stored values, etc - frameCount = 0; - m_dictID = 0; - m_fl.clear(); - m_meanTuning0 = 0; - m_meanTuning1 = 0; - m_meanTuning2 = 0; - m_localTuning0 = 0; - m_localTuning1 = 0; - m_localTuning2 = 0; - m_localTuning.clear(); + NNLSBase::reset(); } NNLSChroma::FeatureSet NNLSChroma::process(const float *const *inputBuffers, Vamp::RealTime timestamp) { if (debug_on) cerr << "--> process" << endl; - frameCount++; - float *magnitude = new float[m_blockSize/2]; - - Feature f10; // local tuning - f10.hasTimestamp = true; - f10.timestamp = timestamp; - const float *fbuf = inputBuffers[0]; - float energysum = 0; - // make magnitude - float maxmag = -10000; - for (size_t iBin = 0; iBin < m_blockSize/2; iBin++) { - magnitude[iBin] = sqrt(fbuf[2 * iBin] * fbuf[2 * iBin] + - fbuf[2 * iBin + 1] * fbuf[2 * iBin + 1]); - if (maxmag < magnitude[iBin]) maxmag = magnitude[iBin]; - if (m_rollon > 0) { - energysum += pow(magnitude[iBin],2); - } - } - - float cumenergy = 0; - if (m_rollon > 0) { - for (size_t iBin = 2; iBin < m_blockSize/2; iBin++) { - cumenergy += pow(magnitude[iBin],2); - if (cumenergy < energysum * m_rollon) magnitude[iBin-2] = 0; - else break; - } - } - - if (maxmag < 2) { - // cerr << "timestamp " << timestamp << ": very low magnitude, setting magnitude to all zeros" << endl; - for (size_t iBin = 0; iBin < m_blockSize/2; iBin++) { - magnitude[iBin] = 0; - } - } - - // note magnitude mapping using pre-calculated matrix - float *nm = new float[nNote]; // note magnitude - for (size_t iNote = 0; iNote < nNote; iNote++) { - nm[iNote] = 0; // initialise as 0 - } - int binCount = 0; - for (vector<float>::iterator it = m_kernelValue.begin(); it != m_kernelValue.end(); ++it) { - // cerr << "."; - nm[m_kernelNoteIndex[binCount]] += magnitude[m_kernelFftIndex[binCount]] * m_kernelValue[binCount]; - // cerr << m_kernelFftIndex[binCount] << " -- " << magnitude[m_kernelFftIndex[binCount]] << " -- "<< m_kernelValue[binCount] << endl; - binCount++; - } - // cerr << nm[20]; - // cerr << endl; - - - float one_over_N = 1.0/frameCount; - // update means of complex tuning variables - m_meanTuning0 *= float(frameCount-1)*one_over_N; - m_meanTuning1 *= float(frameCount-1)*one_over_N; - m_meanTuning2 *= float(frameCount-1)*one_over_N; - - for (int iTone = 0; iTone < 160; iTone = iTone + 3) { - m_meanTuning0 += nm[iTone + 0]*one_over_N; - m_meanTuning1 += nm[iTone + 1]*one_over_N; - m_meanTuning2 += nm[iTone + 2]*one_over_N; - float ratioOld = 0.997; - m_localTuning0 *= ratioOld; m_localTuning0 += nm[iTone + 0] * (1 - ratioOld); - m_localTuning1 *= ratioOld; m_localTuning1 += nm[iTone + 1] * (1 - ratioOld); - m_localTuning2 *= ratioOld; m_localTuning2 += nm[iTone + 2] * (1 - ratioOld); - } - - // if (m_tuneLocal) { - // local tuning - float localTuningImag = sinvalue * m_localTuning1 - sinvalue * m_localTuning2; - float localTuningReal = m_localTuning0 + cosvalue * m_localTuning1 + cosvalue * m_localTuning2; - float normalisedtuning = atan2(localTuningImag, localTuningReal)/(2*M_PI); - m_localTuning.push_back(normalisedtuning); - float tuning440 = 440 * pow(2,normalisedtuning/12); - f10.values.push_back(tuning440); - // cerr << tuning440 << endl; - // } - - Feature f1; // logfreqspec - f1.hasTimestamp = true; - f1.timestamp = timestamp; - for (size_t iNote = 0; iNote < nNote; iNote++) { - f1.values.push_back(nm[iNote]); - } + + NNLSBase::baseProcess(inputBuffers, timestamp); FeatureSet fs; - fs[1].push_back(f1); - fs[8].push_back(f10); - - // deletes - delete[] magnitude; - delete[] nm; - - m_fl.push_back(f1); // remember note magnitude for getRemainingFeatures - char * pPath; - pPath = getenv ("VAMP_PATH"); - - + fs[m_outputLogSpec].push_back(m_logSpectrum[m_logSpectrum.size()-1]); return fs; } @@ -706,8 +215,7 @@ { if (debug_on) cerr << "--> getRemainingFeatures" << endl; FeatureSet fsOut; - if (m_fl.size() == 0) return fsOut; - int nChord = m_chordnames.size(); + if (m_logSpectrum.size() == 0) return fsOut; // /** Calculate Tuning calculate tuning from (using the angle of the complex number defined by the @@ -726,13 +234,6 @@ // cerr << "normalisedtuning: " << normalisedtuning << '\n'; - // push tuning to FeatureSet fsOut - Feature f0; // tuning - f0.hasTimestamp = true; - f0.timestamp = Vamp::RealTime::frame2RealTime(0, lrintf(m_inputSampleRate));; - f0.label = buffer0; - fsOut[0].push_back(f0); - /** Tune Log-Frequency Spectrogram calculate a tuned log-frequency spectrogram (f2): use the tuning estimated above (kinda f0) to perform linear interpolation on the existing log-frequency spectrogram (kinda f1). @@ -745,7 +246,7 @@ // cerr << "tune local ? " << m_tuneLocal << endl; int count = 0; - for (FeatureList::iterator i = m_fl.begin(); i != m_fl.end(); ++i) { + for (FeatureList::iterator i = m_logSpectrum.begin(); i != m_logSpectrum.end(); ++i) { Feature f1 = *i; Feature f2; // tuned log-frequency spectrum f2.hasTimestamp = true; @@ -783,7 +284,7 @@ cerr << "ERROR: negative value in logfreq spectrum" << endl; } } - fsOut[2].push_back(f2); + fsOut[m_outputTunedSpec].push_back(f2); count++; } cerr << "done." << endl; @@ -801,9 +302,6 @@ } - vector<vector<float> > chordogram; - vector<vector<int> > scoreChordogram; - vector<float> chordchange = vector<float>(fsOut[2].size(),0); vector<float> oldchroma = vector<float>(12,0); vector<float> oldbasschroma = vector<float>(12,0); count = 0; @@ -827,7 +325,7 @@ f6.hasTimestamp = true; f6.timestamp = f2.timestamp; - float b[256]; + float b[256]; bool some_b_greater_zero = false; float sumb = 0; @@ -861,34 +359,34 @@ } } else { - float x[84+1000]; + float x[84+1000]; for (int i = 1; i < 1084; ++i) x[i] = 1.0; vector<int> signifIndex; int index=0; sumb /= 84.0; for (unsigned iNote = 2; iNote < nNote - 2; iNote += 3) { float currval = 0; - currval += b[iNote + 1 + -1]; - currval += b[iNote + 1 + 0]; + currval += b[iNote + 1 + -1]; + currval += b[iNote + 1 + 0]; currval += b[iNote + 1 + 1]; if (currval > 0) signifIndex.push_back(index); f3.values.push_back(0); // fill the values, change later index++; } - float rnorm; - float w[84+1000]; - float zz[84+1000]; + float rnorm; + float w[84+1000]; + float zz[84+1000]; int indx[84+1000]; int mode; int dictsize = 256*signifIndex.size(); // cerr << "dictsize is " << dictsize << "and values size" << f3.values.size()<< endl; - float *curr_dict = new float[dictsize]; + float *curr_dict = new float[dictsize]; for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { for (unsigned iBin = 0; iBin < 256; iBin++) { curr_dict[iNote * 256 + iBin] = 1.0 * m_dict[signifIndex[iNote] * 256 + iBin]; } } - nnls(curr_dict, nNote, nNote, signifIndex.size(), b, x, &rnorm, w, zz, indx, &mode); + nnls(curr_dict, nNote, nNote, signifIndex.size(), b, x, &rnorm, w, zz, indx, &mode); delete [] curr_dict; for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { f3.values[signifIndex[iNote]] = x[iNote]; @@ -899,9 +397,6 @@ } } - - - f4.values = chroma; f5.values = basschroma; chroma.insert(chroma.begin(), basschroma.begin(), basschroma.end()); // just stack the both chromas @@ -958,272 +453,16 @@ f6.values[i] /= chromanorm[2]; } } - } - // local chord estimation - vector<float> currentChordSalience; - float tempchordvalue = 0; - float sumchordvalue = 0; - - for (int iChord = 0; iChord < nChord; iChord++) { - tempchordvalue = 0; - for (int iBin = 0; iBin < 12; iBin++) { - tempchordvalue += m_chorddict[24 * iChord + iBin] * chroma[iBin]; - } - for (int iBin = 12; iBin < 24; iBin++) { - tempchordvalue += m_chorddict[24 * iChord + iBin] * chroma[iBin]; - } - sumchordvalue+=tempchordvalue; - currentChordSalience.push_back(tempchordvalue); - } - if (sumchordvalue > 0) { - for (int iChord = 0; iChord < nChord; iChord++) { - currentChordSalience[iChord] /= sumchordvalue; - } - } else { - currentChordSalience[nChord-1] = 1.0; - } - chordogram.push_back(currentChordSalience); - - fsOut[3].push_back(f3); - fsOut[4].push_back(f4); - fsOut[5].push_back(f5); - fsOut[6].push_back(f6); + fsOut[m_outputSemiSpec].push_back(f3); + fsOut[m_outputChroma].push_back(f4); + fsOut[m_outputBassChroma].push_back(f5); + fsOut[m_outputBothChroma].push_back(f6); count++; } cerr << "done." << endl; - - /* Simple chord estimation - I just take the local chord estimates ("currentChordSalience") and average them over time, then - take the maximum. Very simple, don't do this at home... - */ - cerr << "[NNLS Chroma Plugin] Chord Estimation ... "; - count = 0; - int halfwindowlength = m_inputSampleRate / m_stepSize; - vector<int> chordSequence; - for (FeatureList::iterator it = fsOut[6].begin(); it != fsOut[6].end(); ++it) { // initialise the score chordogram - vector<int> temp = vector<int>(nChord,0); - scoreChordogram.push_back(temp); - } - for (FeatureList::iterator it = fsOut[6].begin(); it < fsOut[6].end()-2*halfwindowlength-1; ++it) { - int startIndex = count + 1; - int endIndex = count + 2 * halfwindowlength; - - float chordThreshold = 2.5/nChord;//*(2*halfwindowlength+1); - - vector<int> chordCandidates; - for (unsigned iChord = 0; iChord < nChord-1; iChord++) { - // float currsum = 0; - // for (unsigned iFrame = startIndex; iFrame < endIndex; ++iFrame) { - // currsum += chordogram[iFrame][iChord]; - // } - // if (currsum > chordThreshold) chordCandidates.push_back(iChord); - for (unsigned iFrame = startIndex; iFrame < endIndex; ++iFrame) { - if (chordogram[iFrame][iChord] > chordThreshold) { - chordCandidates.push_back(iChord); - break; - } - } - } - chordCandidates.push_back(nChord-1); - // cerr << chordCandidates.size() << endl; - - float maxval = 0; // will be the value of the most salient *chord change* in this frame - float maxindex = 0; //... and the index thereof - unsigned bestchordL = nChord-1; // index of the best "left" chord - unsigned bestchordR = nChord-1; // index of the best "right" chord - - for (int iWF = 1; iWF < 2*halfwindowlength; ++iWF) { - // now find the max values on both sides of iWF - // left side: - float maxL = 0; - unsigned maxindL = nChord-1; - for (unsigned kChord = 0; kChord < chordCandidates.size(); kChord++) { - unsigned iChord = chordCandidates[kChord]; - float currsum = 0; - for (unsigned iFrame = 0; iFrame < iWF-1; ++iFrame) { - currsum += chordogram[count+iFrame][iChord]; - } - if (iChord == nChord-1) currsum *= 0.8; - if (currsum > maxL) { - maxL = currsum; - maxindL = iChord; - } - } - // right side: - float maxR = 0; - unsigned maxindR = nChord-1; - for (unsigned kChord = 0; kChord < chordCandidates.size(); kChord++) { - unsigned iChord = chordCandidates[kChord]; - float currsum = 0; - for (unsigned iFrame = iWF-1; iFrame < 2*halfwindowlength; ++iFrame) { - currsum += chordogram[count+iFrame][iChord]; - } - if (iChord == nChord-1) currsum *= 0.8; - if (currsum > maxR) { - maxR = currsum; - maxindR = iChord; - } - } - if (maxL+maxR > maxval) { - maxval = maxL+maxR; - maxindex = iWF; - bestchordL = maxindL; - bestchordR = maxindR; - } - - } - // cerr << "maxindex: " << maxindex << ", bestchordR is " << bestchordR << ", of frame " << count << endl; - // add a score to every chord-frame-point that was part of a maximum - for (unsigned iFrame = 0; iFrame < maxindex-1; ++iFrame) { - scoreChordogram[iFrame+count][bestchordL]++; - } - for (unsigned iFrame = maxindex-1; iFrame < 2*halfwindowlength; ++iFrame) { - scoreChordogram[iFrame+count][bestchordR]++; - } - if (bestchordL != bestchordR) chordchange[maxindex+count] += (halfwindowlength - abs(maxindex-halfwindowlength)) * 2.0 / halfwindowlength; - count++; - } - // cerr << "******* agent finished *******" << endl; - count = 0; - for (FeatureList::iterator it = fsOut[6].begin(); it != fsOut[6].end(); ++it) { - float maxval = 0; // will be the value of the most salient chord in this frame - float maxindex = 0; //... and the index thereof - for (unsigned iChord = 0; iChord < nChord; iChord++) { - if (scoreChordogram[count][iChord] > maxval) { - maxval = scoreChordogram[count][iChord]; - maxindex = iChord; - // cerr << iChord << endl; - } - } - chordSequence.push_back(maxindex); - // cerr << "before modefilter, maxindex: " << maxindex << endl; - count++; - } - // cerr << "******* mode filter done *******" << endl; - - - // mode filter on chordSequence - count = 0; - string oldChord = ""; - for (FeatureList::iterator it = fsOut[6].begin(); it != fsOut[6].end(); ++it) { - Feature f6 = *it; - Feature f7; // chord estimate - f7.hasTimestamp = true; - f7.timestamp = f6.timestamp; - Feature f8; // chord estimate - f8.hasTimestamp = true; - f8.timestamp = f6.timestamp; - - vector<int> chordCount = vector<int>(nChord,0); - int maxChordCount = 0; - int maxChordIndex = nChord-1; - string maxChord; - int startIndex = max(count - halfwindowlength/2,0); - int endIndex = min(int(chordogram.size()), count + halfwindowlength/2); - for (int i = startIndex; i < endIndex; i++) { - chordCount[chordSequence[i]]++; - if (chordCount[chordSequence[i]] > maxChordCount) { - // cerr << "start index " << startIndex << endl; - maxChordCount++; - maxChordIndex = chordSequence[i]; - maxChord = m_chordnames[maxChordIndex]; - } - } - // chordSequence[count] = maxChordIndex; - // cerr << maxChordIndex << endl; - f8.values.push_back(chordchange[count]/(halfwindowlength*2)); - // cerr << chordchange[count] << endl; - fsOut[9].push_back(f8); - if (oldChord != maxChord) { - oldChord = maxChord; - - // char buffer1 [50]; - // if (maxChordIndex < nChord - 1) { - // sprintf(buffer1, "%s%s", notenames[maxChordIndex % 12 + 12], chordtypes[maxChordIndex]); - // } else { - // sprintf(buffer1, "N"); - // } - // f7.label = buffer1; - f7.label = m_chordnames[maxChordIndex]; - fsOut[7].push_back(f7); - } - count++; - } - Feature f7; // last chord estimate - f7.hasTimestamp = true; - f7.timestamp = fsOut[6][fsOut[6].size()-1].timestamp; - f7.label = "N"; - fsOut[7].push_back(f7); - cerr << "done." << endl; - // // musicity - // count = 0; - // int oldlabeltype = 0; // start value is 0, music is 1, speech is 2 - // vector<float> musicityValue; - // for (FeatureList::iterator it = fsOut[4].begin(); it != fsOut[4].end(); ++it) { - // Feature f4 = *it; - // - // int startIndex = max(count - musicitykernelwidth/2,0); - // int endIndex = min(int(chordogram.size()), startIndex + musicitykernelwidth - 1); - // float chromasum = 0; - // float diffsum = 0; - // for (int k = 0; k < 12; k++) { - // for (int i = startIndex + 1; i < endIndex; i++) { - // chromasum += pow(fsOut[4][i].values[k],2); - // diffsum += abs(fsOut[4][i-1].values[k] - fsOut[4][i].values[k]); - // } - // } - // diffsum /= chromasum; - // musicityValue.push_back(diffsum); - // count++; - // } - // - // float musicityThreshold = 0.44; - // if (m_stepSize == 4096) { - // musicityThreshold = 0.74; - // } - // if (m_stepSize == 4410) { - // musicityThreshold = 0.77; - // } - // - // count = 0; - // for (FeatureList::iterator it = fsOut[4].begin(); it != fsOut[4].end(); ++it) { - // Feature f4 = *it; - // Feature f8; // musicity - // Feature f9; // musicity segmenter - // - // f8.hasTimestamp = true; - // f8.timestamp = f4.timestamp; - // f9.hasTimestamp = true; - // f9.timestamp = f4.timestamp; - // - // int startIndex = max(count - musicitykernelwidth/2,0); - // int endIndex = min(int(chordogram.size()), startIndex + musicitykernelwidth - 1); - // int musicityCount = 0; - // for (int i = startIndex; i <= endIndex; i++) { - // if (musicityValue[i] > musicityThreshold) musicityCount++; - // } - // bool isSpeech = (2 * musicityCount > endIndex - startIndex + 1); - // - // if (isSpeech) { - // if (oldlabeltype != 2) { - // f9.label = "Speech"; - // fsOut[9].push_back(f9); - // oldlabeltype = 2; - // } - // } else { - // if (oldlabeltype != 1) { - // f9.label = "Music"; - // fsOut[9].push_back(f9); - // oldlabeltype = 1; - // } - // } - // f8.values.push_back(musicityValue[count]); - // fsOut[8].push_back(f8); - // count++; - // } return fsOut; }
--- a/NNLSChroma.h Fri Oct 22 16:19:40 2010 +0900 +++ b/NNLSChroma.h Fri Oct 22 11:30:21 2010 +0100 @@ -1,21 +1,30 @@ /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ -// Remember to use a different guard symbol in each header! +/* + NNLS-Chroma / Chordino + + Audio feature extraction plugins for chromagram and chord + estimation. + + Centre for Digital Music, Queen Mary University of London. + This file copyright 2008-2010 Matthias Mauch and QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + #ifndef _NNLS_CHROMA_ #define _NNLS_CHROMA_ -#include <vamp-sdk/Plugin.h> -#include <list> -// #include "FFT.h" +#include "NNLSBase.h" + using namespace std; -using std::string; -class ChordTranscriberData; - - - -class NNLSChroma : public Vamp::Plugin +class NNLSChroma : public NNLSBase { public: NNLSChroma(float inputSampleRate); @@ -24,61 +33,23 @@ string getIdentifier() const; string getName() const; string getDescription() const; - string getMaker() const; - int getPluginVersion() const; - string getCopyright() const; - - InputDomain getInputDomain() const; - size_t getPreferredBlockSize() const; - size_t getPreferredStepSize() const; - size_t getMinChannelCount() const; - size_t getMaxChannelCount() const; - - ParameterList getParameterDescriptors() const; - float getParameter(string identifier) const; - void setParameter(string identifier, float value); - - ProgramList getPrograms() const; - string getCurrentProgram() const; - void selectProgram(string name); OutputList getOutputDescriptors() const; + FeatureSet process(const float *const *inputBuffers, + Vamp::RealTime timestamp); + FeatureSet getRemainingFeatures(); + bool initialise(size_t channels, size_t stepSize, size_t blockSize); void reset(); - FeatureSet process(const float *const *inputBuffers, - Vamp::RealTime timestamp); - - FeatureSet getRemainingFeatures(); - protected: - // plugin-specific data and methods go here - int frameCount; - FeatureList m_fl; - size_t m_blockSize; - size_t m_stepSize; - int m_lengthOfNoteIndex; - float m_meanTuning0; - float m_meanTuning1; - float m_meanTuning2; - float m_localTuning0; - float m_localTuning1; - float m_localTuning2; - float m_paling; - float m_preset; - vector<float> m_localTuning; - vector<float> m_kernelValue; - vector<int> m_kernelFftIndex; - vector<int> m_kernelNoteIndex; - float *m_dict; - bool m_tuneLocal; - int m_dictID; - vector<float> m_chorddict; - vector<string> m_chordnames; - float m_doNormalizeChroma; - float m_rollon; - // list< vector< float > > *logfreqSpecList; + mutable int m_outputLogSpec; + mutable int m_outputTunedSpec; + mutable int m_outputSemiSpec; + mutable int m_outputChroma; + mutable int m_outputBassChroma; + mutable int m_outputBothChroma; };
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tuning.cpp Fri Oct 22 11:30:21 2010 +0100 @@ -0,0 +1,181 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + NNLS-Chroma / Chordino + + Audio feature extraction plugins for chromagram and chord + estimation. + + Centre for Digital Music, Queen Mary University of London. + This file copyright 2008-2010 Matthias Mauch and QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include "Tuning.h" + +#include "chromamethods.h" + +#include <cstdlib> +#include <fstream> +#include <cmath> + +#include <algorithm> + +const bool debug_on = false; + +const vector<float> hw(hammingwind, hammingwind+19); + +Tuning::Tuning(float inputSampleRate) : + NNLSBase(inputSampleRate) +{ + if (debug_on) cerr << "--> Tuning" << endl; +} + +Tuning::~Tuning() +{ + if (debug_on) cerr << "--> ~Tuning" << endl; +} + +string +Tuning::getIdentifier() const +{ + if (debug_on) cerr << "--> getIdentifier" << endl; + return "tuning"; +} + +string +Tuning::getName() const +{ + if (debug_on) cerr << "--> getName" << endl; + return "Tuning"; +} + +string +Tuning::getDescription() const +{ + // Return something helpful here! + if (debug_on) cerr << "--> getDescription" << endl; + return "This plugin provides a number of features derived from a log-frequency amplitude spectrum of the DFT: some variants of the log-frequency spectrum, including a semitone spectrum derived from approximate transcription using the NNLS algorithm; based on this semitone spectrum, chroma features and a simple chord estimate."; +} + +Tuning::OutputList +Tuning::getOutputDescriptors() const +{ + if (debug_on) cerr << "--> getOutputDescriptors" << endl; + OutputList list; + + int index = 0; + + OutputDescriptor d0; + d0.identifier = "tuning"; + d0.name = "Tuning"; + d0.description = "The concert pitch."; + d0.unit = "Hz"; + d0.hasFixedBinCount = true; + d0.binCount = 0; + d0.hasKnownExtents = true; + d0.minValue = 427.47; + d0.maxValue = 452.89; + d0.isQuantized = false; + d0.sampleType = OutputDescriptor::VariableSampleRate; + d0.hasDuration = false; + list.push_back(d0); + m_outputTuning = index++; + + OutputDescriptor d10; + d10.identifier = "localtuning"; + d10.name = "Local tuning"; + d10.description = "Tuning based on the history up to this timestamp."; + d10.unit = "Hz"; + d10.hasFixedBinCount = true; + d10.binCount = 1; + d10.hasKnownExtents = true; + d10.minValue = 427.47; + d10.maxValue = 452.89; + d10.isQuantized = false; + d10.sampleType = OutputDescriptor::FixedSampleRate; + d10.hasDuration = false; + // d10.sampleRate = (m_stepSize == 0) ? m_inputSampleRate/2048 : m_inputSampleRate/m_stepSize; + list.push_back(d10); + m_outputLocalTuning = index++; + + return list; +} + + +bool +Tuning::initialise(size_t channels, size_t stepSize, size_t blockSize) +{ + if (debug_on) { + cerr << "--> initialise"; + } + + if (!NNLSBase::initialise(channels, stepSize, blockSize)) { + return false; + } + + return true; +} + +void +Tuning::reset() +{ + if (debug_on) cerr << "--> reset"; + NNLSBase::reset(); +} + +Tuning::FeatureSet +Tuning::process(const float *const *inputBuffers, Vamp::RealTime timestamp) +{ + if (debug_on) cerr << "--> process" << endl; + + NNLSBase::baseProcess(inputBuffers, timestamp); + + Feature f10; // local tuning + f10.hasTimestamp = true; + f10.timestamp = timestamp; + float normalisedtuning = m_localTuning[m_localTuning.size()-1]; + float tuning440 = 440 * pow(2,normalisedtuning/12); + f10.values.push_back(tuning440); + + FeatureSet fs; + fs[m_outputLocalTuning].push_back(f10); + return fs; +} + +Tuning::FeatureSet +Tuning::getRemainingFeatures() +{ + if (debug_on) cerr << "--> getRemainingFeatures" << endl; + FeatureSet fsOut; + if (m_logSpectrum.size() == 0) return fsOut; + + // + /** Calculate Tuning + calculate tuning from (using the angle of the complex number defined by the + cumulative mean real and imag values) + **/ + float meanTuningImag = sinvalue * m_meanTuning1 - sinvalue * m_meanTuning2; + float meanTuningReal = m_meanTuning0 + cosvalue * m_meanTuning1 + cosvalue * m_meanTuning2; + float cumulativetuning = 440 * pow(2,atan2(meanTuningImag, meanTuningReal)/(24*M_PI)); + + char buffer0 [50]; + + sprintf(buffer0, "estimated tuning: %0.1f Hz", cumulativetuning); + + // push tuning to FeatureSet fsOut + Feature f0; // tuning + f0.hasTimestamp = true; + f0.timestamp = Vamp::RealTime::frame2RealTime(0, lrintf(m_inputSampleRate));; + f0.label = buffer0; + fsOut[m_outputTuning].push_back(f0); + + return fsOut; + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tuning.h Fri Oct 22 11:30:21 2010 +0100 @@ -0,0 +1,53 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + NNLS-Chroma / Chordino + + Audio feature extraction plugins for chromagram and chord + estimation. + + Centre for Digital Music, Queen Mary University of London. + This file copyright 2008-2010 Matthias Mauch and QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef _TUNING_ +#define _TUNING_ + +#include "NNLSBase.h" + +using namespace std; + + +class Tuning : public NNLSBase +{ +public: + Tuning(float inputSampleRate); + virtual ~Tuning(); + + string getIdentifier() const; + string getName() const; + string getDescription() const; + + OutputList getOutputDescriptors() const; + + FeatureSet process(const float *const *inputBuffers, + Vamp::RealTime timestamp); + FeatureSet getRemainingFeatures(); + + bool initialise(size_t channels, size_t stepSize, size_t blockSize); + void reset(); + +protected: + mutable int m_outputTuning; + mutable int m_outputLocalTuning; +}; + + + +#endif
--- a/chromamethods.cpp Fri Oct 22 16:19:40 2010 +0900 +++ b/chromamethods.cpp Fri Oct 22 11:30:21 2010 +0100 @@ -1,3 +1,21 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + NNLS-Chroma / Chordino + + Audio feature extraction plugins for chromagram and chord + estimation. + + Centre for Digital Music, Queen Mary University of London. + This file copyright 2008-2010 Matthias Mauch and QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + #include "chromamethods.h" #include <cmath> @@ -198,16 +216,6 @@ } -string get_env_var( std::string const & key ) { - char * val; - val = getenv( key.c_str() ); - string retval; - if (val != NULL) { - retval = val; - } - return retval; -} - static std::vector<std::string> getPluginPath()
--- a/chromamethods.h Fri Oct 22 16:19:40 2010 +0900 +++ b/chromamethods.h Fri Oct 22 11:30:21 2010 +0100 @@ -1,3 +1,20 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + NNLS-Chroma / Chordino + + Audio feature extraction plugins for chromagram and chord + estimation. + + Centre for Digital Music, Queen Mary University of London. + This file copyright 2008-2010 Matthias Mauch and QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ #ifndef _CHROMA_METHODS_H_ #define _CHROMA_METHODS_H_
--- a/nnls.c Fri Oct 22 16:19:40 2010 +0900 +++ b/nnls.c Fri Oct 22 11:30:21 2010 +0100 @@ -1,5 +1,16 @@ #include "nnls.h" +/* + NNLS-Chroma / Chordino + + This file is converted from the Netlib FORTRAN code NNLS.FOR, + developed by Charles L. Lawson and Richard J. Hanson at Jet + Propulsion Laboratory 1973 JUN 15, and published in the book + "SOLVING LEAST SQUARES PROBLEMS", Prentice-Hall, 1974. + + Refer to nnls.f for the original code and comments. +*/ + #include <math.h> #define nnls_max(a,b) ((a) >= (b) ? (a) : (b))
--- a/plugins.cpp Fri Oct 22 16:19:40 2010 +0900 +++ b/plugins.cpp Fri Oct 22 11:30:21 2010 +0100 @@ -1,22 +1,33 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ -// This is a skeleton file for use in creating your own plugin -// libraries. Replace MyPlugin and myPlugin throughout with the name -// of your first plugin class, and fill in the gaps as appropriate. +/* + NNLS-Chroma / Chordino + Audio feature extraction plugins for chromagram and chord + estimation. + + Centre for Digital Music, Queen Mary University of London. + This file copyright 2008-2010 Matthias Mauch and QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ #include <vamp/vamp.h> #include <vamp-sdk/PluginAdapter.h> #include "NNLSChroma.h" +#include "Chordino.h" +#include "Tuning.h" -// Declare one static adapter here for each plugin class in this library. +static Vamp::PluginAdapter<NNLSChroma> chromaAdapter; +static Vamp::PluginAdapter<Chordino> chordinoAdapter; +static Vamp::PluginAdapter<Tuning> tuningAdapter; -static Vamp::PluginAdapter<NNLSChroma> myPluginAdapter; - - -// This is the entry-point for the library, and the only function that -// needs to be publicly exported. const VampPluginDescriptor * vampGetPluginDescriptor(unsigned int version, unsigned int index) @@ -29,7 +40,9 @@ // library.) switch (index) { - case 0: return myPluginAdapter.getDescriptor(); + case 0: return chromaAdapter.getDescriptor(); + case 1: return chordinoAdapter.getDescriptor(); + case 2: return tuningAdapter.getDescriptor(); default: return 0; } }