annotate 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
rev   line source
ian@0 1 // Copyright 2011, Ian Hobson.
ian@0 2 //
ian@0 3 // This file is part of gpsynth.
ian@0 4 //
ian@0 5 // gpsynth is free software: you can redistribute it and/or modify
ian@0 6 // it under the terms of the GNU General Public License as published by
ian@0 7 // the Free Software Foundation, either version 3 of the License, or
ian@0 8 // (at your option) any later version.
ian@0 9 //
ian@0 10 // gpsynth is distributed in the hope that it will be useful,
ian@0 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
ian@0 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ian@0 13 // GNU General Public License for more details.
ian@0 14 //
ian@0 15 // You should have received a copy of the GNU General Public License
ian@0 16 // along with gpsynth in the file COPYING.
ian@0 17 // If not, see http://www.gnu.org/licenses/.
ian@0 18
ian@0 19 // FileComparer - Compares sounds against a target set of audio features that
ian@0 20 // have been retrieved from FeatureExtractor
ian@0 21
ian@0 22 #pragma once
ian@0 23
ian@0 24 #include "feature_extractor.hpp"
ian@0 25
ian@0 26 #include "boost/shared_ptr.hpp"
ian@0 27
ian@0 28 #include <map>
ian@0 29 #include <string>
ian@0 30 #include <vector>
ian@0 31
ian@0 32 namespace dsp {
ian@0 33
ian@0 34 struct FeatureComparerInterface {
ian@0 35 virtual ~FeatureComparerInterface() {}
ian@0 36
ian@0 37 virtual void AnalyzeTarget() = 0;
ian@0 38 virtual Value Compare() = 0;
ian@0 39 virtual FeatureComparerInterface* Clone() const = 0;
ian@0 40 virtual void SetExtractor(FeatureExtractor* extractor) = 0;
ian@0 41 virtual int ID() const = 0;
ian@0 42 };
ian@0 43
ian@0 44 typedef boost::shared_ptr<FeatureComparerInterface> FeatureComparerPtr;
ian@0 45
ian@0 46
ian@0 47 class FileComparer {
ian@0 48 public:
ian@0 49
ian@0 50 struct Feature {
ian@0 51 enum ID {
ian@0 52 Pitch,
ian@0 53 Energy,
ian@0 54 MFCCs,
ian@0 55 DeltaMFCCs,
ian@0 56 DoubleDeltaMFCCs,
ian@0 57 Magnitude,
ian@0 58 LogMagnitude,
ian@0 59 SpectralCentroid,
ian@0 60 SpectralSpread,
ian@0 61 SpectralFlux
ian@0 62 };
ian@0 63 };
ian@0 64
ian@0 65 private:
ian@0 66 std::string target_file_;
ian@0 67 Value target_duration_;
ian@0 68 std::vector<FeatureComparerPtr> features_;
ian@0 69 FeatureExtractor extractor_;
ian@0 70 std::map<std::string, Feature::ID> feature_names_;
ian@0 71
ian@0 72 public:
ian@0 73 // copy constructor
ian@0 74 FileComparer(const FileComparer& other);
ian@0 75 FileComparer(int window_size = 1024,
ian@0 76 int hop_size = 256);
ian@0 77 FileComparer(const std::string& feature_list,
ian@0 78 int window_size = 1024,
ian@0 79 int hop_size = 256);
ian@0 80
ian@0 81 void SetTargetFile(const std::string& target_file);
ian@0 82 Value CompareFile(const std::string& file_path);
ian@0 83 void SetFeatureExtractorSettings(int window_size, int hop_size);
ian@0 84
ian@0 85 Value TargetDuration() const { return target_duration_; }
ian@0 86
ian@0 87 void EnableFeature(Feature::ID feature, bool enable = true);
ian@0 88 void EnableFeatures(const std::vector<Feature::ID>& features,
ian@0 89 bool enable = true);
ian@0 90 void EnableFeatures(std::string feature_name_list, bool enable = true);
ian@0 91 void SetFeatures(const std::vector<Feature::ID>& features);
ian@0 92 };
ian@0 93
ian@0 94 } // dsp namespace