annotate plugins/Pitch.cpp @ 12:62414aaaaa7e

* Update to new Vamp process() * Add hack for getting raw tempo out of hacked Aubio
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 12 Dec 2006 10:42:21 +0000
parents 76c1a7bd0416
children 1169d00391d8
rev   line source
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@0 41 Pitch::getName() const
cannam@0 42 {
cannam@0 43 return "aubiopitch";
cannam@0 44 }
cannam@0 45
cannam@0 46 string
cannam@0 47 Pitch::getDescription() const
cannam@0 48 {
cannam@0 49 return "Aubio Pitch Detector";
cannam@0 50 }
cannam@0 51
cannam@0 52 string
cannam@0 53 Pitch::getMaker() const
cannam@0 54 {
cannam@0 55 return "Paul Brossier (plugin by Chris Cannam)";
cannam@0 56 }
cannam@0 57
cannam@0 58 int
cannam@0 59 Pitch::getPluginVersion() const
cannam@0 60 {
cannam@0 61 return 1;
cannam@0 62 }
cannam@0 63
cannam@0 64 string
cannam@0 65 Pitch::getCopyright() const
cannam@0 66 {
cannam@0 67 return "GPL";
cannam@0 68 }
cannam@0 69
cannam@0 70 bool
cannam@0 71 Pitch::initialise(size_t channels, size_t stepSize, size_t blockSize)
cannam@0 72 {
cannam@0 73 m_channelCount = channels;
cannam@0 74 m_stepSize = stepSize;
cannam@0 75 m_blockSize = blockSize;
cannam@0 76
cannam@0 77 m_ibuf = new_fvec(stepSize, channels);
cannam@0 78
piem@2 79 m_pitchdet = new_aubio_pitchdetection(blockSize,
cannam@0 80 stepSize,
cannam@0 81 channels,
cannam@0 82 lrintf(m_inputSampleRate),
cannam@0 83 m_pitchtype,
cannam@0 84 m_pitchmode);
cannam@0 85
cannam@0 86 return true;
cannam@0 87 }
cannam@0 88
cannam@0 89 void
cannam@0 90 Pitch::reset()
cannam@0 91 {
cannam@0 92 }
cannam@0 93
cannam@0 94 size_t
cannam@0 95 Pitch::getPreferredStepSize() const
cannam@0 96 {
cannam@0 97 return 512;
cannam@0 98 }
cannam@0 99
cannam@0 100 size_t
cannam@0 101 Pitch::getPreferredBlockSize() const
cannam@0 102 {
piem@2 103 return 2048;
cannam@0 104 }
cannam@0 105
cannam@0 106 Pitch::ParameterList
cannam@0 107 Pitch::getParameterDescriptors() const
cannam@0 108 {
cannam@0 109 ParameterList list;
cannam@0 110
cannam@0 111 ParameterDescriptor desc;
cannam@0 112 desc.name = "pitchtype";
cannam@0 113 desc.description = "Pitch Detection Function Type";
cannam@0 114 desc.minValue = 0;
cannam@0 115 desc.maxValue = 4;
piem@2 116 desc.defaultValue = (int)aubio_pitch_yinfft;
cannam@0 117 desc.isQuantized = true;
cannam@0 118 desc.quantizeStep = 1;
cannam@0 119 desc.valueNames.push_back("YIN Frequency Estimator");
cannam@0 120 desc.valueNames.push_back("Spectral Comb");
cannam@0 121 desc.valueNames.push_back("Schmitt");
cannam@0 122 desc.valueNames.push_back("Fast Harmonic Comb");
cannam@0 123 desc.valueNames.push_back("YIN with FFT");
cannam@0 124 list.push_back(desc);
cannam@0 125
cannam@0 126 return list;
cannam@0 127 }
cannam@0 128
cannam@0 129 float
cannam@0 130 Pitch::getParameter(std::string param) const
cannam@0 131 {
cannam@0 132 if (param == "pitchtype") {
cannam@0 133 return m_pitchtype;
cannam@0 134 } else {
cannam@0 135 return 0.0;
cannam@0 136 }
cannam@0 137 }
cannam@0 138
cannam@0 139 void
cannam@0 140 Pitch::setParameter(std::string param, float value)
cannam@0 141 {
cannam@0 142 if (param == "pitchtype") {
cannam@0 143 switch (lrintf(value)) {
cannam@0 144 case 0: m_pitchtype = aubio_pitch_yin; break;
cannam@0 145 case 1: m_pitchtype = aubio_pitch_mcomb; break;
cannam@0 146 case 2: m_pitchtype = aubio_pitch_schmitt; break;
cannam@0 147 case 3: m_pitchtype = aubio_pitch_fcomb; break;
cannam@0 148 case 4: m_pitchtype = aubio_pitch_yinfft; break;
cannam@0 149 }
cannam@0 150 }
cannam@0 151 }
cannam@0 152
cannam@0 153 Pitch::OutputList
cannam@0 154 Pitch::getOutputDescriptors() const
cannam@0 155 {
cannam@0 156 OutputList list;
cannam@0 157
cannam@0 158 OutputDescriptor d;
cannam@0 159 d.name = "frequency";
cannam@0 160 d.unit = "Hz";
cannam@0 161 d.description = "Frequency";
cannam@0 162 d.hasFixedBinCount = true;
cannam@0 163 d.binCount = 1;
cannam@0 164 d.hasKnownExtents = false;
cannam@0 165 d.isQuantized = false;
cannam@0 166 d.sampleType = OutputDescriptor::OneSamplePerStep;
cannam@0 167 list.push_back(d);
cannam@0 168
cannam@0 169 return list;
cannam@0 170 }
cannam@0 171
cannam@0 172 Pitch::FeatureSet
cannam@12 173 Pitch::process(const float *const *inputBuffers,
cannam@12 174 Vamp::RealTime /* timestamp */)
cannam@0 175 {
cannam@0 176 for (size_t i = 0; i < m_stepSize; ++i) {
cannam@0 177 for (size_t j = 0; j < m_channelCount; ++j) {
cannam@0 178 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
cannam@0 179 }
cannam@0 180 }
cannam@0 181
cannam@0 182 float pitch = aubio_pitchdetection(m_pitchdet, m_ibuf);
cannam@0 183
cannam@0 184 Feature feature;
cannam@0 185 feature.hasTimestamp = false;
cannam@0 186 feature.values.push_back(pitch);
cannam@0 187
cannam@0 188 FeatureSet returnFeatures;
cannam@0 189 returnFeatures[0].push_back(feature);
cannam@0 190 return returnFeatures;
cannam@0 191 }
cannam@0 192
cannam@0 193 Pitch::FeatureSet
cannam@0 194 Pitch::getRemainingFeatures()
cannam@0 195 {
cannam@0 196 return FeatureSet();
cannam@0 197 }
cannam@0 198