Provide option to shift formant independently of pitch

This commit is contained in:
Chris Cannam
2022-06-13 10:39:13 +01:00
parent 182e2b0e3b
commit c7e4d9eb07
4 changed files with 70 additions and 1 deletions

View File

@@ -75,6 +75,12 @@ RubberBandStretcher::setPitchScale(double scale)
else m_r3d->setPitchScale(scale);
}
void
RubberBandStretcher::setFormantScale(double scale)
{
if (m_r3d) m_r3d->setFormantScale(scale);
}
double
RubberBandStretcher::getTimeRatio() const
{
@@ -89,6 +95,13 @@ RubberBandStretcher::getPitchScale() const
else return m_r3d->getPitchScale();
}
double
RubberBandStretcher::getFormantScale() const
{
if (m_d) return 0.0;
else return m_r3d->getFormantScale();
}
size_t
RubberBandStretcher::getLatency() const
{

View File

@@ -35,6 +35,7 @@ R3StretcherImpl::R3StretcherImpl(Parameters parameters,
m_parameters(parameters),
m_timeRatio(initialTimeRatio),
m_pitchScale(initialPitchScale),
m_formantScale(0.0),
m_guide(Guide::Parameters(m_parameters.sampleRate, parameters.logger)),
m_guideConfiguration(m_guide.getConfiguration()),
m_channelAssembly(m_parameters.channels),
@@ -173,6 +174,12 @@ R3StretcherImpl::setPitchScale(double scale)
calculateHop();
}
void
R3StretcherImpl::setFormantScale(double scale)
{
m_formantScale = scale;
}
void
R3StretcherImpl::setFormantOption(RubberBandStretcher::Options options)
{
@@ -233,6 +240,12 @@ R3StretcherImpl::getPitchScale() const
return m_pitchScale;
}
double
R3StretcherImpl::getFormantScale() const
{
return m_formantScale;
}
size_t
R3StretcherImpl::getLatency() const
{
@@ -777,7 +790,9 @@ R3StretcherImpl::adjustFormant(int c)
int highBin = int(floor(fftSize * 10000.0 / m_parameters.sampleRate));
double targetFactor = double(cd->formant->fftSize) / double(fftSize);
double sourceFactor = targetFactor * m_pitchScale;
double formantScale = m_formantScale;
if (formantScale == 0.0) formantScale = 1.0 / m_pitchScale;
double sourceFactor = targetFactor / formantScale;
double maxRatio = 60.0;
double minRatio = 1.0 / maxRatio;

View File

@@ -69,9 +69,11 @@ public:
void setTimeRatio(double ratio);
void setPitchScale(double scale);
void setFormantScale(double scale);
double getTimeRatio() const;
double getPitchScale() const;
double getFormantScale() const;
void setFormantOption(RubberBandStretcher::Options);
void setPitchOption(RubberBandStretcher::Options);
@@ -265,6 +267,7 @@ protected:
std::atomic<double> m_timeRatio;
std::atomic<double> m_pitchScale;
std::atomic<double> m_formantScale;
std::vector<std::shared_ptr<ChannelData>> m_channelData;
std::map<int, std::shared_ptr<ScaleData>> m_scaleData;