changeset 32:023d12fb71b1

Some sample rate / parameter combinations result in min bin > max bin -- reject them
author Chris Cannam
date Thu, 04 Sep 2014 10:08:47 +0100
parents f795b84c1ff2
children a824d7d14eb9
files TempogramPlugin.cpp
diffstat 1 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/TempogramPlugin.cpp	Thu Sep 04 10:08:09 2014 +0100
+++ b/TempogramPlugin.cpp	Thu Sep 04 10:08:47 2014 +0100
@@ -601,9 +601,29 @@
     float tempogramInputSampleRate = (float)m_inputSampleRate/m_inputStepSize;
     m_tempogramMinBin = (max((int)floor(((m_tempogramMinBPM/60)/tempogramInputSampleRate)*m_tempogramFftLength), 0));
     m_tempogramMaxBin = (min((int)ceil(((m_tempogramMaxBPM/60)/tempogramInputSampleRate)*m_tempogramFftLength), (int)(m_tempogramFftLength/2)));
+
+    if (m_tempogramMaxBin < m_tempogramMinBin) {
+	cerr << "At audio sample rate " << m_inputSampleRate
+	     << ", tempogram sample rate " << tempogramInputSampleRate
+	     << " with bpm range " << m_tempogramMinBPM << " -> "
+	     << m_tempogramMaxBPM << ", min bin = " << m_tempogramMinBin 
+	     << " > max bin " << m_tempogramMaxBin
+	     << ": can't proceed, failing initialise" << endl;
+	return false;
+    }
     
     m_tempogramMinLag = max((int)ceil((60/(m_inputStepSize * m_tempogramMaxBPM))*m_inputSampleRate), 0);
     m_tempogramMaxLag = min((int)floor((60/(m_inputStepSize * m_tempogramMinBPM))*m_inputSampleRate), (int)m_tempogramWindowLength);
+
+    if (m_tempogramMaxLag < m_tempogramMinLag) {
+	cerr << "At audio sample rate " << m_inputSampleRate
+	     << ", tempogram sample rate " << tempogramInputSampleRate
+	     << " with bpm range " << m_tempogramMinBPM << " -> "
+	     << m_tempogramMaxBPM << ", min bin = " << m_tempogramMinLag 
+	     << " > max bin " << m_tempogramMaxLag
+	     << ": can't proceed, failing initialise" << endl;
+	return false;
+    }
     
     if (m_tempogramMinBPM > m_cyclicTempogramMinBPM) m_cyclicTempogramMinBPM = m_tempogramMinBPM; //m_cyclicTempogram can't be less than default = 30
     float cyclicTempogramMaxBPM = 480;