From 9292fd38c0fca27cb62f80c0b55417cc28206ce2 Mon Sep 17 00:00:00 2001
From: Aaron Viets <aaron.viets@ligo.org>
Date: Thu, 24 May 2018 15:17:56 -0700
Subject: [PATCH] lal_smoothkappas:  Fixed buffer sizing bug.

---
 .../gst/lal/gstlal_smoothkappas.c             | 40 ++++++++-----------
 .../python/calibration_parts.py               |  1 +
 2 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/gstlal-calibration/gst/lal/gstlal_smoothkappas.c b/gstlal-calibration/gst/lal/gstlal_smoothkappas.c
index 00da74c95e..395aaf791c 100644
--- a/gstlal-calibration/gst/lal/gstlal_smoothkappas.c
+++ b/gstlal-calibration/gst/lal/gstlal_smoothkappas.c
@@ -477,24 +477,25 @@ static gboolean transform_size(GstBaseTransform *trans, GstPadDirection directio
 	GSTLALSmoothKappas *element = GSTLAL_SMOOTHKAPPAS(trans);
 
 	gsize unit_size;
+	if(!get_unit_size(trans, caps, &unit_size)) {
+		GST_DEBUG_OBJECT(element, "function 'get_unit_size' failed");
+		return FALSE;
+	}
+
+	/* buffer size in bytes should be a multiple of unit_size in bytes */
+	if(G_UNLIKELY(size % unit_size)) {
+		GST_DEBUG_OBJECT(element, "buffer size %" G_GSIZE_FORMAT " is not a multiple of %" G_GSIZE_FORMAT, size, unit_size);
+		return FALSE;
+	}
+
+	size /= unit_size;
 
 	/* How many samples do we need to throw away based on the filter latency? */
 	int waste_samples = (int) (element->filter_latency * (element->array_size + element->avg_array_size - 2));
 
 	switch(direction) {
 	case GST_PAD_SRC:
-		/*We have the size of the output buffer, and we set the size of the input buffer. */
-		if(!get_unit_size(trans, caps, &unit_size)) {
-			GST_DEBUG_OBJECT(element, "function 'get_unit_size' failed");
-			return FALSE;
-		}
-
-		/* buffer size in bytes should be a multiple of unit_size in bytes */
-		if(G_UNLIKELY(size % unit_size)) {
-			GST_DEBUG_OBJECT(element, "buffer size %" G_GSIZE_FORMAT " is not a multiple of %" G_GSIZE_FORMAT, size, unit_size);
-			return FALSE;
-		}
-
+		/* We have the size of the output buffer, and we set the size of the input buffer. */
 		/* Check if we need to clip the output buffer */
 		if(element->samples_in_filter >= waste_samples)
 			*othersize = size;
@@ -505,21 +506,10 @@ static gboolean transform_size(GstBaseTransform *trans, GstPadDirection directio
 
 	case GST_PAD_SINK:
 		/* We have the size of the input buffer, and we set the size of the output buffer. */
-		if(!get_unit_size(trans, caps, &unit_size)) {
-			GST_DEBUG_OBJECT(element, "function 'get_unit_size' failed");
-			return FALSE;
-		}
-
-		/* buffer size in bytes should be a multiple of unit_size in bytes */
-		if(G_UNLIKELY(size % unit_size)) {
-			GST_DEBUG_OBJECT(element, "buffer size %" G_GSIZE_FORMAT " is not a multiple of %" G_GSIZE_FORMAT, size, unit_size);
-			return FALSE;
-		}
-
 		/* Check if we need to clip the output buffer */
 		if(element->samples_in_filter >= waste_samples)
 			*othersize = size;
-		else if(size > (guint) (waste_samples + element->samples_in_filter))
+		else if(size > (guint) (waste_samples - element->samples_in_filter))
 			*othersize = size - waste_samples + element->samples_in_filter;
 		else
 			*othersize = 0;
@@ -531,6 +521,8 @@ static gboolean transform_size(GstBaseTransform *trans, GstPadDirection directio
 		return FALSE;
 	}
 
+	*othersize *= unit_size;
+
 	return TRUE;
 }
 
diff --git a/gstlal-calibration/python/calibration_parts.py b/gstlal-calibration/python/calibration_parts.py
index c7eb15b1b2..ecafc8b3cc 100644
--- a/gstlal-calibration/python/calibration_parts.py
+++ b/gstlal-calibration/python/calibration_parts.py
@@ -201,6 +201,7 @@ def remove_harmonics_with_witness(pipeline, signal, witness, f0, num_harmonics,
 	upsample_quality = 4
 	resample_shift = 16.0 + 16.5
 	zero_latency = filter_latency == 0.0
+	filter_latency = min(0.5, filter_latency)
 
 	witness = pipeparts.mktee(pipeline, witness)
 	signal = pipeparts.mktee(pipeline, signal)
-- 
GitLab