void PSD::internalUpdate() { writeLockInputsAndOutputs(); VectorPtr iv = _inputVectors[INVECTOR]; const int v_len = iv->length(); _last_n_new += iv->numNew(); assert(_last_n_new >= 0); int n_subsets = (v_len)/_PSDLength; // determine if the PSD needs to be updated. // if not using averaging, then we need at least _PSDLength/16 new data points. // if averaging, then we want enough new data for a complete subset. // ... unless we are counting from end at fixed length (scrolling data). bool scrolling_data = (_last_n == iv->length()); if ( (!_changed) && ((_last_n_new < _PSDLength/16) || (_Average && scrolling_data && (_last_n_new < _PSDLength/16)) || (_Average && !scrolling_data && (n_subsets - _last_n_subsets < 1))) && iv->length() != iv->numNew()) { unlockInputsAndOutputs(); return; } _changed = false; _adjustLengths(); double *psd = _sVector->value(); double *f = _fVector->value(); int i_samp; for (i_samp = 0; i_samp < _PSDLength; ++i_samp) { f[i_samp] = i_samp * 0.5 * _Frequency / (_PSDLength - 1); } //f[0] = -1E-280; // really 0 (this shouldn't be needed...) _psdCalculator.calculatePowerSpectrum(iv->value(), v_len, psd, _PSDLength, _RemoveMean, _interpolateHoles, _Average, _averageLength, _Apodize, _apodizeFxn, _gaussianSigma, _Output, _Frequency); _last_n_subsets = n_subsets; _last_n_new = 0; _last_n = iv->length(); updateVectorLabels(); // should be updated by the update manager //_sVector->update(); //_fVector->update(); unlockInputsAndOutputs(); return; }
KstObject::UpdateType KstPSD::update(int update_counter) { Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED); bool force = dirty(); setDirty(false); if (KstObject::checkUpdateCounter(update_counter) && !force) { return lastUpdateResult(); } if (recursed()) { return setLastUpdateResult(NO_CHANGE); } writeLockInputsAndOutputs(); KstVectorPtr iv = _inputVectors[INVECTOR]; if (update_counter <= 0) { assert(update_counter == 0); force = true; } bool xUpdated = KstObject::UPDATE == iv->update(update_counter); const int v_len = iv->length(); // Don't touch _last_n_new if !xUpdated since it will certainly be wrong. if (!xUpdated && !force) { unlockInputsAndOutputs(); return setLastUpdateResult(NO_CHANGE); } _last_n_new += iv->numNew(); assert(_last_n_new >= 0); int n_subsets = v_len/_PSDLen; // determine if the PSD needs to be updated. if not using averaging, then we need at least _PSDLen/16 new data points. if averaging, then we want enough new data for a complete subset. if ( ((_last_n_new < _PSDLen/16) || (_Average && (n_subsets - _last_n_subsets < 1))) && iv->length() != iv->numNew() && !force) { unlockInputsAndOutputs(); return setLastUpdateResult(NO_CHANGE); } _adjustLengths(); double *psd = (*_sVector)->value(); double *f = (*_fVector)->value(); int i_samp; for (i_samp = 0; i_samp < _PSDLen; ++i_samp) { f[i_samp] = i_samp * 0.5 * _Freq / (_PSDLen - 1); } _psdCalculator.calculatePowerSpectrum(iv->value(), v_len, psd, _PSDLen, _RemoveMean, _interpolateHoles, _Average, _averageLen, _Apodize, _apodizeFxn, _gaussianSigma, _Output, _Freq); _last_n_subsets = n_subsets; _last_n_new = 0; updateVectorLabels(); (*_sVector)->setDirty(); (*_sVector)->update(update_counter); (*_fVector)->setDirty(); (*_fVector)->update(update_counter); unlockInputsAndOutputs(); return setLastUpdateResult(UPDATE); }