# HG changeset patch # User Chris Cannam # Date 1400075978 -3600 # Node ID fe4440881a082e47e40087a2a167743280fef430 # Parent fdd32f995b0d029d1f6c253c5d52b5ceb72dbc58 Make kernel a bit more robust to weird parameters diff -r fdd32f995b0d -r fe4440881a08 cpp-qm-dsp/CQKernel.cpp --- a/cpp-qm-dsp/CQKernel.cpp Wed May 14 14:04:34 2014 +0100 +++ b/cpp-qm-dsp/CQKernel.cpp Wed May 14 14:59:38 2014 +0100 @@ -79,6 +79,18 @@ (m_p.Q * m_p.sampleRate / (m_p.minFrequency * pow(2, (bpo - 1.0) / bpo))); + if (minNK == 0 || maxNK == 0) { + // most likely pathological parameters of some sort + cerr << "WARNING: CQKernel::generateKernel: minNK or maxNK is zero (minNK == " << minNK << ", maxNK == " << maxNK << "), not generating a kernel" << endl; + m_p.atomSpacing = 0; + m_p.firstCentre = 0; + m_p.fftSize = 0; + m_p.atomsPerFrame = 0; + m_p.lastCentre = 0; + m_p.fftHop = 0; + return; + } + m_p.atomSpacing = round(minNK * atomHopFactor); m_p.firstCentre = m_p.atomSpacing * ceil(ceil(maxNK / 2.0) / m_p.atomSpacing); m_p.fftSize = MathUtilities::nextPowerOfTwo @@ -87,7 +99,7 @@ m_p.atomsPerFrame = floor (1.0 + (m_p.fftSize - ceil(maxNK / 2.0) - m_p.firstCentre) / m_p.atomSpacing); - cerr << "atomsPerFrame = " << m_p.atomsPerFrame << " (atomHopFactor = " << atomHopFactor << ")" << endl; + cerr << "atomsPerFrame = " << m_p.atomsPerFrame << " (atomHopFactor = " << atomHopFactor << ", atomSpacing = " << m_p.atomSpacing << ", fftSize = " << m_p.fftSize << ", maxNK = " << maxNK << ", firstCentre = " << m_p.firstCentre << ")" << endl; m_p.lastCentre = m_p.firstCentre + (m_p.atomsPerFrame - 1) * m_p.atomSpacing; @@ -280,6 +292,8 @@ // straightforward matrix multiply (taking into account m_kernel's // slightly-sparse representation) + if (m_kernel.data.empty()) return vector(); + int nrows = m_p.binsPerOctave * m_p.atomsPerFrame; vector rv(nrows, C()); @@ -302,6 +316,8 @@ // conjugate-transpose of the kernel because we expect to be doing // more forward transforms than inverse ones. + if (m_kernel.data.empty()) return vector(); + int ncols = m_p.binsPerOctave * m_p.atomsPerFrame; int nrows = m_p.fftSize;