#ifndef MyProcessing_hxx #define MyProcessing_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 MyProcessing : public CLAM::Processing { CLAM::InPort mIn; typedef CLAM::NullProcessingConfig Config; public: std::vector notes; int output; int median; const char* GetClassName() const { return "MyProcessing"; } MyProcessing(const Config & config=Config()) : mIn("CLAM::Fundamental", this) { Configure( config ); } ~MyProcessing() {} // 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::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() { //calculate median std::sort(notes.begin(), notes.end()); int median = notes[notes.size()/2]; //std::copy(notes.begin(), notes.end(), std::ostream_iterator(std::cout, "\n")); if (median < 2800){ std::cout << "This is probably a begging call." << std::endl; } else if (median > 3200 && median < 3850) {std::cout << "This is most likely a greeting call." << std::endl;} else { std::cout << "Too close to call." << std::endl;} std::cout << "The median is: " << median << "." << std::endl; return 1; } }; #endif // MyProcessing_hxx