changeset 116:b8969a96b678

bug in DIT filter integration found !!!!
author lbajardsilogic
date Fri, 21 Sep 2007 07:29:52 +0000
parents 1ae07a8c28a0
children 493ccef46cab
files sv/filter/DSP.cpp sv/filter/TimeStretchFilter.cpp
diffstat 2 files changed, 173 insertions(+), 169 deletions(-) [+]
line wrap: on
line diff
--- a/sv/filter/DSP.cpp	Thu Sep 20 09:16:41 2007 +0000
+++ b/sv/filter/DSP.cpp	Fri Sep 21 07:29:52 2007 +0000
@@ -220,7 +220,7 @@
 		//c_synthphase[i]=p_synthphase[i]+((phase_diff*diffhop)*interpfactor);
 		
 		//if (currentposition<framesize/2 || (!(lastfactor==hopfactor))){c_synthphase[i] = c_phase[i];}
-		if (currentposition<framesize/2){c_synthphase[i] = c_phase[i];}
+		//if (currentposition<framesize/2){c_synthphase[i] = c_phase[i];}
 		
 		p_synthphase[i]=c_synthphase[i];
 	}
@@ -288,7 +288,7 @@
 		//c_synthphase[i]=p_synthphase[i]+(phase_diff);
 		//c_synthphase[i]=p_synthphase[i]+((phase_diff*diffhop)*interpfactor);
 		//if (currentposition<framesize/2 || (!(lastfactor==hopfactor))){c_synthphase[i] = c_phase[i];}
-		if (currentposition<framesize/2){c_synthphase[i] = c_phase[i];}
+		//if (currentposition<framesize/2){c_synthphase[i] = c_phase[i];}
 		p_synthphase[i]=c_synthphase[i];
 
 		int j;
--- a/sv/filter/TimeStretchFilter.cpp	Thu Sep 20 09:16:41 2007 +0000
+++ b/sv/filter/TimeStretchFilter.cpp	Fri Sep 21 07:29:52 2007 +0000
@@ -48,24 +48,26 @@
 
 int numpeaks;
 float *peak_locations; 
-int currentposition = 1024+1;//= hop+1;
+int currentposition;
 //
 
 TimeStretchFilter::TimeStretchFilter() : Filter(),
-	m_bypass(false),
-	m_transcheck(false),
+	m_bypass(false),
+	m_transcheck(true),
 	m_peakcheck(false),
 	m_framesize(4096),
 	m_interpfactor(1),
 	m_transhold(0),
-	m_tmaxfactor(2),
+	m_tmaxfactor(2),
 	m_pmaxfactor(2)
 {
 	m_hop = m_framesize/4;
 
+	currentposition = m_hop;
+
 	m_inputBuffer = (float *)calloc(m_framesize*(m_pmaxfactor+1), sizeof(float));
 	
-	/**********malloc***********/
+	/**********malloc***********/
 	FFTframe=(float *)calloc((m_framesize), sizeof(float));
 			
 	//This block specifically sets up the buffers required to do a 75% overlap scheme
@@ -88,15 +90,15 @@
 	p_synthphase=(float *)calloc((m_framesize/2), sizeof(float));
 
 	peak_locations=(float *)calloc((m_framesize/2), sizeof(float));
-
-	hanning(window, m_framesize);
-
+
+	hanning(window, m_framesize);
+
 	/***************************/
 }
 
 TimeStretchFilter::~TimeStretchFilter()
 {
-	/**********de-alloc***********/
+	/**********de-alloc***********/
 	delete m_inputBuffer;
 	delete FFTframe;
 			
@@ -126,100 +128,100 @@
 
 TimeStretchFilter::PropertyList TimeStretchFilter::getProperties() const
 {
-	PropertyList list;
-    list.push_back("Time");
-	list.push_back("Pitch");
-	list.push_back("Bypass");
-	list.push_back("Transdetect");
-	list.push_back("Peaklock");
+	PropertyList list;
+    list.push_back("Time");
+	list.push_back("Pitch");
+	list.push_back("Bypass");
+	list.push_back("Transdetect");
+	list.push_back("Peaklock");
     return list;
 }
 
-QString TimeStretchFilter::getPropertyLabel(const PropertyName &name) const
-{
-    if (name == "Time") return tr("Time");
-	if (name == "Pitch") return tr("Pitch");
-	if (name == "Bypass") return tr("Bypass Processing");
-	if (name == "Transdetect") return tr("Transient Detection");
-	if (name == "Peaklock") return tr("Peak Locking");
-    return "";
+QString TimeStretchFilter::getPropertyLabel(const PropertyName &name) const
+{
+    if (name == "Time") return tr("Time");
+	if (name == "Pitch") return tr("Pitch");
+	if (name == "Bypass") return tr("Bypass Processing");
+	if (name == "Transdetect") return tr("Transient Detection");
+	if (name == "Peaklock") return tr("Peak Locking");
+    return "";
 }
 
-TimeStretchFilter::PropertyType TimeStretchFilter::getPropertyType(const PropertyName &name) const
-{
-	if (name == "Time") return RangeProperty;
-	if (name == "Pitch") return RangeProperty;
-	if (name == "Bypass") return ToggleProperty;
-	if (name == "Transdetect") return ToggleProperty;
-	if (name == "Peaklock") return ToggleProperty;
-    return InvalidProperty;
-}
-
-int TimeStretchFilter::getPropertyRangeAndValue(const PropertyName &name,
-                                    int *min, int *max, int *deflt) const
-{
-    //!!! factor this colour handling stuff out into a colour manager class
-	int val = 0;
-
-    if (name == "Time") {
-		if (min) *min = -100;
-		if (max) *max = 100;
-		if (deflt) *deflt = 0;
-		if (hopfactor > 1)
-			val = (hopfactor-1)/(m_tmaxfactor-1)*100.0;
-		else if (hopfactor < 1)
-			val = (1/hopfactor - 1)*(1-m_tmaxfactor)*100.0;
-		else if (hopfactor == 1)
-			val = 0;
-	}
-
-	if (name == "Pitch") {
-		if (min) *min = -100;
-		if (max) *max = 100;
-		if (deflt) *deflt = 0;
-		if (m_interpfactor > 1)
-			val = (m_interpfactor-1)/(m_pmaxfactor-1)*100.0;
-		else if (m_interpfactor < 1)
-			val = (1/m_interpfactor - 1)*(1-m_pmaxfactor)*100.0;
-		else if (m_interpfactor == 1)
-			val = 0;
-	}
-
-	if (name == "Bypass") {
-        if (deflt) *deflt = 0;
-		val = (m_bypass ? 1 : 0);
-    }
-
-	if (name == "Transdetect") {
-        if (deflt) *deflt = 0;
-		val = (m_transcheck ? 1 : 0);
-    }
-
-	if (name == "Peaklock") {
-        if (deflt) *deflt = 0;
-		val = (m_peakcheck ? 1 : 0);
-    }
-#ifdef DEBUG_FILTERS
-	std::cerr << "TimeStretchFilter::getPropertyRangeAndValue = " << val << std::endl;
-#endif
-    return val;
-}
-
-QString TimeStretchFilter::getPropertyValueLabel(const PropertyName &name,
-				    int value) const
-{
-    if (name == "Time") {
-		if (value == -100) 
-			return tr("Slow");
-		if (value == 100)
-			return tr("Fast");
-	}
-    return tr("<unknown>");
-}
-
-void TimeStretchFilter::setProperty(const PropertyName &name, int value)
-{
-    if (name == "Time") {
+TimeStretchFilter::PropertyType TimeStretchFilter::getPropertyType(const PropertyName &name) const
+{
+	if (name == "Time") return RangeProperty;
+	if (name == "Pitch") return RangeProperty;
+	if (name == "Bypass") return ToggleProperty;
+	if (name == "Transdetect") return ToggleProperty;
+	if (name == "Peaklock") return ToggleProperty;
+    return InvalidProperty;
+}
+
+int TimeStretchFilter::getPropertyRangeAndValue(const PropertyName &name,
+                                    int *min, int *max, int *deflt) const
+{
+    //!!! factor this colour handling stuff out into a colour manager class
+	int val = 0;
+
+    if (name == "Time") {
+		if (min) *min = -100;
+		if (max) *max = 100;
+		if (deflt) *deflt = 0;
+		if (hopfactor > 1)
+			val = (hopfactor-1)/(m_tmaxfactor-1)*100.0;
+		else if (hopfactor < 1)
+			val = (1/hopfactor - 1)*(1-m_tmaxfactor)*100.0;
+		else if (hopfactor == 1)
+			val = 0;
+	}
+
+	if (name == "Pitch") {
+		if (min) *min = -100;
+		if (max) *max = 100;
+		if (deflt) *deflt = 0;
+		if (m_interpfactor > 1)
+			val = (m_interpfactor-1)/(m_pmaxfactor-1)*100.0;
+		else if (m_interpfactor < 1)
+			val = (1/m_interpfactor - 1)*(1-m_pmaxfactor)*100.0;
+		else if (m_interpfactor == 1)
+			val = 0;
+	}
+
+	if (name == "Bypass") {
+        if (deflt) *deflt = 0;
+		val = (m_bypass ? 1 : 0);
+    }
+
+	if (name == "Transdetect") {
+        if (deflt) *deflt = 0;
+		val = (m_transcheck ? 1 : 0);
+    }
+
+	if (name == "Peaklock") {
+        if (deflt) *deflt = 0;
+		val = (m_peakcheck ? 1 : 0);
+    }
+#ifdef DEBUG_FILTERS
+	std::cerr << "TimeStretchFilter::getPropertyRangeAndValue = " << val << std::endl;
+#endif
+    return val;
+}
+
+QString TimeStretchFilter::getPropertyValueLabel(const PropertyName &name,
+				    int value) const
+{
+    if (name == "Time") {
+		if (value == -100) 
+			return tr("Slow");
+		if (value == 100)
+			return tr("Fast");
+	}
+    return tr("<unknown>");
+}
+
+void TimeStretchFilter::setProperty(const PropertyName &name, int value)
+{
+    if (name == "Time") {
 		if (value > 0){
 			hopfactor=1.0+((m_tmaxfactor-1)*(((float)value)/100.0));
 		}
@@ -228,8 +230,8 @@
 		}
 		if(value == 0){
 			hopfactor=1;
-		}
-	} else if (name == "Pitch") {
+		}
+	} else if (name == "Pitch") {
 		if (value > 0){
 			m_interpfactor=1.0+((m_pmaxfactor-1)*(((float)value)/100.0));
 		}
@@ -238,47 +240,47 @@
 		}
 		if(value == 0){
 			m_interpfactor=1;
-		}
-	} else if (name == "Bypass"){
-		m_bypass = (value > 0) ? true : false;
-	} else if (name == "Transdetect"){
-		m_transcheck = (value > 0) ? true : false;
-	} else if (name == "Peaklock"){
-		m_peakcheck = (value > 0) ? true : false;
-	}
-#ifdef DEBUG_FILTERS
-	std::cerr << "TimeStretchFilter::hopfactor = " << hopfactor << std::endl;
-	std::cerr << "TimeStretchFilter::m_interpfactor = " << m_interpfactor << std::endl;
-	std::cerr << "TimeStretchFilter::m_hop = " << m_hop << std::endl;
-	std::cerr << "TimeStretchFilter::skip = " << getRequiredSkipSamples() << std::endl;
-#endif
-
-}
-
-void TimeStretchFilter::putInput(float **input, size_t samples)
-{	
+		}
+	} else if (name == "Bypass"){
+		m_bypass = (value > 0) ? true : false;
+	} else if (name == "Transdetect"){
+		m_transcheck = (value > 0) ? true : false;
+	} else if (name == "Peaklock"){
+		m_peakcheck = (value > 0) ? true : false;
+	}
+#ifdef DEBUG_FILTERS
+	std::cerr << "TimeStretchFilter::hopfactor = " << hopfactor << std::endl;
+	std::cerr << "TimeStretchFilter::m_interpfactor = " << m_interpfactor << std::endl;
+	std::cerr << "TimeStretchFilter::m_hop = " << m_hop << std::endl;
+	std::cerr << "TimeStretchFilter::skip = " << getRequiredSkipSamples() << std::endl;
+#endif
+
+}
+
+void TimeStretchFilter::putInput(float **input, size_t samples)
+{	
 	int dd;
 	float sampdiff;
 	float difratio;
 	float interpsample;
-
+
 	bool drum = 0;
-	float drumthresh = 65;
-
-	int currentposition = m_hop;
-
-	if ( samples < ( (size_t) floor(m_framesize*(m_interpfactor + 1)) ) )
-		return;
-
-	int channel = getSourceChannelCount();
-
+	float drumthresh = 65;
+
+	int delta = m_hop; //the "current position" is shifted of m_hop
+
+	if ( samples < ( (size_t) floor(m_framesize*(m_interpfactor + 1)) ) )
+		return;
+
+	int channel = getSourceChannelCount();
+
 	for (int i=0; i<samples; i++){
 		if (channel > 1)
 			m_inputBuffer[i] = input[0][i];// + input[1][i]) /2;
 		else
 			m_inputBuffer[i] = input[0][i];
-	}
-	
+	}
+	
 	for (int i = 0; i<m_framesize; i++)
 	{
 			
@@ -291,16 +293,16 @@
 			difratio = (double(i*m_interpfactor)) - floor(double(i*m_interpfactor));
 			
 			// this block loads a frame as normal
-			sampdiff=m_inputBuffer[dd+currentposition+1]-m_inputBuffer[dd+currentposition];
-			interpsample = (difratio*sampdiff)+m_inputBuffer[dd+currentposition];
+			sampdiff=m_inputBuffer[dd+delta+1]-m_inputBuffer[dd+delta];
+			interpsample = (difratio*sampdiff)+m_inputBuffer[dd+delta];
 			audioframe[i] = interpsample*window[i];
 
-			sampdiff=m_inputBuffer[dd+currentposition+1-m_hop]-m_inputBuffer[dd+currentposition-m_hop];
-			interpsample = (difratio*sampdiff)+m_inputBuffer[dd+currentposition-m_hop];
+			sampdiff=m_inputBuffer[dd+delta+1-m_hop]-m_inputBuffer[dd+delta-m_hop];
+			interpsample = (difratio*sampdiff)+m_inputBuffer[dd+delta-m_hop];
 			prev_audioframe[i] = interpsample*window[i];
 		}
 		else {
-			audioframe[i] = m_inputBuffer[i+currentposition+1]*window[i];
+			audioframe[i] = m_inputBuffer[i+delta+1]*window[i];
 			processedframe[i] = audioframe[i]*window[i];
 		}
 	}
@@ -380,41 +382,43 @@
 		if (j < m_framesize*0.75){
 			holdbuffer3[j]=processedframe[j+(m_framesize/4)];
 		}
-	}
-}
-
-void TimeStretchFilter::getOutput(float **output, size_t samples)
-{
-	if (samples > m_framesize/4)
-		return;
-
-	int channel = getSourceChannelCount();
-
-	for (size_t ch = 0; ch < channel; ++ch) 
-	{
-		for (size_t i = 0; i < samples; ++i) {
-			output[ch][i] = outbuffer[i];
-		}
-	}
-}
-
-size_t TimeStretchFilter::getRequiredInputSamples(size_t outputSamplesNeeded)
-{
-	size_t need = (size_t) (floor(m_framesize*(m_interpfactor + 1)));
-	return need;
-}
-
-size_t TimeStretchFilter::getRequiredSkipSamples()
-{
-	size_t skip = 1024;
-
+	}
+}
+
+void TimeStretchFilter::getOutput(float **output, size_t samples)
+{
+	if (samples > m_framesize/4)
+		return;
+
+	int channel = getSourceChannelCount();
+
+	for (size_t ch = 0; ch < channel; ++ch) 
+	{
+		for (size_t i = 0; i < samples; ++i) {
+			output[ch][i] = outbuffer[i];
+		}
+	}
+}
+
+size_t TimeStretchFilter::getRequiredInputSamples(size_t outputSamplesNeeded)
+{
+	size_t need = (size_t) (floor(m_framesize*(m_interpfactor + 1)));
+	return need;
+}
+
+size_t TimeStretchFilter::getRequiredSkipSamples()
+{
+	size_t skip = 1024;
+
 	if (m_bypass == false && m_transhold==0)
 	{
 			skip = floor(m_hop*hopfactor);
+			currentposition += floor(m_hop*hopfactor);
 	}
 	else
 	{		
-			skip = m_hop;
-	}
-	return skip;
+			skip = m_hop;
+			currentposition += m_hop;
+	}
+	return skip;
 }
\ No newline at end of file