marlin r1322 - trunk/marlin



Author: iain
Date: Tue Oct 21 23:50:18 2008
New Revision: 1322
URL: http://svn.gnome.org/viewvc/marlin?rev=1322&view=rev

Log:
Allow a tolerance in finding Zero crossings


Modified:
   trunk/marlin/ChangeLog
   trunk/marlin/marlin-channel.c
   trunk/marlin/marlin-sample.c

Modified: trunk/marlin/marlin-channel.c
==============================================================================
--- trunk/marlin/marlin-channel.c	(original)
+++ trunk/marlin/marlin-channel.c	Tue Oct 21 23:50:18 2008
@@ -1844,9 +1844,9 @@
 	return (channel->first != NULL);
 }
 
-/* FIXME: I'm not sure that marlin_channel_next_zero and 
-   marlin_channel_previous_zero actually work correctly. But I'm not sure
-   how they're supposed to. */
+/* For a zero crossing a zero is between -0.009 and 0.009 */
+#define ZERO_TOLERANCE 0.009
+
 /**
  * marlin_channel_next_zero:
  * @channel: The channel.
@@ -1883,7 +1883,8 @@
 
 		/* Work forward to end of block */
 		while (pos_in_block <= block->end) {
-			if (data[pos_in_block] == 0.0f) {
+			if (data[pos_in_block] <= ZERO_TOLERANCE &&
+			    data[pos_in_block] >= -ZERO_TOLERANCE) {
 				READ_UNLOCK (block->lock);
 				READ_UNLOCK (channel->lock);
 				return position;
@@ -1947,9 +1948,11 @@
 
 		/* Work back to start of block */
 		while (pos_in_block >= 0) {
-			if (data[pos_in_block] == 0.0f) {
+			if (data[pos_in_block] <= ZERO_TOLERANCE &&
+			    data[pos_in_block] >= -ZERO_TOLERANCE) {
 				READ_UNLOCK (block->lock);
 				READ_UNLOCK (channel->lock);
+
 				return position;
 			}
 
@@ -1976,6 +1979,8 @@
 
 	/* If we're here, we didn't find a 0 */
 	READ_UNLOCK (channel->lock);
+
+	g_print ("Did not find 0\n");
 	return orig;
 }
 
@@ -2001,16 +2006,16 @@
 	guint64 frames_needed, insert_point;
 	float *buf;
 	gboolean ret;
-	
+
 	frames_needed = (finish - start) + 1;
-	
+
 	buf = g_new (float, MARLIN_BLOCK_SIZE);
-	
+
 	WRITE_LOCK (channel->lock);
-	
+
 	lockless_unlink_range (channel, start, finish, &block, ctxt);
 	b = block;
-	
+
 	insert_point = start;
 
 	/* We get a block size, reverse it and insert it before all the other

Modified: trunk/marlin/marlin-sample.c
==============================================================================
--- trunk/marlin/marlin-sample.c	(original)
+++ trunk/marlin/marlin-sample.c	Tue Oct 21 23:50:18 2008
@@ -2486,9 +2486,11 @@
 			new_pos = marlin_channel_previous_zero (priv->channel_data->pdata[i],
 								position);
 			if (new_pos != position) {
-				pos = MAX (new_pos, pos);
+				pos = MIN (new_pos, pos);
 			}
 		}
+
+		g_print ("Found zero at: %llu\n", pos);
 		break;
 
 	case MARLIN_COVERAGE_LEFT:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]