ian@0: // Copyright 2011, Ian Hobson. ian@0: // ian@0: // This file is part of gpsynth. ian@0: // ian@0: // gpsynth is free software: you can redistribute it and/or modify ian@0: // it under the terms of the GNU General Public License as published by ian@0: // the Free Software Foundation, either version 3 of the License, or ian@0: // (at your option) any later version. ian@0: // ian@0: // gpsynth is distributed in the hope that it will be useful, ian@0: // but WITHOUT ANY WARRANTY; without even the implied warranty of ian@0: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ian@0: // GNU General Public License for more details. ian@0: // ian@0: // You should have received a copy of the GNU General Public License ian@0: // along with gpsynth in the file COPYING. ian@0: // If not, see http://www.gnu.org/licenses/. ian@0: ian@0: // FileComparer - Compares sounds against a target set of audio features that ian@0: // have been retrieved from FeatureExtractor ian@0: ian@0: #pragma once ian@0: ian@0: #include "feature_extractor.hpp" ian@0: ian@0: #include "boost/shared_ptr.hpp" ian@0: ian@0: #include ian@0: #include ian@0: #include ian@0: ian@0: namespace dsp { ian@0: ian@0: struct FeatureComparerInterface { ian@0: virtual ~FeatureComparerInterface() {} ian@0: ian@0: virtual void AnalyzeTarget() = 0; ian@0: virtual Value Compare() = 0; ian@0: virtual FeatureComparerInterface* Clone() const = 0; ian@0: virtual void SetExtractor(FeatureExtractor* extractor) = 0; ian@0: virtual int ID() const = 0; ian@0: }; ian@0: ian@0: typedef boost::shared_ptr FeatureComparerPtr; ian@0: ian@0: ian@0: class FileComparer { ian@0: public: ian@0: ian@0: struct Feature { ian@0: enum ID { ian@0: Pitch, ian@0: Energy, ian@0: MFCCs, ian@0: DeltaMFCCs, ian@0: DoubleDeltaMFCCs, ian@0: Magnitude, ian@0: LogMagnitude, ian@0: SpectralCentroid, ian@0: SpectralSpread, ian@0: SpectralFlux ian@0: }; ian@0: }; ian@0: ian@0: private: ian@0: std::string target_file_; ian@0: Value target_duration_; ian@0: std::vector features_; ian@0: FeatureExtractor extractor_; ian@0: std::map feature_names_; ian@0: ian@0: public: ian@0: // copy constructor ian@0: FileComparer(const FileComparer& other); ian@0: FileComparer(int window_size = 1024, ian@0: int hop_size = 256); ian@0: FileComparer(const std::string& feature_list, ian@0: int window_size = 1024, ian@0: int hop_size = 256); ian@0: ian@0: void SetTargetFile(const std::string& target_file); ian@0: Value CompareFile(const std::string& file_path); ian@0: void SetFeatureExtractorSettings(int window_size, int hop_size); ian@0: ian@0: Value TargetDuration() const { return target_duration_; } ian@0: ian@0: void EnableFeature(Feature::ID feature, bool enable = true); ian@0: void EnableFeatures(const std::vector& features, ian@0: bool enable = true); ian@0: void EnableFeatures(std::string feature_name_list, bool enable = true); ian@0: void SetFeatures(const std::vector& features); ian@0: }; ian@0: ian@0: } // dsp namespace