#ifndef NoteCounter_hxx #define NoteCounter_hxx #include #include #include #include #include #include #include #include #include // Those two configuration types could be the ones you choose. // Your own ones or any type already in CLAM. #include "CLAM/Fundamental.hxx" #include class NoteCounter : public CLAM::Processing { //in ports CLAM::InPort mIn; CLAM::InPort mIn; typedef CLAM::NullProcessingConfig Config; //variables public: CLAM::TData _lastValue; bool _increasing; unsigned _nNotes; std::vector notes; int output; int median; //clam configuration const char* GetClassName() const { return "NoteCounter"; } NoteCounter(const Config & config=Config()) : mIn("Input", this) : mIn("Fundamental", this) { Configure( config ); _lastValue=0; _increasing=true; _nNotes=0; } ~NoteCounter() {} // Configuration to the minimal expression bool ConcreteConfigure(const CLAM::ProcessingConfig&) { return true; // I got proper configuration } const CLAM::ProcessingConfig& GetConfig() const { static Config config; return config; } bool Do() { bool result = Do(mIn.GetData()); notes.reserve(450); // Tell the ports this is done mIn.Consume(); return result; } bool Do(const CLAM::SpectralPeakArray & in) { const CLAM::Array & magnitudes = mIn.GetData().GetMagBuffer(); CLAM::TData sum=0; for (int i=0;i= .04) { sum+=pow(10,magnitudes[i]/20); } } bool thisOneIncreasing = _lastValue<=sum; if (thisOneIncreasing && !_increasing) _nNotes++; _increasing=thisOneIncreasing; _lastValue=sum; return 1; } bool Do(const CLAM::Fundamental& in) { CLAM::TData newNote = in.GetCandidatesFreq()[0]; if (newNote<1.0) return true; std::vector::iterator it = std::lower_bound(notes.begin(), notes.end(), newNote); notes.insert(it, newNote); return true; } bool ConcreteStop() { std::cout << _nNotes << std::endl; std::sort(notes.begin(), notes.end()); int median = notes[notes.size()/2]; std::cout << median << std::endl; //std::copy(notes.begin(), notes.end(), std::ostream_iterator(std::cout, "\n")); return 1; } }; #endif // NoteCounter_hxx