Implement reset
This commit is contained in:
@@ -77,6 +77,14 @@ public:
|
|||||||
deallocate_channels(m_prevOutPhase, ch);
|
deallocate_channels(m_prevOutPhase, ch);
|
||||||
deallocate_channels(m_unlocked, 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,
|
void advance(double *const *outPhase,
|
||||||
const double *const *mag,
|
const double *const *mag,
|
||||||
|
|||||||
@@ -195,7 +195,19 @@ R3StretcherImpl::getChannelCount() const
|
|||||||
void
|
void
|
||||||
R3StretcherImpl::reset()
|
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
|
size_t
|
||||||
@@ -303,8 +315,6 @@ R3StretcherImpl::consume()
|
|||||||
// advanced the input and output since the previous frame, not the
|
// advanced the input and output since the previous frame, not the
|
||||||
// distances we are about to advance them, so they use the m_prev
|
// distances we are about to advance them, so they use the m_prev
|
||||||
// values.
|
// values.
|
||||||
|
|
||||||
// std::cout << "outhop = " << outhop << std::endl;
|
|
||||||
|
|
||||||
if (inhop != m_prevInhop) {
|
if (inhop != m_prevInhop) {
|
||||||
std::cout << "Note: inhop has changed from " << 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
|
// rather than classification) anew rather than reuse the previous
|
||||||
// readahead. Pity...
|
// readahead. Pity...
|
||||||
|
|
||||||
if (inhop != prevInhop) {
|
bool haveValidReadahead = cd->haveReadahead;
|
||||||
|
if (inhop != prevInhop) haveValidReadahead = false;
|
||||||
|
|
||||||
|
if (!haveValidReadahead) {
|
||||||
m_scaleData.at(classify)->analysisWindow.cut
|
m_scaleData.at(classify)->analysisWindow.cut
|
||||||
(buf + (longest - classify) / 2,
|
(buf + (longest - classify) / 2,
|
||||||
classifyScale->timeDomain.data());
|
classifyScale->timeDomain.data());
|
||||||
@@ -477,7 +490,7 @@ R3StretcherImpl::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
|
|||||||
|
|
||||||
v_fftshift(readahead.timeDomain.data(), classify);
|
v_fftshift(readahead.timeDomain.data(), classify);
|
||||||
|
|
||||||
if (inhop == prevInhop) {
|
if (haveValidReadahead) {
|
||||||
v_copy(classifyScale->mag.data(),
|
v_copy(classifyScale->mag.data(),
|
||||||
readahead.mag.data(),
|
readahead.mag.data(),
|
||||||
classifyScale->bufSize);
|
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
|
// For the others (and the classify if the inhop has changed) we
|
||||||
// operate directly in the scale data and restrict the range for
|
// operate directly in the scale data and restrict the range for
|
||||||
// cartesian-polar conversion
|
// cartesian-polar conversion
|
||||||
|
|
||||||
for (auto &it: cd->scales) {
|
for (auto &it: cd->scales) {
|
||||||
int fftSize = it.first;
|
int fftSize = it.first;
|
||||||
if (fftSize == classify && inhop == prevInhop) continue;
|
if (fftSize == classify && haveValidReadahead) continue;
|
||||||
auto &scale = it.second;
|
auto &scale = it.second;
|
||||||
|
|
||||||
v_fftshift(scale->timeDomain.data(), fftSize);
|
v_fftshift(scale->timeDomain.data(), fftSize);
|
||||||
|
|||||||
@@ -119,6 +119,11 @@ protected:
|
|||||||
accumulator(_longestFftSize, 0.f)
|
accumulator(_longestFftSize, 0.f)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
v_zero(prevMag.data(), prevMag.size());
|
||||||
|
v_zero(accumulator.data(), accumulator.size());
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ChannelScaleData(const ChannelScaleData &) =delete;
|
ChannelScaleData(const ChannelScaleData &) =delete;
|
||||||
ChannelScaleData &operator=(const ChannelScaleData &) =delete;
|
ChannelScaleData &operator=(const ChannelScaleData &) =delete;
|
||||||
@@ -127,6 +132,7 @@ protected:
|
|||||||
struct ChannelData {
|
struct ChannelData {
|
||||||
std::map<int, std::shared_ptr<ChannelScaleData>> scales;
|
std::map<int, std::shared_ptr<ChannelScaleData>> scales;
|
||||||
ClassificationReadaheadData readahead;
|
ClassificationReadaheadData readahead;
|
||||||
|
bool haveReadahead;
|
||||||
std::unique_ptr<BinSegmenter> segmenter;
|
std::unique_ptr<BinSegmenter> segmenter;
|
||||||
BinSegmenter::Segmentation segmentation;
|
BinSegmenter::Segmentation segmentation;
|
||||||
BinSegmenter::Segmentation prevSegmentation;
|
BinSegmenter::Segmentation prevSegmentation;
|
||||||
@@ -143,6 +149,7 @@ protected:
|
|||||||
int outRingBufferSize) :
|
int outRingBufferSize) :
|
||||||
scales(),
|
scales(),
|
||||||
readahead(segmenterParameters.fftSize),
|
readahead(segmenterParameters.fftSize),
|
||||||
|
haveReadahead(false),
|
||||||
segmenter(new BinSegmenter(segmenterParameters,
|
segmenter(new BinSegmenter(segmenterParameters,
|
||||||
classifierParameters)),
|
classifierParameters)),
|
||||||
segmentation(), prevSegmentation(), nextSegmentation(),
|
segmentation(), prevSegmentation(), nextSegmentation(),
|
||||||
@@ -150,6 +157,17 @@ protected:
|
|||||||
resampled(outRingBufferSize, 0.f),
|
resampled(outRingBufferSize, 0.f),
|
||||||
inbuf(new RingBuffer<float>(inRingBufferSize)),
|
inbuf(new RingBuffer<float>(inRingBufferSize)),
|
||||||
outbuf(new RingBuffer<float>(outRingBufferSize)) { }
|
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 {
|
struct ChannelAssembly {
|
||||||
|
|||||||
Reference in New Issue
Block a user