Logo Search packages:      
Sourcecode: vamp-plugin-sdk version File versions  Download package

SpectralCentroid::FeatureSet SpectralCentroid::process ( const float *const *  inputBuffers,
Vamp::RealTime  timestamp 
) [virtual]

Process a single block of input data.

If the plugin's inputDomain is TimeDomain, inputBuffers will point to one array of floats per input channel, and each of these arrays will contain blockSize consecutive audio samples (the host will zero-pad as necessary). The timestamp will be the real time in seconds of the start of the supplied block of samples.

If the plugin's inputDomain is FrequencyDomain, inputBuffers will point to one array of floats per input channel, and each of these arrays will contain blockSize/2+1 consecutive pairs of real and imaginary component floats corresponding to bins 0..(blockSize/2) of the FFT output. That is, bin 0 (the first pair of floats) contains the DC output, up to bin blockSize/2 which contains the Nyquist-frequency output. There will therefore be blockSize+2 floats per channel in total. The timestamp will be the real time in seconds of the centre of the FFT input window (i.e. the very first block passed to process might contain the FFT of half a block of zero samples and the first half-block of the actual data, with a timestamp of zero).

Return any features that have become available after this process call. (These do not necessarily have to fall within the process block, except for OneSamplePerStep outputs.)

Implements Vamp::Plugin.

Definition at line 137 of file SpectralCentroid.cpp.

{
    if (m_stepSize == 0) {
      cerr << "ERROR: SpectralCentroid::process: "
           << "SpectralCentroid has not been initialised"
           << endl;
      return FeatureSet();
    }

    double numLin = 0.0, numLog = 0.0, denom = 0.0;

    for (size_t i = 1; i <= m_blockSize/2; ++i) {
      double freq = (double(i) * m_inputSampleRate) / m_blockSize;
      double real = inputBuffers[0][i*2];
      double imag = inputBuffers[0][i*2 + 1];
      double power = sqrt(real * real + imag * imag) / (m_blockSize/2);
      numLin += freq * power;
        numLog += log10f(freq) * power;
      denom += power;
    }

    FeatureSet returnFeatures;

//    std::cerr << "power " << denom << ", block size " << m_blockSize << std::endl;

    if (denom != 0.0) {
      float centroidLin = float(numLin / denom);
      float centroidLog = powf(10, float(numLog / denom));

      Feature feature;
      feature.hasTimestamp = false;
        if (!std::isnan(centroidLog) && !std::isinf(centroidLog)) {
            feature.values.push_back(centroidLog);
        }
      returnFeatures[0].push_back(feature);

        feature.values.clear();
        if (!std::isnan(centroidLin) && !std::isinf(centroidLin)) {
            feature.values.push_back(centroidLin);
        }
      returnFeatures[1].push_back(feature);
    }

    return returnFeatures;
}


Generated by  Doxygen 1.6.0   Back to index