48 #define isinf(x) (!finite(x))
52 #define isnan(x) false
53 #define isinf(x) false
57 Plugin(inputSampleRate),
70 return "spectralcentroid";
76 return "Spectral Centroid";
82 return "Calculate the centroid frequency of the spectrum of the input signal";
88 return "Vamp SDK Example Plugins";
100 return "Freely redistributable (BSD license)";
127 d.
name =
"Log Frequency Centroid";
128 d.
description =
"Centroid of the log weighted frequency spectrum";
138 d.
name =
"Linear Frequency Centroid";
139 d.
description =
"Centroid of the linear frequency spectrum";
149 cerr <<
"ERROR: SpectralCentroid::process: "
150 <<
"SpectralCentroid has not been initialised"
155 double numLin = 0.0, numLog = 0.0, denom = 0.0;
159 double real = inputBuffers[0][i*2];
160 double imag = inputBuffers[0][i*2 + 1];
161 double scalemag = sqrt(real * real + imag * imag) / (
m_blockSize/2);
162 numLin += freq * scalemag;
163 numLog += log10f(freq) * scalemag;
170 float centroidLin = float(numLin / denom);
171 float centroidLog = powf(10,
float(numLog / denom));
176 if (!isnan(centroidLog) && !isinf(centroidLog)) {
177 feature.
values.push_back(centroidLog);
179 returnFeatures[0].push_back(feature);
182 if (!isnan(centroidLin) && !isinf(centroidLin)) {
183 feature.
values.push_back(centroidLin);
185 returnFeatures[1].push_back(feature);
188 return returnFeatures;