annotate src/vamp-plugin-sdk-2.5/examples/PowerSpectrum.cpp @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 619f715526df
children
rev   line source
Chris@23 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@23 2
Chris@23 3 /*
Chris@23 4 Vamp
Chris@23 5
Chris@23 6 An API for audio analysis and feature extraction plugins.
Chris@23 7
Chris@23 8 Centre for Digital Music, Queen Mary, University of London.
Chris@23 9 Copyright 2008 QMUL.
Chris@23 10
Chris@23 11 Permission is hereby granted, free of charge, to any person
Chris@23 12 obtaining a copy of this software and associated documentation
Chris@23 13 files (the "Software"), to deal in the Software without
Chris@23 14 restriction, including without limitation the rights to use, copy,
Chris@23 15 modify, merge, publish, distribute, sublicense, and/or sell copies
Chris@23 16 of the Software, and to permit persons to whom the Software is
Chris@23 17 furnished to do so, subject to the following conditions:
Chris@23 18
Chris@23 19 The above copyright notice and this permission notice shall be
Chris@23 20 included in all copies or substantial portions of the Software.
Chris@23 21
Chris@23 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@23 23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@23 24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@23 25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
Chris@23 26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@23 27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@23 28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@23 29
Chris@23 30 Except as contained in this notice, the names of the Centre for
Chris@23 31 Digital Music; Queen Mary, University of London; and Chris Cannam
Chris@23 32 shall not be used in advertising or otherwise to promote the sale,
Chris@23 33 use or other dealings in this Software without prior written
Chris@23 34 authorization.
Chris@23 35 */
Chris@23 36
Chris@23 37 #include "PowerSpectrum.h"
Chris@23 38
Chris@23 39 using std::string;
Chris@23 40 using std::cerr;
Chris@23 41 using std::endl;
Chris@23 42
Chris@23 43 #include <math.h>
Chris@23 44
Chris@23 45 PowerSpectrum::PowerSpectrum(float inputSampleRate) :
Chris@23 46 Plugin(inputSampleRate),
Chris@23 47 m_blockSize(0)
Chris@23 48 {
Chris@23 49 }
Chris@23 50
Chris@23 51 PowerSpectrum::~PowerSpectrum()
Chris@23 52 {
Chris@23 53 }
Chris@23 54
Chris@23 55 string
Chris@23 56 PowerSpectrum::getIdentifier() const
Chris@23 57 {
Chris@23 58 return "powerspectrum";
Chris@23 59 }
Chris@23 60
Chris@23 61 string
Chris@23 62 PowerSpectrum::getName() const
Chris@23 63 {
Chris@23 64 return "Simple Power Spectrum";
Chris@23 65 }
Chris@23 66
Chris@23 67 string
Chris@23 68 PowerSpectrum::getDescription() const
Chris@23 69 {
Chris@23 70 return "Return the power spectrum of a signal";
Chris@23 71 }
Chris@23 72
Chris@23 73 string
Chris@23 74 PowerSpectrum::getMaker() const
Chris@23 75 {
Chris@23 76 return "Vamp SDK Example Plugins";
Chris@23 77 }
Chris@23 78
Chris@23 79 int
Chris@23 80 PowerSpectrum::getPluginVersion() const
Chris@23 81 {
Chris@23 82 return 1;
Chris@23 83 }
Chris@23 84
Chris@23 85 string
Chris@23 86 PowerSpectrum::getCopyright() const
Chris@23 87 {
Chris@23 88 return "Freely redistributable (BSD license)";
Chris@23 89 }
Chris@23 90
Chris@23 91 bool
Chris@23 92 PowerSpectrum::initialise(size_t channels, size_t stepSize, size_t blockSize)
Chris@23 93 {
Chris@23 94 if (channels < getMinChannelCount() ||
Chris@23 95 channels > getMaxChannelCount()) return false;
Chris@23 96
Chris@23 97 m_blockSize = blockSize;
Chris@23 98
Chris@23 99 return true;
Chris@23 100 }
Chris@23 101
Chris@23 102 void
Chris@23 103 PowerSpectrum::reset()
Chris@23 104 {
Chris@23 105 }
Chris@23 106
Chris@23 107 PowerSpectrum::OutputList
Chris@23 108 PowerSpectrum::getOutputDescriptors() const
Chris@23 109 {
Chris@23 110 OutputList list;
Chris@23 111
Chris@23 112 OutputDescriptor d;
Chris@23 113 d.identifier = "powerspectrum";
Chris@23 114 d.name = "Power Spectrum";
Chris@23 115 d.description = "Power values of the frequency spectrum bins calculated from the input signal";
Chris@23 116 d.unit = "";
Chris@23 117 d.hasFixedBinCount = true;
Chris@23 118 if (m_blockSize == 0) {
Chris@23 119 // Just so as not to return "1". This is the bin count that
Chris@23 120 // would result from a block size of 1024, which is a likely
Chris@23 121 // default -- but the host should always set the block size
Chris@23 122 // before querying the bin count for certain.
Chris@23 123 d.binCount = 513;
Chris@23 124 } else {
Chris@23 125 d.binCount = m_blockSize / 2 + 1;
Chris@23 126 }
Chris@23 127 d.hasKnownExtents = false;
Chris@23 128 d.isQuantized = false;
Chris@23 129 d.sampleType = OutputDescriptor::OneSamplePerStep;
Chris@23 130 list.push_back(d);
Chris@23 131
Chris@23 132 return list;
Chris@23 133 }
Chris@23 134
Chris@23 135 PowerSpectrum::FeatureSet
Chris@23 136 PowerSpectrum::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
Chris@23 137 {
Chris@23 138 FeatureSet fs;
Chris@23 139
Chris@23 140 if (m_blockSize == 0) {
Chris@23 141 cerr << "ERROR: PowerSpectrum::process: Not initialised" << endl;
Chris@23 142 return fs;
Chris@23 143 }
Chris@23 144
Chris@23 145 size_t n = m_blockSize / 2 + 1;
Chris@23 146 const float *fbuf = inputBuffers[0];
Chris@23 147
Chris@23 148 Feature feature;
Chris@23 149 feature.hasTimestamp = false;
Chris@23 150 feature.values.reserve(n); // optional
Chris@23 151
Chris@23 152 for (size_t i = 0; i < n; ++i) {
Chris@23 153
Chris@23 154 double real = fbuf[i * 2];
Chris@23 155 double imag = fbuf[i * 2 + 1];
Chris@23 156
Chris@23 157 feature.values.push_back(real * real + imag * imag);
Chris@23 158 }
Chris@23 159
Chris@23 160 fs[0].push_back(feature);
Chris@23 161
Chris@23 162 return fs;
Chris@23 163 }
Chris@23 164
Chris@23 165 PowerSpectrum::FeatureSet
Chris@23 166 PowerSpectrum::getRemainingFeatures()
Chris@23 167 {
Chris@23 168 return FeatureSet();
Chris@23 169 }
Chris@23 170