Mercurial > hg > gpsynth
diff src/file_comparer.hpp @ 0:add35537fdbb tip
Initial import
author | irh <ian.r.hobson@gmail.com> |
---|---|
date | Thu, 25 Aug 2011 11:05:55 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/file_comparer.hpp Thu Aug 25 11:05:55 2011 +0100 @@ -0,0 +1,94 @@ +// Copyright 2011, Ian Hobson. +// +// This file is part of gpsynth. +// +// gpsynth 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 3 of the License, or +// (at your option) any later version. +// +// gpsynth is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with gpsynth in the file COPYING. +// If not, see http://www.gnu.org/licenses/. + +// FileComparer - Compares sounds against a target set of audio features that +// have been retrieved from FeatureExtractor + +#pragma once + +#include "feature_extractor.hpp" + +#include "boost/shared_ptr.hpp" + +#include <map> +#include <string> +#include <vector> + +namespace dsp { + +struct FeatureComparerInterface { + virtual ~FeatureComparerInterface() {} + + virtual void AnalyzeTarget() = 0; + virtual Value Compare() = 0; + virtual FeatureComparerInterface* Clone() const = 0; + virtual void SetExtractor(FeatureExtractor* extractor) = 0; + virtual int ID() const = 0; +}; + +typedef boost::shared_ptr<FeatureComparerInterface> FeatureComparerPtr; + + +class FileComparer { +public: + + struct Feature { + enum ID { + Pitch, + Energy, + MFCCs, + DeltaMFCCs, + DoubleDeltaMFCCs, + Magnitude, + LogMagnitude, + SpectralCentroid, + SpectralSpread, + SpectralFlux + }; + }; + +private: + std::string target_file_; + Value target_duration_; + std::vector<FeatureComparerPtr> features_; + FeatureExtractor extractor_; + std::map<std::string, Feature::ID> feature_names_; + +public: + // copy constructor + FileComparer(const FileComparer& other); + FileComparer(int window_size = 1024, + int hop_size = 256); + FileComparer(const std::string& feature_list, + int window_size = 1024, + int hop_size = 256); + + void SetTargetFile(const std::string& target_file); + Value CompareFile(const std::string& file_path); + void SetFeatureExtractorSettings(int window_size, int hop_size); + + Value TargetDuration() const { return target_duration_; } + + void EnableFeature(Feature::ID feature, bool enable = true); + void EnableFeatures(const std::vector<Feature::ID>& features, + bool enable = true); + void EnableFeatures(std::string feature_name_list, bool enable = true); + void SetFeatures(const std::vector<Feature::ID>& features); +}; + +} // dsp namespace