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