Chris@1: Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1: VampPluginSDK
Chris@1: 2.1
Chris@1:
Chris@1:
Chris@1: |
Chris@1:
Chris@1:
Chris@1:
Chris@1:
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@1: 00002 Chris@1: 00003 /* Chris@1: 00004 Vamp Chris@1: 00005 Chris@1: 00006 An API for audio analysis and feature extraction plugins. Chris@1: 00007 Chris@1: 00008 Centre for Digital Music, Queen Mary, University of London. Chris@1: 00009 Copyright 2008 QMUL. Chris@1: 00010 Chris@1: 00011 Permission is hereby granted, free of charge, to any person Chris@1: 00012 obtaining a copy of this software and associated documentation Chris@1: 00013 files (the "Software"), to deal in the Software without Chris@1: 00014 restriction, including without limitation the rights to use, copy, Chris@1: 00015 modify, merge, publish, distribute, sublicense, and/or sell copies Chris@1: 00016 of the Software, and to permit persons to whom the Software is Chris@1: 00017 furnished to do so, subject to the following conditions: Chris@1: 00018 Chris@1: 00019 The above copyright notice and this permission notice shall be Chris@1: 00020 included in all copies or substantial portions of the Software. Chris@1: 00021 Chris@1: 00022 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, Chris@1: 00023 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF Chris@1: 00024 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND Chris@1: 00025 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR Chris@1: 00026 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF Chris@1: 00027 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION Chris@1: 00028 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Chris@1: 00029 Chris@1: 00030 Except as contained in this notice, the names of the Centre for Chris@1: 00031 Digital Music; Queen Mary, University of London; and Chris Cannam Chris@1: 00032 shall not be used in advertising or otherwise to promote the sale, Chris@1: 00033 use or other dealings in this Software without prior written Chris@1: 00034 authorization. Chris@1: 00035 */ Chris@1: 00036 Chris@1: 00037 #include "PowerSpectrum.h" Chris@1: 00038 Chris@1: 00039 using std::string; Chris@1: 00040 using std::cerr; Chris@1: 00041 using std::endl; Chris@1: 00042 Chris@1: 00043 #include <math.h> Chris@1: 00044 Chris@1: 00045 PowerSpectrum::PowerSpectrum(float inputSampleRate) : Chris@1: 00046 Plugin(inputSampleRate), Chris@1: 00047 m_blockSize(0) Chris@1: 00048 { Chris@1: 00049 } Chris@1: 00050 Chris@1: 00051 PowerSpectrum::~PowerSpectrum() Chris@1: 00052 { Chris@1: 00053 } Chris@1: 00054 Chris@1: 00055 string Chris@1: 00056 PowerSpectrum::getIdentifier() const Chris@1: 00057 { Chris@1: 00058 return "powerspectrum"; Chris@1: 00059 } Chris@1: 00060 Chris@1: 00061 string Chris@1: 00062 PowerSpectrum::getName() const Chris@1: 00063 { Chris@1: 00064 return "Simple Power Spectrum"; Chris@1: 00065 } Chris@1: 00066 Chris@1: 00067 string Chris@1: 00068 PowerSpectrum::getDescription() const Chris@1: 00069 { Chris@1: 00070 return "Return the power spectrum of a signal"; Chris@1: 00071 } Chris@1: 00072 Chris@1: 00073 string Chris@1: 00074 PowerSpectrum::getMaker() const Chris@1: 00075 { Chris@1: 00076 return "Vamp SDK Example Plugins"; Chris@1: 00077 } Chris@1: 00078 Chris@1: 00079 int Chris@1: 00080 PowerSpectrum::getPluginVersion() const Chris@1: 00081 { Chris@1: 00082 return 1; Chris@1: 00083 } Chris@1: 00084 Chris@1: 00085 string Chris@1: 00086 PowerSpectrum::getCopyright() const Chris@1: 00087 { Chris@1: 00088 return "Freely redistributable (BSD license)"; Chris@1: 00089 } Chris@1: 00090 Chris@1: 00091 bool Chris@1: 00092 PowerSpectrum::initialise(size_t channels, size_t stepSize, size_t blockSize) Chris@1: 00093 { Chris@1: 00094 if (channels < getMinChannelCount() || Chris@1: 00095 channels > getMaxChannelCount()) return false; Chris@1: 00096 Chris@1: 00097 m_blockSize = blockSize; Chris@1: 00098 Chris@1: 00099 return true; Chris@1: 00100 } Chris@1: 00101 Chris@1: 00102 void Chris@1: 00103 PowerSpectrum::reset() Chris@1: 00104 { Chris@1: 00105 } Chris@1: 00106 Chris@1: 00107 PowerSpectrum::OutputList Chris@1: 00108 PowerSpectrum::getOutputDescriptors() const Chris@1: 00109 { Chris@1: 00110 OutputList list; Chris@1: 00111 Chris@1: 00112 OutputDescriptor d; Chris@1: 00113 d.identifier = "powerspectrum"; Chris@1: 00114 d.name = "Power Spectrum"; Chris@1: 00115 d.description = "Power values of the frequency spectrum bins calculated from the input signal"; Chris@1: 00116 d.unit = ""; Chris@1: 00117 d.hasFixedBinCount = true; Chris@1: 00118 if (m_blockSize == 0) { Chris@1: 00119 // Just so as not to return "1". This is the bin count that Chris@1: 00120 // would result from a block size of 1024, which is a likely Chris@1: 00121 // default -- but the host should always set the block size Chris@1: 00122 // before querying the bin count for certain. Chris@1: 00123 d.binCount = 513; Chris@1: 00124 } else { Chris@1: 00125 d.binCount = m_blockSize / 2 + 1; Chris@1: 00126 } Chris@1: 00127 d.hasKnownExtents = false; Chris@1: 00128 d.isQuantized = false; Chris@1: 00129 d.sampleType = OutputDescriptor::OneSamplePerStep; Chris@1: 00130 list.push_back(d); Chris@1: 00131 Chris@1: 00132 return list; Chris@1: 00133 } Chris@1: 00134 Chris@1: 00135 PowerSpectrum::FeatureSet Chris@1: 00136 PowerSpectrum::process(const float *const *inputBuffers, Vamp::RealTime timestamp) Chris@1: 00137 { Chris@1: 00138 FeatureSet fs; Chris@1: 00139 Chris@1: 00140 if (m_blockSize == 0) { Chris@1: 00141 cerr << "ERROR: PowerSpectrum::process: Not initialised" << endl; Chris@1: 00142 return fs; Chris@1: 00143 } Chris@1: 00144 Chris@1: 00145 size_t n = m_blockSize / 2 + 1; Chris@1: 00146 const float *fbuf = inputBuffers[0]; Chris@1: 00147 Chris@1: 00148 Feature feature; Chris@1: 00149 feature.hasTimestamp = false; Chris@1: 00150 feature.values.reserve(n); // optional Chris@1: 00151 Chris@1: 00152 for (size_t i = 0; i < n; ++i) { Chris@1: 00153 Chris@1: 00154 double real = fbuf[i * 2]; Chris@1: 00155 double imag = fbuf[i * 2 + 1]; Chris@1: 00156 Chris@1: 00157 feature.values.push_back(real * real + imag * imag); Chris@1: 00158 } Chris@1: 00159 Chris@1: 00160 fs[0].push_back(feature); Chris@1: 00161 Chris@1: 00162 return fs; Chris@1: 00163 } Chris@1: 00164 Chris@1: 00165 PowerSpectrum::FeatureSet Chris@1: 00166 PowerSpectrum::getRemainingFeatures() Chris@1: 00167 { Chris@1: 00168 return FeatureSet(); Chris@1: 00169 } Chris@1: 00170 Chris@1: