comparison plugins/GetModePlugin.cpp @ 19:799b13ab3792

* Add key mode detector
author Chris Cannam <c.cannam@qmul.ac.uk>
date Mon, 11 Dec 2006 09:57:19 +0000
parents
children 1f1881046b0c
comparison
equal deleted inserted replaced
18:99dadc93042e 19:799b13ab3792
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Vamp
5
6 An API for audio analysis and feature extraction plugins.
7
8 Centre for Digital Music, Queen Mary, University of London.
9 Copyright 2006 Chris Cannam.
10
11 Permission is hereby granted, free of charge, to any person
12 obtaining a copy of this software and associated documentation
13 files (the "Software"), to deal in the Software without
14 restriction, including without limitation the rights to use, copy,
15 modify, merge, publish, distribute, sublicense, and/or sell copies
16 of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be
20 included in all copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 Except as contained in this notice, the names of the Centre for
31 Digital Music; Queen Mary, University of London; and Chris Cannam
32 shall not be used in advertising or otherwise to promote the sale,
33 use or other dealings in this Software without prior written
34 authorization.
35 */
36
37 #include "GetModePlugin.h"
38
39 using std::string;
40 using std::vector;
41 //using std::cerr;
42 using std::endl;
43
44 #include <cmath>
45
46
47 GetModePlugin::GetModePlugin(float inputSampleRate) :
48 Plugin(inputSampleRate),
49 m_stepSize(0),
50 m_blockSize(32768),
51 m_GetMode(0),
52 m_InputFrame(0),
53 m_BlockandHopSize(0)
54 {
55 m_BlockandHopSize= 32768;
56 }
57
58 GetModePlugin::~GetModePlugin()
59 {
60 if( m_GetMode )
61 {
62 delete m_GetMode;
63 m_GetMode = 0;
64 }
65
66 if( m_InputFrame )
67 {
68 delete [] m_InputFrame;
69 m_InputFrame = 0;
70 }
71 }
72
73 string
74 GetModePlugin::getName() const
75 {
76 return "qm-keymode";
77 }
78
79 string
80 GetModePlugin::getDescription() const
81 {
82 return "Key Mode";
83 }
84
85 string
86 GetModePlugin::getMaker() const
87 {
88 return "Katy Noland and Christian Landone";
89 }
90
91 int
92 GetModePlugin::getPluginVersion() const
93 {
94 return 2;
95 }
96
97 string
98 GetModePlugin::getCopyright() const
99 {
100 return "Centre for Digital Music QMUL";
101 }
102
103 bool
104 GetModePlugin::initialise(size_t channels, size_t stepSize, size_t blockSize)
105 {
106 if (channels < getMinChannelCount() ||
107 channels > getMaxChannelCount()) return false;
108
109 m_stepSize = stepSize;
110 m_blockSize = blockSize;
111
112 if( stepSize != m_BlockandHopSize || blockSize != m_BlockandHopSize )
113 return false;
114
115 m_GetMode = new GetKeyMode( 10, 10 );
116
117 m_InputFrame = new double[m_BlockandHopSize];
118
119 return true;
120 }
121
122 void
123 GetModePlugin::reset()
124 {
125 for( unsigned int i = 0; i < m_BlockandHopSize; i++ )
126 {
127 m_InputFrame[ i ] = 0.0;
128 }
129 }
130
131
132 GetModePlugin::OutputList
133 GetModePlugin::getOutputDescriptors() const
134 {
135 OutputList list;
136
137 OutputDescriptor d;
138 d.name = "mode";
139 d.unit = "";
140 d.description = "Key Mode";
141 d.hasFixedBinCount = true;
142 d.binCount = 1;
143 d.hasKnownExtents = true;
144 d.isQuantized = true;
145 d.minValue = 0;
146 d.maxValue = 1;
147 d.quantizeStep = 1;
148 d.binNames.push_back("Major = 0, Minor = 1");
149 d.sampleType = OutputDescriptor::OneSamplePerStep;
150 list.push_back(d);
151
152 return list;
153 }
154
155 GetModePlugin::FeatureSet
156 GetModePlugin::process(const float *const *inputBuffers,
157 Vamp::RealTime)
158 {
159 if (m_stepSize == 0) {
160 return FeatureSet();
161 }
162
163 FeatureSet returnFeatures;
164
165 for( unsigned int i = 0 ; i < m_BlockandHopSize; i++ )
166 {
167 m_InputFrame[i] = (double)inputBuffers[0][i];
168 }
169
170
171 int minor = m_GetMode->process( m_InputFrame );
172
173 Feature feature;
174 feature.hasTimestamp = false;
175
176 feature.values.push_back((float)minor);
177 returnFeatures[0].push_back(feature);
178 feature.values.clear();
179
180 return returnFeatures;
181 }
182
183 GetModePlugin::FeatureSet
184 GetModePlugin::getRemainingFeatures()
185 {
186 return FeatureSet();
187 }
188
189
190 size_t
191 GetModePlugin::getPreferredStepSize() const
192 {
193 return 0;
194 }
195
196 size_t
197 GetModePlugin::getPreferredBlockSize() const
198 {
199 return 32768;
200 }
201