This commit is contained in:
Chris Cannam
2022-06-06 17:10:12 +01:00
parent 100a7c0ba6
commit 6ef77ef7aa
2 changed files with 13 additions and 58 deletions

View File

@@ -598,11 +598,8 @@ R3StretcherImpl::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
}
if (m_parameters.options & RubberBandStretcher::OptionFormantPreserved) {
cd->formant->enabled = true;
analyseFormant(c);
adjustFormant(c);
} else {
cd->formant->enabled = false;
}
// Use the classification scale to get a bin segmentation and
@@ -622,9 +619,6 @@ R3StretcherImpl::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
classifyScale->troughs.data());
double instantaneousRatio = double(prevOuthop) / double(prevInhop);
//!!!??? bool specialCaseUnity = !(m_parameters.options &
// RubberBandStretcher::OptionPitchHighConsistency);
bool specialCaseUnity = true;
m_guide.calculate(instantaneousRatio,
@@ -682,40 +676,27 @@ R3StretcherImpl::adjustFormant(int c)
int fftSize = it.first;
auto &scale = it.second;
int formantHigh = int(floor(fftSize * 10000.0 / m_parameters.sampleRate));
/*
int lowBin = int(floor(fftSize * band.f0 / m_parameters.sampleRate));
int highBin = int(floor(fftSize * band.f1 / m_parameters.sampleRate));
if (highBin % 2 == 1) --highBin;
for (int i = 0; i < lowBin; ++i) {
scale->mag[i] = 0.0;
}
*/
int highBin = int(floor(fftSize * 10000.0 / m_parameters.sampleRate));
double targetFactor = double(cd->formant->fftSize) / double(fftSize);
double sourceFactor = targetFactor * m_pitchScale;
double maxRatio = 60.0;
double minRatio = 1.0 / maxRatio;
for (const auto &b : m_guideConfiguration.fftBandLimits) {
if (b.fftSize == fftSize) {
// double maxRatio = 60.0;
// double minRatio = 1.0 / maxRatio;
// for (int i = lowBin; i < highBin && i < formantHigh; ++i) {
for (int i = b.b0min; i < b.b1max && i < formantHigh; ++i) {
if (b.fftSize != fftSize) continue;
for (int i = b.b0min; i < b.b1max && i < highBin; ++i) {
double source = cd->formant->envelopeAt(i * sourceFactor);
double target = cd->formant->envelopeAt(i * targetFactor);
if (target > 0.0) {
double ratio = source / target;
// if (ratio < minRatio) ratio = minRatio;
// if (ratio > maxRatio) ratio = maxRatio;
if (ratio < minRatio) ratio = minRatio;
if (ratio > maxRatio) ratio = maxRatio;
scale->mag[i] *= ratio;
}
}
}
}
}
}
void
R3StretcherImpl::synthesiseChannel(int c, int outhop)
@@ -735,10 +716,6 @@ R3StretcherImpl::synthesiseChannel(int c, int outhop)
bufSize);
}
// if (m_formant->enabled) {
// adjustFormant(c);
// }
for (const auto &band : cd->guidance.fftBands) {
int fftSize = band.fftSize;
auto &scale = cd->scales.at(fftSize);
@@ -767,30 +744,10 @@ R3StretcherImpl::synthesiseChannel(int c, int outhop)
int lowBin = int(floor(fftSize * band.f0 / m_parameters.sampleRate));
int highBin = int(floor(fftSize * band.f1 / m_parameters.sampleRate));
if (highBin % 2 == 1) --highBin;
/*
int formantHigh = int(floor(fftSize * 10000.0 / m_parameters.sampleRate));
*/
for (int i = 0; i < lowBin; ++i) {
scale->mag[i] = 0.0;
}
/*
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 < minRatio) ratio = minRatio;
if (ratio > maxRatio) ratio = maxRatio;
scale->mag[i] *= ratio;
}
}
}
*/
for (int i = lowBin; i < highBin; ++i) {
scale->mag[i] *= winscale;
}

View File

@@ -138,14 +138,12 @@ protected:
};
struct FormantData {
bool enabled;
int fftSize;
FixedVector<double> cepstra;
FixedVector<double> envelope;
FixedVector<double> spare;
FormantData(int _fftSize) :
enabled(false),
fftSize(_fftSize),
cepstra(_fftSize, 0.0),
envelope(_fftSize/2 + 1, 0.0),