changeset 281:65c4d8591b4a trunk

[svn] - pinch xvs's beat detection algorithm.
author nenolod
date Mon, 20 Nov 2006 13:06:08 -0800
parents 3b5878a7c62f
children 3e160f6c04d2
files ChangeLog src/paranormal/beatdetect.c
diffstat 2 files changed, 31 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Nov 20 09:06:45 2006 -0800
+++ b/ChangeLog	Mon Nov 20 13:06:08 2006 -0800
@@ -1,3 +1,11 @@
+2006-11-20 17:06:45 +0000  Derek Pomery <nemo@m8y.org>
+  revision [594]
+  typo
+  
+  trunk/m4/libFLAC.m4 |    2 +-
+  1 file changed, 1 insertion(+), 1 deletion(-)
+
+
 2006-11-20 06:54:10 +0000  Yoshiki Yazawa <yaz@cc.rim.or.jp>
   revision [586]
   build fixes:
--- a/src/paranormal/beatdetect.c	Mon Nov 20 09:06:45 2006 -0800
+++ b/src/paranormal/beatdetect.c	Mon Nov 20 13:06:08 2006 -0800
@@ -1,15 +1,30 @@
 #include "paranormal.h"
 
+/*
+ * This algorithm is by Janusz Gregorcyzk, the implementation is
+ * mine, however.
+ *
+ *   -- nenolod
+ */
 int
 pn_is_new_beat(void)
 {
-  /* quantize the average energy of the pcm_data for beat detection. */
-  int fftsum =
-    ((pn_sound_data->pcm_data[0][0] + pn_sound_data->pcm_data[1][0]) >> 6);
+  gint i;
+  gint total = 0;
+  gboolean ret = FALSE;
+  static gint previous;
 
-  /*
-   * if the energy's quantization is within this, trigger as a detected
-   * beat, otherwise don't.
-   */
-  return (fftsum >= 300 && fftsum <= 600) ? 1 : 0;
+  for (i = 1; i < 512; i++)
+    {
+       total += abs (pn_sound_data->pcm_data[0][i] -
+		     pn_sound_data->pcm_data[0][i - 1]);
+    }
+
+  total /= 512;
+
+  ret = (total > (2 * previous));
+
+  previous = total;
+
+  return ret;
 }