From 9a7a977fa07db255db92ed58192d0985464cf1eb Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Mon, 6 Jun 2022 14:49:01 +0100 Subject: [PATCH] Tidy --- src/finer/R3StretcherImpl.cpp | 34 +++++----------------------------- src/finer/R3StretcherImpl.h | 13 ++++++++----- 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/src/finer/R3StretcherImpl.cpp b/src/finer/R3StretcherImpl.cpp index 3250e4c..51b760f 100644 --- a/src/finer/R3StretcherImpl.cpp +++ b/src/finer/R3StretcherImpl.cpp @@ -674,7 +674,7 @@ R3StretcherImpl::analyseFormant() m_scaleData.at(classify)->fft.forward (f.cepstra.data(), f.envelope.data(), - f.shifted.data()); // shifted is just a spare for this one + f.spare.data()); // shifted is just a spare for this one v_exp(f.envelope.data(), binCount); v_square(f.envelope.data(), binCount); @@ -682,24 +682,6 @@ R3StretcherImpl::analyseFormant() for (int i = 0; i < binCount; ++i) { if (f.envelope[i] > 1.0e10) f.envelope[i] = 1.0e10; } - - //!!! - double scale = m_pitchScale; - for (int target = 0; target < binCount; ++target) { - int source = int(round(target * scale)); - if (source >= binCount) { - f.shifted[target] = 0.0; - } else { - f.shifted[target] = f.envelope[source]; - } - } - -// std::cout << "X:"; -// for (int i = 0; i < binCount; ++i) { -// if (i > 0) std::cout << ","; -// std::cout << f.shifted[i]; -// } -// std::cout << std::endl; } void @@ -718,14 +700,6 @@ R3StretcherImpl::synthesiseChannel(int c, int outhop) v_copy(scale->prevMag.data(), scale->mag.data(), bufSize); - -// if (m_formant->enabled) { - // formant shift only the middle register -// if (it.first == m_guideConfiguration.classificationFftSize) { -// v_divide(scale->mag.data(), m_formant->envelope.data(), bufSize); -// v_multiply(scale->mag.data(), m_formant->shifted.data(), bufSize); -// } -// } } for (const auto &band : cd->guidance.fftBands) { @@ -764,13 +738,15 @@ R3StretcherImpl::synthesiseChannel(int c, int outhop) if (m_formant->enabled) { double targetFactor = double(m_formant->fftSize) / double(fftSize); double sourceFactor = targetFactor * m_pitchScale; + double maxRatio = 60.0; + double minRatio = 1.0 / maxRatio; for (int i = lowBin; i < highBin && i < formantHigh; ++i) { double source = m_formant->envelopeAt(i * sourceFactor); double target = m_formant->envelopeAt(i * targetFactor); if (target > 0.0) { double ratio = source / target; -// if (ratio < 0.2) ratio = 0.2; -// if (ratio > 5.0) ratio = 5.0; + if (ratio < minRatio) ratio = minRatio; + if (ratio > maxRatio) ratio = maxRatio; scale->mag[i] *= ratio; } } diff --git a/src/finer/R3StretcherImpl.h b/src/finer/R3StretcherImpl.h index 1132a0a..a7eb39b 100644 --- a/src/finer/R3StretcherImpl.h +++ b/src/finer/R3StretcherImpl.h @@ -226,19 +226,22 @@ protected: int fftSize; FixedVector cepstra; FixedVector envelope; - FixedVector shifted; + FixedVector spare; FormantData(int _fftSize) : enabled(false), fftSize(_fftSize), cepstra(_fftSize, 0.0), - envelope(_fftSize, 0.0), - shifted(_fftSize, 0.0) { } + envelope(_fftSize/2 + 1, 0.0), + spare(_fftSize/2 + 1, 0.0) { } double envelopeAt(double bin) const { int b0 = int(floor(bin)), b1 = int(ceil(bin)); - if (b1 == b0) return envelope.at(b0); - else { + if (b0 < 0 || b0 > fftSize/2) { + return 0.0; + } else if (b1 == b0 || b1 > fftSize/2) { + return envelope.at(b0); + } else { double diff = bin - double(b0); return envelope.at(b0) * (1.0 - diff) + envelope.at(b1) * diff; }