changeset 194:5e8cf0611af3 trunk

[svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform) - update rush preset (DON'T use lines here.)
author nenolod
date Fri, 03 Nov 2006 03:10:26 -0800
parents 4b48e6e9b3cb
children 2aca8ce28871
files ChangeLog src/paranormal/presets/nenolod_-_rush.pnv src/paranormal/wave.c
diffstat 3 files changed, 46 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Nov 03 02:54:12 2006 -0800
+++ b/ChangeLog	Fri Nov 03 03:10:26 2006 -0800
@@ -1,3 +1,13 @@
+2006-11-03 10:54:12 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [386]
+  - rewrite line drawing algorithm for speed
+  - use lines instead of dots by default in horizontal and vertical waveforms
+  
+  trunk/src/paranormal/drawing.c |   68 ++++----------------
+  trunk/src/paranormal/wave.c    |  138 ++++++++++++++++++++++++++++++++++++++++-
+  2 files changed, 151 insertions(+), 55 deletions(-)
+
+
 2006-11-03 06:19:05 +0000  William Pitcock <nenolod@nenolod.net>
   revision [384]
   - add fast linedrawing code
--- a/src/paranormal/presets/nenolod_-_rush.pnv	Fri Nov 03 02:54:12 2006 -0800
+++ b/src/paranormal/presets/nenolod_-_rush.pnv	Fri Nov 03 03:10:26 2006 -0800
@@ -12,9 +12,13 @@
   </container_once>
   <wave_horizontal>
    <channels> -1 </channels>
+   <value> 255 </value>
+   <lines> FALSE </lines>
   </wave_horizontal>
   <wave_vertical>
    <channels> -1 </channels>
+   <value> 255 </value>
+   <lines> FALSE </lines>
   </wave_vertical>
   <container_cycle>
    <change_interval> 0 </change_interval>
--- a/src/paranormal/wave.c	Fri Nov 03 02:54:12 2006 -0800
+++ b/src/paranormal/wave.c	Fri Nov 03 03:10:26 2006 -0800
@@ -2,6 +2,8 @@
 # include <config.h>
 #endif
 
+#include <math.h>
+
 #include "paranormal.h"
 #include "actuators.h"
 #include "pn_utils.h"
@@ -60,40 +62,42 @@
   guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival;
   int *x_pos, *y_pos;	/* dynamic tables which store the positions for the line */
   int *x2_pos, *y2_pos;	/* dynamic tables which store the positions for the line */
-  int i;
+  int i, step;
 
-  x_pos = g_new0(int, pn_image_data->width + 1);
-  y_pos = g_new0(int, pn_image_data->width + 1);
-  x2_pos = g_new0(int, pn_image_data->width + 1);
-  y2_pos = g_new0(int, pn_image_data->width + 1);
+  x_pos = g_new0(int, 257);
+  y_pos = g_new0(int, 257);
+  x2_pos = g_new0(int, 257);
+  y2_pos = g_new0(int, 257);
+
+  step = round((gfloat)pn_image_data->width / 256.0);
 
   /* calculate the line. */
-  for (i = 0; i < pn_image_data->width; i++)
+  for (i = 0; i < 256; i++)
     {
       if (opts[0].val.ival != 0)
         {
-           x_pos[i] = i;
+           x_pos[i] = i * step;
            y_pos[i] = (pn_image_data->height>>1) - 
-			CAP (pn_sound_data->pcm_data[channel][i*512/pn_image_data->width]>>8, 
+			CAP (pn_sound_data->pcm_data[channel][i * 2]>>8, 
 			(pn_image_data->height>>1)-1);
         }
       else
         {
-           x_pos[i] = i;
+           x_pos[i] = i * step;
            y_pos[i] = (pn_image_data->height>>2) - 
-			CAP (pn_sound_data->pcm_data[0][i*512/pn_image_data->width]>>9,
+			CAP (pn_sound_data->pcm_data[0][i * 2]>>9,
 			(pn_image_data->height>>2)-1);
 
-           x2_pos[i] = i;
+           x2_pos[i] = i * step;
            y2_pos[i] = 3*(pn_image_data->height>>2) - 
-			CAP (pn_sound_data->pcm_data[1][i*512/pn_image_data->width]>>9,
+			CAP (pn_sound_data->pcm_data[1][i * 2]>>9,
 			(pn_image_data->height>>2)-1);
 
         }
     }
 
   /* draw the line. */
-  for (i = 1; i < pn_image_data->width; i++)
+  for (i = 1; i < 256; i++)
     {
        pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value);
 
@@ -176,42 +180,44 @@
   guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival;
   int *x_pos, *y_pos;	/* dynamic tables which store the positions for the line */
   int *x2_pos, *y2_pos;	/* dynamic tables which store the positions for the line */
-  int i;
+  int i, step;
 
-  x_pos = g_new0(int, pn_image_data->height + 1);
-  y_pos = g_new0(int, pn_image_data->height + 1);
-  x2_pos = g_new0(int, pn_image_data->height + 1);
-  y2_pos = g_new0(int, pn_image_data->height + 1);
+  x_pos = g_new0(int, 129);
+  y_pos = g_new0(int, 129);
+  x2_pos = g_new0(int, 129);
+  y2_pos = g_new0(int, 129);
+
+  step = round((gfloat)pn_image_data->height / 128.0);
 
   /* calculate the line. */
-  for (i = 0; i < pn_image_data->height; i++)
+  for (i = 0; i < 128; i++)
     {
       if (opts[0].val.ival != 0)
         {
            x_pos[i] = (pn_image_data->width>>1) - 
 			CAP (pn_sound_data->pcm_data[channel]
-			[i*512/pn_image_data->height]>>8,
+			[i*4]>>8,
 			(pn_image_data->width>>1)-1);
-	   y_pos[i] = i;
+	   y_pos[i] = i * step;
         }
       else
         {
            x_pos[i] = (pn_image_data->width>>2) 
 		      - CAP (pn_sound_data->pcm_data[0]
-		     [i*512/pn_image_data->height]>>9,
+		     [i*4]>>9,
 		     (pn_image_data->width>>2)-1);
-           y_pos[i] = i;
+           y_pos[i] = i * step;
 
            x2_pos[i] = 3*(pn_image_data->width>>2) 
 		      - CAP (pn_sound_data->pcm_data[1]
-		     [i*512/pn_image_data->height]>>9,
+		     [i*4]>>9,
 		     (pn_image_data->width>>2)-1);
-           y2_pos[i] = i;
+           y2_pos[i] = i * step;
         }
     }
 
   /* draw the line. */
-  for (i = 1; i < pn_image_data->width; i++)
+  for (i = 1; i < 128; i++)
     {
        pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value);