void Leq::compute() { const std::vector<Real>& signal = _signal.get(); Real& leq = _leq.get(); if (signal.empty()) { throw EssentiaException("Leq: input signal is empty"); } leq = pow2db(instantPower(signal)); }
void ReplayGain::compute() { const vector<Real>& signal = _signal.get(); Real& gain = _gain.get(); // we do not have enough input data to construct a single frame... // return the same value as if it was silence if ((int)signal.size() < _rmsWindowSize) { throw EssentiaException("ReplayGain: The input size must not be less than 0.05ms"); } // 1. Equal loudness filter vector<Real> eqloudSignal; _eqloudFilter->input("signal").set(signal); _eqloudFilter->output("signal").set(eqloudSignal); _eqloudFilter->compute(); // 2. RMS Energy calculation int nFrames = (int)eqloudSignal.size() / _rmsWindowSize; vector<Real> rms(nFrames, 0.0); for (int i = 0; i < nFrames; i++) { Real vrms = 0.0; for (int j = i*_rmsWindowSize; j < (i+1)*_rmsWindowSize; j++) { vrms += eqloudSignal[j] * eqloudSignal[j]; } vrms /= _rmsWindowSize; // Convert value to db // Note that vrms is energy and not an amplitude as sqrt is not applied rms[i] = pow2db(vrms); } // 3. Statistical processing, as described in the algorithm, the 5% point is taken to // represent the overall loudness of the input audio signal sort(rms.begin(), rms.end()); Real loudness = rms[(int)(0.95*rms.size())]; // 4. Calibration with reference level // file is ref_pink.wav, downloaded on reference site (www.replaygain.org) Real ref_loudness = -31.492595672607422; // 5. Replay gain gain = ref_loudness - loudness; }
void Leq::finalProduce() { if (_size == 0) throw EssentiaException("Leq: signal is empty"); _leq.push(pow2db(_energy/_size)); }