changeset 170:13955c70fbec trunk

[svn] - split out beat detection code into beatdetect.c
author nenolod
date Tue, 31 Oct 2006 23:13:49 -0800
parents c99b74280827
children 9e51ffaca177
files ChangeLog src/paranormal/Makefile src/paranormal/beatdetect.c src/paranormal/containers.c src/paranormal/paranormal.h
diffstat 5 files changed, 29 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Oct 31 22:55:20 2006 -0800
+++ b/ChangeLog	Tue Oct 31 23:13:49 2006 -0800
@@ -1,3 +1,12 @@
+2006-11-01 06:55:20 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [338]
+  - another example preset showing the true power of on-beat branched execution
+  
+  trunk/src/paranormal/presets/Makefile                |    3 
+  trunk/src/paranormal/presets/nenolod_-_beatscope.pnv |   71 +++++++++++++++++++
+  2 files changed, 73 insertions(+), 1 deletion(-)
+
+
 2006-11-01 06:42:55 +0000  William Pitcock <nenolod@nenolod.net>
   revision [336]
   - support lookup of actuator templates by their display name
--- a/src/paranormal/Makefile	Tue Oct 31 22:55:20 2006 -0800
+++ b/src/paranormal/Makefile	Tue Oct 31 23:13:49 2006 -0800
@@ -11,6 +11,7 @@
 
 SOURCES =			\
 	actuators.c		\
+	beatdetect.c		\
 	builtins.c		\
 	cfg.c			\
 	cmaps.c			\
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/paranormal/beatdetect.c	Tue Oct 31 23:13:49 2006 -0800
@@ -0,0 +1,15 @@
+#include "paranormal.h"
+
+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);
+
+  /*
+   * if the energy's quantization is within this, trigger as a detected
+   * beat, otherwise don't.
+   */
+  return (fftsum >= 300 && fftsum <= 600) ? 1 : 0;
+}
--- a/src/paranormal/containers.c	Tue Oct 31 22:55:20 2006 -0800
+++ b/src/paranormal/containers.c	Tue Oct 31 23:13:49 2006 -0800
@@ -175,16 +175,7 @@
 {
   struct container_cycle_data *cdata = (struct container_cycle_data*)data;
   int now;
-
-  /* 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);
-
-  /*
-   * if the energy's quantization is within this, trigger as a detected 
-   * beat.
-   */
-  int new_beat = (fftsum >= 300 && fftsum <= 600) ? 1 : 0;
+  int new_beat = pn_is_new_beat();
 
   /*
    * Change branch if all of the requirements are met for the branch to change.
--- a/src/paranormal/paranormal.h	Tue Oct 31 22:55:20 2006 -0800
+++ b/src/paranormal/paranormal.h	Tue Oct 31 23:13:49 2006 -0800
@@ -50,4 +50,7 @@
 extern float sin_val[360];
 extern float cos_val[360];
 
+/* beat detection */
+int pn_is_new_beat(void);
+
 #endif /* _PARANORMAL_H */