Implement reset

This commit is contained in:
Chris Cannam
2022-05-27 11:17:20 +01:00
parent 580d28afd2
commit 9ecc601a2c
3 changed files with 47 additions and 6 deletions

View File

@@ -77,6 +77,14 @@ public:
deallocate_channels(m_prevOutPhase, ch);
deallocate_channels(m_unlocked, ch);
}
void reset() {
size_t ch = m_parameters.channels;
v_zero_channels(m_prevPeaks, ch, m_binCount);
v_zero_channels(m_prevInMag, ch, m_binCount);
v_zero_channels(m_prevInPhase, ch, m_binCount);
v_zero_channels(m_prevOutPhase, ch, m_binCount);
}
void advance(double *const *outPhase,
const double *const *mag,

View File

@@ -195,7 +195,19 @@ R3StretcherImpl::getChannelCount() const
void
R3StretcherImpl::reset()
{
//!!!
m_calculator->reset();
m_resampler->reset();
for (auto &it : m_scaleData) {
it.second->guided.reset();
}
for (auto &cd : m_channelData) {
cd->reset();
}
m_prevInhop = m_inhop;
m_prevOuthop = int(round(m_inhop * getEffectiveRatio()));
}
size_t
@@ -303,8 +315,6 @@ 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.
// std::cout << "outhop = " << outhop << std::endl;
if (inhop != m_prevInhop) {
std::cout << "Note: inhop has changed from " << m_prevInhop
@@ -457,7 +467,10 @@ R3StretcherImpl::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
// rather than classification) anew rather than reuse the previous
// readahead. Pity...
if (inhop != prevInhop) {
bool haveValidReadahead = cd->haveReadahead;
if (inhop != prevInhop) haveValidReadahead = false;
if (!haveValidReadahead) {
m_scaleData.at(classify)->analysisWindow.cut
(buf + (longest - classify) / 2,
classifyScale->timeDomain.data());
@@ -477,7 +490,7 @@ R3StretcherImpl::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
v_fftshift(readahead.timeDomain.data(), classify);
if (inhop == prevInhop) {
if (haveValidReadahead) {
v_copy(classifyScale->mag.data(),
readahead.mag.data(),
classifyScale->bufSize);
@@ -520,13 +533,15 @@ R3StretcherImpl::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
}
}
cd->haveReadahead = true;
// For the others (and the classify if the inhop has changed) we
// operate directly in the scale data and restrict the range for
// cartesian-polar conversion
for (auto &it: cd->scales) {
int fftSize = it.first;
if (fftSize == classify && inhop == prevInhop) continue;
if (fftSize == classify && haveValidReadahead) continue;
auto &scale = it.second;
v_fftshift(scale->timeDomain.data(), fftSize);

View File

@@ -119,6 +119,11 @@ protected:
accumulator(_longestFftSize, 0.f)
{ }
void reset() {
v_zero(prevMag.data(), prevMag.size());
v_zero(accumulator.data(), accumulator.size());
}
private:
ChannelScaleData(const ChannelScaleData &) =delete;
ChannelScaleData &operator=(const ChannelScaleData &) =delete;
@@ -127,6 +132,7 @@ protected:
struct ChannelData {
std::map<int, std::shared_ptr<ChannelScaleData>> scales;
ClassificationReadaheadData readahead;
bool haveReadahead;
std::unique_ptr<BinSegmenter> segmenter;
BinSegmenter::Segmentation segmentation;
BinSegmenter::Segmentation prevSegmentation;
@@ -143,6 +149,7 @@ protected:
int outRingBufferSize) :
scales(),
readahead(segmenterParameters.fftSize),
haveReadahead(false),
segmenter(new BinSegmenter(segmenterParameters,
classifierParameters)),
segmentation(), prevSegmentation(), nextSegmentation(),
@@ -150,6 +157,17 @@ protected:
resampled(outRingBufferSize, 0.f),
inbuf(new RingBuffer<float>(inRingBufferSize)),
outbuf(new RingBuffer<float>(outRingBufferSize)) { }
void reset() {
haveReadahead = false;
segmentation = BinSegmenter::Segmentation();
prevSegmentation = BinSegmenter::Segmentation();
nextSegmentation = BinSegmenter::Segmentation();
inbuf->reset();
outbuf->reset();
for (auto &s : scales) {
s.second->reset();
}
}
};
struct ChannelAssembly {