comparison src/paranormal/wave.c @ 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 0c5e3d562d99
comparison
equal deleted inserted replaced
193:4b48e6e9b3cb 194:5e8cf0611af3
1 #ifdef HAVE_CONFIG_H 1 #ifdef HAVE_CONFIG_H
2 # include <config.h> 2 # include <config.h>
3 #endif 3 #endif
4
5 #include <math.h>
4 6
5 #include "paranormal.h" 7 #include "paranormal.h"
6 #include "actuators.h" 8 #include "actuators.h"
7 #include "pn_utils.h" 9 #include "pn_utils.h"
8 10
58 { 60 {
59 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1; 61 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1;
60 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival; 62 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival;
61 int *x_pos, *y_pos; /* dynamic tables which store the positions for the line */ 63 int *x_pos, *y_pos; /* dynamic tables which store the positions for the line */
62 int *x2_pos, *y2_pos; /* dynamic tables which store the positions for the line */ 64 int *x2_pos, *y2_pos; /* dynamic tables which store the positions for the line */
63 int i; 65 int i, step;
64 66
65 x_pos = g_new0(int, pn_image_data->width + 1); 67 x_pos = g_new0(int, 257);
66 y_pos = g_new0(int, pn_image_data->width + 1); 68 y_pos = g_new0(int, 257);
67 x2_pos = g_new0(int, pn_image_data->width + 1); 69 x2_pos = g_new0(int, 257);
68 y2_pos = g_new0(int, pn_image_data->width + 1); 70 y2_pos = g_new0(int, 257);
71
72 step = round((gfloat)pn_image_data->width / 256.0);
69 73
70 /* calculate the line. */ 74 /* calculate the line. */
71 for (i = 0; i < pn_image_data->width; i++) 75 for (i = 0; i < 256; i++)
72 { 76 {
73 if (opts[0].val.ival != 0) 77 if (opts[0].val.ival != 0)
74 { 78 {
75 x_pos[i] = i; 79 x_pos[i] = i * step;
76 y_pos[i] = (pn_image_data->height>>1) - 80 y_pos[i] = (pn_image_data->height>>1) -
77 CAP (pn_sound_data->pcm_data[channel][i*512/pn_image_data->width]>>8, 81 CAP (pn_sound_data->pcm_data[channel][i * 2]>>8,
78 (pn_image_data->height>>1)-1); 82 (pn_image_data->height>>1)-1);
79 } 83 }
80 else 84 else
81 { 85 {
82 x_pos[i] = i; 86 x_pos[i] = i * step;
83 y_pos[i] = (pn_image_data->height>>2) - 87 y_pos[i] = (pn_image_data->height>>2) -
84 CAP (pn_sound_data->pcm_data[0][i*512/pn_image_data->width]>>9, 88 CAP (pn_sound_data->pcm_data[0][i * 2]>>9,
85 (pn_image_data->height>>2)-1); 89 (pn_image_data->height>>2)-1);
86 90
87 x2_pos[i] = i; 91 x2_pos[i] = i * step;
88 y2_pos[i] = 3*(pn_image_data->height>>2) - 92 y2_pos[i] = 3*(pn_image_data->height>>2) -
89 CAP (pn_sound_data->pcm_data[1][i*512/pn_image_data->width]>>9, 93 CAP (pn_sound_data->pcm_data[1][i * 2]>>9,
90 (pn_image_data->height>>2)-1); 94 (pn_image_data->height>>2)-1);
91 95
92 } 96 }
93 } 97 }
94 98
95 /* draw the line. */ 99 /* draw the line. */
96 for (i = 1; i < pn_image_data->width; i++) 100 for (i = 1; i < 256; i++)
97 { 101 {
98 pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value); 102 pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value);
99 103
100 if ( opts[0].val.ival == 0 ) 104 if ( opts[0].val.ival == 0 )
101 pn_draw_line(x2_pos[i - 1], y2_pos[i - 1], x2_pos[i], y2_pos[i], value); 105 pn_draw_line(x2_pos[i - 1], y2_pos[i - 1], x2_pos[i], y2_pos[i], value);
174 { 178 {
175 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1; 179 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1;
176 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival; 180 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival;
177 int *x_pos, *y_pos; /* dynamic tables which store the positions for the line */ 181 int *x_pos, *y_pos; /* dynamic tables which store the positions for the line */
178 int *x2_pos, *y2_pos; /* dynamic tables which store the positions for the line */ 182 int *x2_pos, *y2_pos; /* dynamic tables which store the positions for the line */
179 int i; 183 int i, step;
180 184
181 x_pos = g_new0(int, pn_image_data->height + 1); 185 x_pos = g_new0(int, 129);
182 y_pos = g_new0(int, pn_image_data->height + 1); 186 y_pos = g_new0(int, 129);
183 x2_pos = g_new0(int, pn_image_data->height + 1); 187 x2_pos = g_new0(int, 129);
184 y2_pos = g_new0(int, pn_image_data->height + 1); 188 y2_pos = g_new0(int, 129);
189
190 step = round((gfloat)pn_image_data->height / 128.0);
185 191
186 /* calculate the line. */ 192 /* calculate the line. */
187 for (i = 0; i < pn_image_data->height; i++) 193 for (i = 0; i < 128; i++)
188 { 194 {
189 if (opts[0].val.ival != 0) 195 if (opts[0].val.ival != 0)
190 { 196 {
191 x_pos[i] = (pn_image_data->width>>1) - 197 x_pos[i] = (pn_image_data->width>>1) -
192 CAP (pn_sound_data->pcm_data[channel] 198 CAP (pn_sound_data->pcm_data[channel]
193 [i*512/pn_image_data->height]>>8, 199 [i*4]>>8,
194 (pn_image_data->width>>1)-1); 200 (pn_image_data->width>>1)-1);
195 y_pos[i] = i; 201 y_pos[i] = i * step;
196 } 202 }
197 else 203 else
198 { 204 {
199 x_pos[i] = (pn_image_data->width>>2) 205 x_pos[i] = (pn_image_data->width>>2)
200 - CAP (pn_sound_data->pcm_data[0] 206 - CAP (pn_sound_data->pcm_data[0]
201 [i*512/pn_image_data->height]>>9, 207 [i*4]>>9,
202 (pn_image_data->width>>2)-1); 208 (pn_image_data->width>>2)-1);
203 y_pos[i] = i; 209 y_pos[i] = i * step;
204 210
205 x2_pos[i] = 3*(pn_image_data->width>>2) 211 x2_pos[i] = 3*(pn_image_data->width>>2)
206 - CAP (pn_sound_data->pcm_data[1] 212 - CAP (pn_sound_data->pcm_data[1]
207 [i*512/pn_image_data->height]>>9, 213 [i*4]>>9,
208 (pn_image_data->width>>2)-1); 214 (pn_image_data->width>>2)-1);
209 y2_pos[i] = i; 215 y2_pos[i] = i * step;
210 } 216 }
211 } 217 }
212 218
213 /* draw the line. */ 219 /* draw the line. */
214 for (i = 1; i < pn_image_data->width; i++) 220 for (i = 1; i < 128; i++)
215 { 221 {
216 pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value); 222 pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value);
217 223
218 if ( opts[0].val.ival == 0 ) 224 if ( opts[0].val.ival == 0 )
219 pn_draw_line(x2_pos[i - 1], y2_pos[i - 1], x2_pos[i], y2_pos[i], value); 225 pn_draw_line(x2_pos[i - 1], y2_pos[i - 1], x2_pos[i], y2_pos[i], value);