This commit is contained in:
Chris Cannam
2022-05-26 15:09:40 +01:00
2 changed files with 42 additions and 61 deletions

View File

@@ -48,18 +48,23 @@ public:
GuidedPhaseAdvance(Parameters parameters) :
m_parameters(parameters),
m_blockSize(parameters.fftSize / 2 + 1),
m_peakPicker(m_blockSize),
m_binCount(parameters.fftSize / 2 + 1),
m_peakPicker(m_binCount),
m_reported(false) {
size_t ch = m_parameters.channels;
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);
//!!! there is also a prevMag in R3StretcherImpl which could be passed in to here instead
m_prevInMag = allocate_and_zero_channels<double>(ch, m_blockSize);
m_prevInPhase = allocate_and_zero_channels<double>(ch, m_blockSize);
m_prevOutPhase = allocate_and_zero_channels<double>(ch, m_blockSize);
m_unlocked = allocate_and_zero_channels<double>(ch, m_blockSize);
m_currentPeaks = allocate_and_zero_channels<int>(ch, m_binCount);
m_prevPeaks = allocate_and_zero_channels<int>(ch, m_binCount);
m_greatestChannel = allocate_and_zero<int>(m_binCount);
m_prevInMag = allocate_and_zero_channels<double>(ch, m_binCount);
m_prevInPhase = allocate_and_zero_channels<double>(ch, m_binCount);
m_prevOutPhase = allocate_and_zero_channels<double>(ch, m_binCount);
m_unlocked = allocate_and_zero_channels<double>(ch, m_binCount);
for (int c = 0; c < ch; ++c) {
for (int i = 0; i < m_binCount; ++i) {
m_prevPeaks[c][i] = i;
}
}
}
~GuidedPhaseAdvance() {
@@ -127,27 +132,10 @@ public:
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;
}
}
*/
// m_peakPicker.findNearestAndNextPeaks(m_prevInMag[c],
// lowest, highest - lowest + 1,
// 2, m_prevPeaks[c],
// nullptr);
}
if (channels > 1) {
@@ -230,20 +218,15 @@ public:
m_prevOutPhase[c][i] = outPhase[c][i];
}
}
//!!! NB in the original we use a different value of p for
//!!! peak-picking the prior magnitudes - this isn't carried
//!!! 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:
Parameters m_parameters;
int m_blockSize;
int m_binCount;
Peak<double> m_peakPicker;
int **m_currentPeaks;
int **m_prevPeaks;

View File

@@ -415,12 +415,12 @@ R3StretcherImpl::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
cd->inbuf->peek(buf, longest);
}
// We have a single unwindowed frame at the longest FFT
// size ("scale"). Populate the shorter FFT sizes from the
// centre of it, windowing as we copy. The classification
// scale is handled separately because it has readahead,
// so skip it here as well as the longest. (In practice
// this means we are probably only populating one scale)
// We have a single unwindowed frame at the longest FFT size
// ("scale"). Populate the shorter FFT sizes from the centre of
// it, windowing as we copy. The classification scale is handled
// separately because it has readahead, so skip it here as well as
// the longest. (In practice this means we are probably only
// populating one scale)
for (auto &it: cd->scales) {
int fftSize = it.first;
@@ -539,9 +539,8 @@ R3StretcherImpl::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
}
}
// Use the classification scale to get a bin segmentation
// and calculate the adaptive frequency guide for this
// channel
// Use the classification scale to get a bin segmentation and
// calculate the adaptive frequency guide for this channel
cd->prevSegmentation = cd->segmentation;
cd->segmentation = cd->nextSegmentation;
cd->nextSegmentation = cd->segmenter->segment(readahead.mag.data());
@@ -595,9 +594,9 @@ R3StretcherImpl::synthesiseChannel(int c, int outhop)
}
winscale = double(outhop) / winscale;
// The frequency filter is applied naively in the
// frequency domain. Aliasing is reduced by the
// shorter resynthesis window
// The frequency filter is applied naively in the frequency
// domain. Aliasing is reduced by the shorter resynthesis
// window
double factor = m_parameters.sampleRate / double(fftSize);
for (int i = 0; i < fftSize/2 + 1; ++i) {
@@ -611,9 +610,9 @@ R3StretcherImpl::synthesiseChannel(int c, int outhop)
}
}
// Resynthesise each FFT size (scale) individually, then
// sum. This is easier to manage scaling for in situations
// with a varying resynthesis hop
// Resynthesise each FFT size (scale) individually, then sum. This
// is easier to manage scaling for in situations with a varying
// resynthesis hop
for (auto &it : cd->scales) {
int fftSize = it.first;
@@ -641,12 +640,11 @@ R3StretcherImpl::synthesiseChannel(int c, int outhop)
v_fftshift(scale->timeDomain.data(), fftSize);
// Synthesis window is shorter than analysis window,
// so copy and cut only from the middle of the
// time-domain frame; and the accumulator length
// always matches the longest FFT size, so as to make
// mixing straightforward, so there is an additional
// offset needed for the target
// Synthesis window may be shorter than analysis window, so
// copy and cut only from the middle of the time-domain frame;
// and the accumulator length always matches the longest FFT
// size, so as to make mixing straightforward, so there is an
// additional offset needed for the target
int synthesisWindowSize = scaleData->synthesisWindow.getSize();
int fromOffset = (fftSize - synthesisWindowSize) / 2;