cannam@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@0
|
2
|
cannam@0
|
3 /*
|
cannam@0
|
4 Vamp feature extraction plugins using Paul Brossier's Aubio library.
|
cannam@0
|
5
|
cannam@0
|
6 Centre for Digital Music, Queen Mary, University of London.
|
cannam@0
|
7 This file copyright 2006 Chris Cannam.
|
cannam@0
|
8
|
cannam@0
|
9 This program is free software; you can redistribute it and/or
|
cannam@0
|
10 modify it under the terms of the GNU General Public License as
|
cannam@0
|
11 published by the Free Software Foundation; either version 2 of the
|
cannam@0
|
12 License, or (at your option) any later version. See the file
|
cannam@0
|
13 COPYING included with this distribution for more information.
|
cannam@0
|
14
|
cannam@0
|
15 */
|
cannam@0
|
16
|
piem@2
|
17 #include <math.h>
|
cannam@0
|
18 #include "Pitch.h"
|
cannam@0
|
19
|
cannam@0
|
20 using std::string;
|
cannam@0
|
21 using std::vector;
|
cannam@0
|
22 using std::cerr;
|
cannam@0
|
23 using std::endl;
|
cannam@0
|
24
|
cannam@0
|
25 Pitch::Pitch(float inputSampleRate) :
|
cannam@0
|
26 Plugin(inputSampleRate),
|
cannam@0
|
27 m_ibuf(0),
|
cannam@0
|
28 m_pitchdet(0),
|
piem@2
|
29 m_pitchtype(aubio_pitch_yinfft),
|
cannam@0
|
30 m_pitchmode(aubio_pitchm_freq)
|
cannam@0
|
31 {
|
cannam@0
|
32 }
|
cannam@0
|
33
|
cannam@0
|
34 Pitch::~Pitch()
|
cannam@0
|
35 {
|
cannam@0
|
36 if (m_pitchdet) del_aubio_pitchdetection(m_pitchdet);
|
cannam@0
|
37 if (m_ibuf) del_fvec(m_ibuf);
|
cannam@0
|
38 }
|
cannam@0
|
39
|
cannam@0
|
40 string
|
cannam@13
|
41 Pitch::getIdentifier() const
|
cannam@0
|
42 {
|
cannam@0
|
43 return "aubiopitch";
|
cannam@0
|
44 }
|
cannam@0
|
45
|
cannam@0
|
46 string
|
cannam@13
|
47 Pitch::getName() const
|
cannam@13
|
48 {
|
cannam@13
|
49 return "Aubio Pitch Detector";
|
cannam@13
|
50 }
|
cannam@13
|
51
|
cannam@13
|
52 string
|
cannam@0
|
53 Pitch::getDescription() const
|
cannam@0
|
54 {
|
cannam@13
|
55 return "Track estimated note pitches";
|
cannam@0
|
56 }
|
cannam@0
|
57
|
cannam@0
|
58 string
|
cannam@0
|
59 Pitch::getMaker() const
|
cannam@0
|
60 {
|
cannam@0
|
61 return "Paul Brossier (plugin by Chris Cannam)";
|
cannam@0
|
62 }
|
cannam@0
|
63
|
cannam@0
|
64 int
|
cannam@0
|
65 Pitch::getPluginVersion() const
|
cannam@0
|
66 {
|
cannam@0
|
67 return 1;
|
cannam@0
|
68 }
|
cannam@0
|
69
|
cannam@0
|
70 string
|
cannam@0
|
71 Pitch::getCopyright() const
|
cannam@0
|
72 {
|
cannam@0
|
73 return "GPL";
|
cannam@0
|
74 }
|
cannam@0
|
75
|
cannam@0
|
76 bool
|
cannam@0
|
77 Pitch::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
cannam@0
|
78 {
|
cannam@0
|
79 m_channelCount = channels;
|
cannam@0
|
80 m_stepSize = stepSize;
|
cannam@0
|
81 m_blockSize = blockSize;
|
cannam@0
|
82
|
cannam@0
|
83 m_ibuf = new_fvec(stepSize, channels);
|
cannam@0
|
84
|
piem@2
|
85 m_pitchdet = new_aubio_pitchdetection(blockSize,
|
cannam@0
|
86 stepSize,
|
cannam@0
|
87 channels,
|
cannam@0
|
88 lrintf(m_inputSampleRate),
|
cannam@0
|
89 m_pitchtype,
|
cannam@0
|
90 m_pitchmode);
|
cannam@0
|
91
|
cannam@0
|
92 return true;
|
cannam@0
|
93 }
|
cannam@0
|
94
|
cannam@0
|
95 void
|
cannam@0
|
96 Pitch::reset()
|
cannam@0
|
97 {
|
cannam@0
|
98 }
|
cannam@0
|
99
|
cannam@0
|
100 size_t
|
cannam@0
|
101 Pitch::getPreferredStepSize() const
|
cannam@0
|
102 {
|
cannam@0
|
103 return 512;
|
cannam@0
|
104 }
|
cannam@0
|
105
|
cannam@0
|
106 size_t
|
cannam@0
|
107 Pitch::getPreferredBlockSize() const
|
cannam@0
|
108 {
|
piem@2
|
109 return 2048;
|
cannam@0
|
110 }
|
cannam@0
|
111
|
cannam@0
|
112 Pitch::ParameterList
|
cannam@0
|
113 Pitch::getParameterDescriptors() const
|
cannam@0
|
114 {
|
cannam@0
|
115 ParameterList list;
|
cannam@0
|
116
|
cannam@0
|
117 ParameterDescriptor desc;
|
cannam@13
|
118 desc.identifier = "pitchtype";
|
cannam@13
|
119 desc.name = "Pitch Detection Function Type";
|
cannam@0
|
120 desc.minValue = 0;
|
cannam@0
|
121 desc.maxValue = 4;
|
piem@2
|
122 desc.defaultValue = (int)aubio_pitch_yinfft;
|
cannam@0
|
123 desc.isQuantized = true;
|
cannam@0
|
124 desc.quantizeStep = 1;
|
cannam@0
|
125 desc.valueNames.push_back("YIN Frequency Estimator");
|
cannam@0
|
126 desc.valueNames.push_back("Spectral Comb");
|
cannam@0
|
127 desc.valueNames.push_back("Schmitt");
|
cannam@0
|
128 desc.valueNames.push_back("Fast Harmonic Comb");
|
cannam@0
|
129 desc.valueNames.push_back("YIN with FFT");
|
cannam@0
|
130 list.push_back(desc);
|
cannam@0
|
131
|
cannam@0
|
132 return list;
|
cannam@0
|
133 }
|
cannam@0
|
134
|
cannam@0
|
135 float
|
cannam@0
|
136 Pitch::getParameter(std::string param) const
|
cannam@0
|
137 {
|
cannam@0
|
138 if (param == "pitchtype") {
|
cannam@0
|
139 return m_pitchtype;
|
cannam@0
|
140 } else {
|
cannam@0
|
141 return 0.0;
|
cannam@0
|
142 }
|
cannam@0
|
143 }
|
cannam@0
|
144
|
cannam@0
|
145 void
|
cannam@0
|
146 Pitch::setParameter(std::string param, float value)
|
cannam@0
|
147 {
|
cannam@0
|
148 if (param == "pitchtype") {
|
cannam@0
|
149 switch (lrintf(value)) {
|
cannam@0
|
150 case 0: m_pitchtype = aubio_pitch_yin; break;
|
cannam@0
|
151 case 1: m_pitchtype = aubio_pitch_mcomb; break;
|
cannam@0
|
152 case 2: m_pitchtype = aubio_pitch_schmitt; break;
|
cannam@0
|
153 case 3: m_pitchtype = aubio_pitch_fcomb; break;
|
cannam@0
|
154 case 4: m_pitchtype = aubio_pitch_yinfft; break;
|
cannam@0
|
155 }
|
cannam@0
|
156 }
|
cannam@0
|
157 }
|
cannam@0
|
158
|
cannam@0
|
159 Pitch::OutputList
|
cannam@0
|
160 Pitch::getOutputDescriptors() const
|
cannam@0
|
161 {
|
cannam@0
|
162 OutputList list;
|
cannam@0
|
163
|
cannam@0
|
164 OutputDescriptor d;
|
cannam@13
|
165 d.identifier = "frequency";
|
cannam@13
|
166 d.name = "Frequency";
|
cannam@0
|
167 d.unit = "Hz";
|
cannam@0
|
168 d.hasFixedBinCount = true;
|
cannam@0
|
169 d.binCount = 1;
|
cannam@0
|
170 d.hasKnownExtents = false;
|
cannam@0
|
171 d.isQuantized = false;
|
cannam@0
|
172 d.sampleType = OutputDescriptor::OneSamplePerStep;
|
cannam@0
|
173 list.push_back(d);
|
cannam@0
|
174
|
cannam@0
|
175 return list;
|
cannam@0
|
176 }
|
cannam@0
|
177
|
cannam@0
|
178 Pitch::FeatureSet
|
cannam@12
|
179 Pitch::process(const float *const *inputBuffers,
|
cannam@12
|
180 Vamp::RealTime /* timestamp */)
|
cannam@0
|
181 {
|
cannam@0
|
182 for (size_t i = 0; i < m_stepSize; ++i) {
|
cannam@0
|
183 for (size_t j = 0; j < m_channelCount; ++j) {
|
cannam@0
|
184 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
|
cannam@0
|
185 }
|
cannam@0
|
186 }
|
cannam@0
|
187
|
cannam@0
|
188 float pitch = aubio_pitchdetection(m_pitchdet, m_ibuf);
|
cannam@0
|
189
|
cannam@0
|
190 Feature feature;
|
cannam@0
|
191 feature.hasTimestamp = false;
|
cannam@0
|
192 feature.values.push_back(pitch);
|
cannam@0
|
193
|
cannam@0
|
194 FeatureSet returnFeatures;
|
cannam@0
|
195 returnFeatures[0].push_back(feature);
|
cannam@0
|
196 return returnFeatures;
|
cannam@0
|
197 }
|
cannam@0
|
198
|
cannam@0
|
199 Pitch::FeatureSet
|
cannam@0
|
200 Pitch::getRemainingFeatures()
|
cannam@0
|
201 {
|
cannam@0
|
202 return FeatureSet();
|
cannam@0
|
203 }
|
cannam@0
|
204
|