Move gaborProcessEntry preconditions to gaborApplySlice

This commit is contained in:
DataHoarder 2022-07-15 14:42:30 +02:00
parent 13f6e179e3
commit c20789e8ce
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk

View file

@ -143,11 +143,20 @@ private:
}, min_band, INT_MAX, st0, st1, coefs);
*/
std::vector<float> magnitudes;
//Adjust start to match gaborProcessEntry requirements
if((st0 / frequencyBinTimeStepSize) <= 0){
st0 = frequencyBinTimeStepSize;
}
//Skip if nothing to process, the first results have a negative audio sample index
if(st0 > st1){
return;
}
gaborator::apply_to_slice(false, [&](int band, int64_t sampleIndex, int time_step, unsigned len, const std::complex<float> *p0) {
//process magnitudes beforehand for easier auto-vectorization
magnitudes.resize(len);
magnitudeCache.resize(len);
#ifdef __AVX2__
@ -166,51 +175,45 @@ private:
// reorder values prior to storing
__m256d ordered = _mm256_permute4x64_pd (_mm256_castps_pd(abs), _MM_SHUFFLE(3, 1, 2, 0));
_mm256_storeu_ps(magnitudes.data() + i, _mm256_castpd_ps(ordered));
_mm256_storeu_ps(magnitudeCache.data() + i, _mm256_castpd_ps(ordered));
}
for (int64_t j = i; j < len; j++) {
#else
for (unsigned int j = 0; j < len; j++) {
#endif
magnitudes[j] = std::abs(p0[j]);
magnitudeCache[j] = std::abs(p0[j]);
}
for(auto magnitude : magnitudes){
for(auto magnitude : magnitudeCache){
gaborProcessEntry(band, sampleIndex, magnitude);
sampleIndex += time_step;
}
}, min_band, INT_MAX, st0, st1, coefs);
}, min_band, numberOfBandsCache + firstBandCache, st0, st1, coefs);
}
inline void gaborProcessEntry(int band, int64_t sampleIndex, float coefficient) {
int64_t coefficientIndex = sampleIndex / frequencyBinTimeStepSize;
int bandIndex = band - firstBandCache;
int64_t circularIndex = coefficientIndex % coefficientSize;
auto& currentCoefficient = coefficients[circularIndex];
// The first results have a negative audio sample index
// ignore these
if (coefficientIndex > 0 && bandIndex < numberOfBandsCache) {
// If a new index is reached, save the old (fixed) coefficients in the history
// Fill the array with zeros to get the max
if (coefficientIndex > mostRecentCoefficentIndex && coefficientIndex > coefficientSize) {
// keep the new maximum
mostRecentCoefficentIndex = coefficientIndex;
// "copy" the oldest data to the history
// the slice can be reused thanks to the oldest being filled with zeros just after
resultCache.insert(resultCache.end(), currentCoefficient.begin(), currentCoefficient.end());
// fill the oldest with zeros
std::fill(currentCoefficient.begin(), currentCoefficient.end(), 0);
}
// due to reduction in precision (from audio sample accuracy to steps) multiple
// magnitudes could be placed in the same stepIndex, bandIndex pair.
// We take the maximum magnitudes value.
currentCoefficient[bandIndex] = std::max(currentCoefficient[bandIndex], coefficient);
int64_t circularIndex = coefficientIndex % coefficientSize;
auto& currentCoefficient = coefficients[circularIndex];
// If a new index is reached, save the old (fixed) coefficients in the history
// Fill the array with zeros to get the max
if (coefficientIndex > mostRecentCoefficentIndex && coefficientIndex > coefficientSize) {
// keep the new maximum
mostRecentCoefficentIndex = coefficientIndex;
// "copy" the oldest data to the history
// the slice can be reused thanks to the oldest being filled with zeros just after
resultCache.insert(resultCache.end(), currentCoefficient.begin(), currentCoefficient.end());
// fill the oldest with zeros
std::fill(currentCoefficient.begin(), currentCoefficient.end(), 0);
}
// due to reduction in precision (from audio sample accuracy to steps) multiple
// magnitudes could be placed in the same stepIndex, bandIndex pair.
// We take the maximum magnitudes value.
currentCoefficient[bandIndex] = std::max(currentCoefficient[bandIndex], coefficient);
}
}
@ -228,6 +231,7 @@ private:
int64_t mostRecentCoefficentIndex = 0;
const int blockSize;
std::vector<float> magnitudeCache;
const int64_t frequencyBinTimeStepSize;
int64_t t_in;
int min_band;