Some work on phase updates

This commit is contained in:
Chris Cannam
2022-05-24 15:21:13 +01:00
parent 2b401e5cbe
commit 49ac04ceab
4 changed files with 54 additions and 22 deletions

View File

@@ -77,15 +77,11 @@ public:
struct BandLimits {
int fftSize;
float f0min;
float f0max;
float f1min;
float f1max;
BandLimits(int _fftSize, float _f0min, float _f0max,
float _f1min, float _f1max) :
fftSize(_fftSize), f0min(_f0min), f0max(_f0max),
f1min(_f1min), f1max(_f1max) { }
BandLimits(int _fftSize, float _f0min, float _f1max) :
fftSize(_fftSize), f0min(_f0min), f1max(_f1max) { }
BandLimits() :
fftSize(0), f0min(0.f), f0max(0.f), f1min(0.f), f1max(0.f) { }
fftSize(0), f0min(0.f), f1max(0.f) { }
};
struct Configuration {
@@ -114,19 +110,21 @@ public:
m_configuration(roundUp(int(ceil(parameters.sampleRate / 16.0))),
roundUp(int(ceil(parameters.sampleRate / 64.0))),
roundUp(int(ceil(parameters.sampleRate / 32.0)))),
m_minLower(350.0), m_minHigher(2400.0),
m_defaultLower(700.0), m_defaultHigher(4800.0),
m_maxLower(1100.0), m_maxHigher(7000.0)
{
double rate = m_parameters.sampleRate;
double nyquist = rate / 2.0;
m_configuration.fftBandLimits[0] =
BandLimits(roundUp(int(ceil(rate/16.0))),
0.0, 0.0, m_defaultLower, m_maxLower);
0.0, m_maxLower);
m_configuration.fftBandLimits[1] =
BandLimits(roundUp(int(ceil(rate/32.0))),
m_defaultLower, m_maxLower, m_defaultHigher, m_maxHigher);
m_minLower, m_maxHigher);
m_configuration.fftBandLimits[2] =
BandLimits(roundUp(int(ceil(rate/64.0))),
m_defaultHigher, m_maxHigher, rate/2.0, rate/2.0);
m_minHigher, rate/2.0);
}
const Configuration &getConfiguration() const {
@@ -248,6 +246,8 @@ protected:
Parameters m_parameters;
Configuration m_configuration;
double m_minLower;
double m_minHigher;
double m_defaultLower;
double m_defaultHigher;
double m_maxLower;

View File

@@ -110,7 +110,7 @@ public:
if (j == 0) {
nearest[i] = np;
} else {
if (np - i < i - pp) {
if (np - i <= i - pp) {
nearest[i] = np;
} else {
nearest[i] = pp;

View File

@@ -55,6 +55,7 @@ public:
m_currentPeaks = allocate_and_zero_channels<int>(ch, m_blockSize);
m_prevPeaks = allocate_and_zero_channels<int>(ch, m_blockSize);
m_greatestChannel = allocate_and_zero<int>(m_blockSize);
m_prevInMag = allocate_and_zero_channels<float>(ch, m_blockSize);
m_prevInPhase = allocate_and_zero_channels<float>(ch, m_blockSize);
m_prevOutPhase = allocate_and_zero_channels<double>(ch, m_blockSize);
m_unlocked = allocate_and_zero_channels<double>(ch, m_blockSize);
@@ -65,6 +66,7 @@ public:
deallocate_channels(m_currentPeaks, ch);
deallocate_channels(m_prevPeaks, ch);
deallocate(m_greatestChannel);
deallocate_channels(m_prevInMag, ch);
deallocate_channels(m_prevInPhase, ch);
deallocate_channels(m_prevOutPhase, ch);
deallocate_channels(m_unlocked, ch);
@@ -120,10 +122,33 @@ public:
int startBin = binForFrequency(band.f0);
int endBin = binForFrequency(band.f1);
if (startBin > highest || endBin < lowest) continue;
int count = endBin - startBin;
int count = endBin - startBin + 1;
m_peakPicker.findNearestAndNextPeaks(mag[c], startBin, count,
band.p, m_currentPeaks[c]);
band.p, m_currentPeaks[c],
nullptr);
}
m_peakPicker.findNearestAndNextPeaks(m_prevInMag[c],
lowest, highest - lowest + 1,
2, m_prevPeaks[c],
nullptr);
/*
static int counter = 0;
if (c == 0) {
if (++counter > 140 && counter < 150) {
std::cout << "Magnitudes and peaks (fftSize = " << m_parameters.fftSize << "):" << std::endl;
for (int i = 0; i < bs; ++i) {
if (m_currentPeaks[c][i] == i) {
std::cout << "*";
}
std::cout << mag[c][i] << ", ";
}
std::cout << std::endl;
}
}
*/
}
if (channels > 1) {
@@ -163,10 +188,9 @@ public:
++phaseLockBand;
}
double ph = 0.0;
/*
if (inRange(f, g->phaseReset) || inRange(f, g->kick)) {
ph = phase[c][i];
} else */ if (inRange (f, g->highPercussive)) {
} else if (inRange (f, g->highPercussive)) {
ph = m_unlocked[c][i];
} else {
int peak = m_currentPeaks[c][i];
@@ -200,8 +224,9 @@ public:
for (int i = lowest; i <= highest; ++i) {
m_prevInPhase[c][i] = phase[c][i];
}
}
for (int c = 0; c < channels; ++c) {
for (int i = lowest; i <= highest; ++i) {
m_prevInMag[c][i] = mag[c][i];
}
for (int i = lowest; i <= highest; ++i) {
m_prevOutPhase[c][i] = outPhase[c][i];
}
@@ -209,11 +234,12 @@ public:
//!!! NB in the original we use a different value of p for
//!!! peak-picking the prior magnitudes - this isn't carried
//!!! over here
//!!! over here - it is now but I don't think this was the
//!!! full cause of our burbling
int **tmp = m_prevPeaks;
m_prevPeaks = m_currentPeaks;
m_currentPeaks = tmp;
// int **tmp = m_prevPeaks;
// m_prevPeaks = m_currentPeaks;
// m_currentPeaks = tmp;
}
protected:
@@ -223,6 +249,7 @@ protected:
int **m_currentPeaks;
int **m_prevPeaks;
int *m_greatestChannel;
float **m_prevInMag;
float **m_prevInPhase;
double **m_prevOutPhase;
double **m_unlocked;

View File

@@ -187,7 +187,12 @@ R3StretcherImpl::consume()
std::cout << "outhop = " << outhop << std::endl;
double instantaneousRatio = double(outhop) / double(m_inhop);
//!!!
outhop = int(round(m_inhop * ratio));
//!!! shouldn't this be the *previous* outhop?
// double instantaneousRatio = double(outhop) / double(m_inhop);
double instantaneousRatio = ratio;
while (m_channelData.at(0)->outbuf->getWriteSpace() >= outhop) {