From ce64122ffeb9e26986a19dfd15867bcad6487569 Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Fri, 27 May 2022 15:16:10 +0100 Subject: [PATCH] Wire up formant option; some tidying --- src/RubberBandStretcher.cpp | 4 ++++ src/finer/R3StretcherImpl.cpp | 25 ++++++++++++++----------- src/finer/R3StretcherImpl.h | 2 ++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/RubberBandStretcher.cpp b/src/RubberBandStretcher.cpp index c021730..5e75498 100644 --- a/src/RubberBandStretcher.cpp +++ b/src/RubberBandStretcher.cpp @@ -96,6 +96,8 @@ RubberBandStretcher::getLatency() const else return m_r3d->getLatency(); } +//!!! review all these + void RubberBandStretcher::setTransientsOption(Options options) { @@ -118,12 +120,14 @@ void RubberBandStretcher::setFormantOption(Options options) { if (m_d) m_d->setFormantOption(options); + else if (m_r3d) m_r3d->setFormantOption(options); } void RubberBandStretcher::setPitchOption(Options options) { if (m_d) m_d->setPitchOption(options); + else if (m_r3d) m_r3d->setPitchOption(options); } void diff --git a/src/finer/R3StretcherImpl.cpp b/src/finer/R3StretcherImpl.cpp index c7a29d1..0a19320 100644 --- a/src/finer/R3StretcherImpl.cpp +++ b/src/finer/R3StretcherImpl.cpp @@ -192,7 +192,7 @@ R3StretcherImpl::calculateHop() m_inhop = int(round(inhop)); - std::cout << "R3StretcherImpl::calculateHop: inhop = " << m_inhop << ", proposed outhop = " << proposedOuthop << ", mean outhop = " << m_inhop * ratio << std::endl; +// std::cout << "R3StretcherImpl::calculateHop: inhop = " << m_inhop << ", proposed outhop = " << proposedOuthop << ", mean outhop = " << m_inhop * ratio << std::endl; } double @@ -346,7 +346,7 @@ R3StretcherImpl::consume() // advanced the input and output since the previous frame, not the // distances we are about to advance them, so they use the m_prev // values. - +/* if (inhop != m_prevInhop) { std::cout << "Note: inhop has changed from " << m_prevInhop << " to " << inhop << std::endl; @@ -355,7 +355,7 @@ R3StretcherImpl::consume() std::cout << "Note: outhop has changed from " << m_prevOuthop << " to " << outhop << std::endl; } - +*/ while (m_channelData.at(0)->outbuf->getWriteSpace() >= outhop) { // NB our ChannelData, ScaleData, and ChannelScaleData maps @@ -382,7 +382,10 @@ R3StretcherImpl::consume() } if (m_parameters.options & RubberBandStretcher::OptionFormantPreserved) { + m_formant->enabled = true; analyseFormant(); + } else { + m_formant->enabled = false; } // Phase update. This is synchronised across all channels @@ -687,12 +690,12 @@ R3StretcherImpl::analyseFormant() } } - std::cout << "X:"; - for (int i = 0; i < binCount; ++i) { - if (i > 0) std::cout << ","; - std::cout << f.shifted[i]; - } - std::cout << std::endl; +// 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 @@ -712,8 +715,8 @@ R3StretcherImpl::synthesiseChannel(int c, int outhop) scale->mag.data(), bufSize); - // formant shift only the middle register - if (m_parameters.options & RubberBandStretcher::OptionFormantPreserved) { + 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); diff --git a/src/finer/R3StretcherImpl.h b/src/finer/R3StretcherImpl.h index fee814c..b702025 100644 --- a/src/finer/R3StretcherImpl.h +++ b/src/finer/R3StretcherImpl.h @@ -221,11 +221,13 @@ protected: }; struct FormantData { + bool enabled; FixedVector cepstra; FixedVector envelope; FixedVector shifted; FormantData(int _fftSize) : + enabled(false), cepstra(_fftSize, 0.0), envelope(_fftSize, 0.0), shifted(_fftSize, 0.0) { }