Mercurial > hg > constant-q-cpp
changeset 54:2e0d1300a065
Correct output latency
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Thu, 28 Nov 2013 14:32:42 +0000 |
parents | a25abb7a21c0 |
children | 2a21b4506d7f |
files | cpp-qm-dsp/CQKernel.cpp cpp-qm-dsp/CQKernel.h cpp-qm-dsp/ConstantQ.cpp cpp-qm-dsp/ConstantQ.h |
diffstat | 4 files changed, 19 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/cpp-qm-dsp/CQKernel.cpp Thu Nov 28 11:46:39 2013 +0000 +++ b/cpp-qm-dsp/CQKernel.cpp Thu Nov 28 14:32:42 2013 +0000 @@ -60,9 +60,9 @@ cerr << "atomsPerFrame = " << m_p.atomsPerFrame << " (atomHopFactor = " << atomHopFactor << ")" << endl; - int lastCentre = m_p.firstCentre + (m_p.atomsPerFrame - 1) * m_p.atomSpacing; + m_p.lastCentre = m_p.firstCentre + (m_p.atomsPerFrame - 1) * m_p.atomSpacing; - m_p.fftHop = (lastCentre + m_p.atomSpacing) - m_p.firstCentre; + m_p.fftHop = (m_p.lastCentre + m_p.atomSpacing) - m_p.firstCentre; cerr << "fftHop = " << m_p.fftHop << endl;
--- a/cpp-qm-dsp/CQKernel.h Thu Nov 28 11:46:39 2013 +0000 +++ b/cpp-qm-dsp/CQKernel.h Thu Nov 28 14:32:42 2013 +0000 @@ -24,6 +24,7 @@ int atomsPerFrame; int atomSpacing; int firstCentre; + int lastCentre; double Q; };
--- a/cpp-qm-dsp/ConstantQ.cpp Thu Nov 28 11:46:39 2013 +0000 +++ b/cpp-qm-dsp/ConstantQ.cpp Thu Nov 28 14:32:42 2013 +0000 @@ -111,7 +111,7 @@ m_decimators.push_back(r); } - m_bigBlockSize = m_p.fftSize * pow(2, m_octaves) / 2; + m_bigBlockSize = m_p.fftSize * pow(2, m_octaves - 1); // Now add in the extra padding and compensate for hops that must // be dropped in order to align the atom centres across @@ -135,18 +135,23 @@ if (latPlusDrop > maxLatPlusDrop) maxLatPlusDrop = latPlusDrop; } - // we want to design m_totalLatency such that m_totalLatency - + // we want to design totalLatency such that totalLatency - // latencies[0] - drops[0] is a multiple of m_p.fftHop, so that we // can get identical results in octave 0 to our reference // implementation, making for easier testing (though other octaves // will differ because of different resampler implementations) - m_totalLatency = maxLatPlusDrop; - int lat0 = m_totalLatency - latencies[0] - drops[0]; - m_totalLatency = ceil(double(lat0 / m_p.fftHop) * m_p.fftHop) + int totalLatency = maxLatPlusDrop; + int lat0 = totalLatency - latencies[0] - drops[0]; + totalLatency = ceil(double(lat0 / m_p.fftHop) * m_p.fftHop) + latencies[0] + drops[0]; - cerr << "total latency = " << m_totalLatency << endl; + cerr << "total latency = " << totalLatency << endl; + + // Padding as in the reference (will be introduced with the + // latency compensation in the loop below) + m_outputLatency = totalLatency + m_bigBlockSize + - m_p.firstCentre * pow(2, m_octaves-1); for (int i = 0; i < m_octaves; ++i) { @@ -160,7 +165,7 @@ // (as in the reference). double octaveLatency = - double(m_totalLatency - latencies[i] - drops[i] + double(totalLatency - latencies[i] - drops[i] + m_bigBlockSize) / factor; m_buffers.push_back @@ -239,15 +244,8 @@ vector<vector<double> > ConstantQ::getRemainingBlocks() { - int n = ceil(double(m_totalLatency) / m_bigBlockSize) * m_bigBlockSize; - - int pad = m_p.fftSize * pow(2, m_octaves-1); // same as padding - // added at start - - pad += n; - - cerr << "pad = " << pad << endl; - + // Same as padding added at start, though rounded up + int pad = ceil(double(m_outputLatency) / m_bigBlockSize) * m_bigBlockSize; vector<double> zeros(pad, 0.0); return process(zeros); }
--- a/cpp-qm-dsp/ConstantQ.h Thu Nov 28 11:46:39 2013 +0000 +++ b/cpp-qm-dsp/ConstantQ.h Thu Nov 28 14:32:42 2013 +0000 @@ -25,7 +25,7 @@ int getOctaves() const { return m_octaves; } int getTotalBins() const { return m_octaves * m_binsPerOctave; } int getColumnHop() const { return m_p.fftHop / m_p.atomsPerFrame; } - int getLatency() const { return m_totalLatency; } // a multiple of column hop + int getLatency() const { return m_outputLatency; } std::vector<std::vector<double> > process(const std::vector<double> &); std::vector<std::vector<double> > getRemainingBlocks(); @@ -44,7 +44,7 @@ std::vector<Resampler *> m_decimators; std::vector<std::vector<double> > m_buffers; - int m_totalLatency; + int m_outputLatency; FFTReal *m_fft;