annotate src/paranormal/wave.c @ 1833:15e7d3473974

paranormal: MK2
author William Pitcock <nenolod@atheme.org>
date Mon, 24 Sep 2007 13:57:28 -0500
parents 3d0b7ca9c8eb
children 3b034150d31e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
1 #ifdef HAVE_CONFIG_H
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
2 # include <config.h>
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
3 #endif
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
4
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
5 #include <math.h>
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
6
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
7 #include "paranormal.h"
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
8 #include "actuators.h"
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
9 #include "pn_utils.h"
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
10
203
0c5e3d562d99 [svn] - include drawing.h
nenolod
parents: 194
diff changeset
11 #include "drawing.h"
0c5e3d562d99 [svn] - include drawing.h
nenolod
parents: 194
diff changeset
12
283
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
13 #include "libcalc/calc.h"
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
14
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
15 /* **************** wave_horizontal **************** */
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
16 struct pn_actuator_option_desc wave_horizontal_opts[] =
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
17 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
18 {"channels", "Which sound channels to use: negative = channel 1, \npositive = channel 2, "
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
19 "zero = both (two wave-forms.)", OPT_TYPE_INT, {ival: -1} },
183
37b53a5a9aa4 [svn] - allow waves to be drawn with a custom value instead of just 255
nenolod
parents: 155
diff changeset
20 {"value", "The colour value to use.", OPT_TYPE_INT, {ival: 255} },
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
21 {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} },
188
0d826917c56f [svn] - 64-bit safety (pass 1 of 2)
nenolod
parents: 183
diff changeset
22 { NULL }
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
23 };
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
24
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
25 static void
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
26 wave_horizontal_exec_dots (const struct pn_actuator_option *opts,
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
27 gpointer data)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
28 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
29 int i;
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
30 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1;
183
37b53a5a9aa4 [svn] - allow waves to be drawn with a custom value instead of just 255
nenolod
parents: 155
diff changeset
31 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival;
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
32
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
33 for (i=0; i<pn_image_data->width; i++) {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
34
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
35 /*single channel, centered horz.*/
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
36 if ( opts[0].val.ival ) {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
37 pn_image_data->surface[0][PN_IMG_INDEX (i, (pn_image_data->height>>1)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
38 - CAP (pn_sound_data->pcm_data[channel]
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
39 [i*512/pn_image_data->width]>>8,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
40 (pn_image_data->height>>1)-1))]
183
37b53a5a9aa4 [svn] - allow waves to be drawn with a custom value instead of just 255
nenolod
parents: 155
diff changeset
41 = value;
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
42 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
43
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
44 /*both channels, at 1/4 and 3/4 of the screen*/
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
45 else {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
46 pn_image_data->surface[0][PN_IMG_INDEX( i, (pn_image_data->height>>2) -
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
47 CAP( (pn_sound_data->pcm_data[0]
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
48 [i*512/pn_image_data->width]>>9),
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
49 (pn_image_data->height>>2)-1))]
183
37b53a5a9aa4 [svn] - allow waves to be drawn with a custom value instead of just 255
nenolod
parents: 155
diff changeset
50 = value;
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
51
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
52 pn_image_data->surface[0][PN_IMG_INDEX( i, 3*(pn_image_data->height>>2) -
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
53 CAP( (pn_sound_data->pcm_data[1]
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
54 [i*512/pn_image_data->width]>>9),
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
55 (pn_image_data->height>>2)-1))]
183
37b53a5a9aa4 [svn] - allow waves to be drawn with a custom value instead of just 255
nenolod
parents: 155
diff changeset
56 = value;
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
57 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
58 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
59 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
60
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
61 void
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
62 wave_horizontal_exec_lines (const struct pn_actuator_option *opts,
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
63 gpointer data)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
64 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
65 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1;
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
66 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival;
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
67 int *x_pos, *y_pos; /* dynamic tables which store the positions for the line */
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
68 int *x2_pos, *y2_pos; /* dynamic tables which store the positions for the line */
269
69f309c8bd71 [svn] - properly calculate points
nenolod
parents: 238
diff changeset
69 int i;
69f309c8bd71 [svn] - properly calculate points
nenolod
parents: 238
diff changeset
70 float step;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
71
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
72 x_pos = g_new0(int, 257);
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
73 y_pos = g_new0(int, 257);
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
74 x2_pos = g_new0(int, 257);
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
75 y2_pos = g_new0(int, 257);
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
76
269
69f309c8bd71 [svn] - properly calculate points
nenolod
parents: 238
diff changeset
77 step = pn_image_data->width / 256.;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
78
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
79 /* calculate the line. */
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
80 for (i = 0; i < 256; i++)
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
81 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
82 if (opts[0].val.ival != 0)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
83 {
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
84 x_pos[i] = i * step;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
85 y_pos[i] = (pn_image_data->height>>1) -
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
86 CAP (pn_sound_data->pcm_data[channel][i * 2]>>8,
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
87 (pn_image_data->height>>1)-1);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
88 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
89 else
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
90 {
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
91 x_pos[i] = i * step;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
92 y_pos[i] = (pn_image_data->height>>2) -
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
93 CAP (pn_sound_data->pcm_data[0][i * 2]>>9,
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
94 (pn_image_data->height>>2)-1);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
95
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
96 x2_pos[i] = i * step;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
97 y2_pos[i] = 3*(pn_image_data->height>>2) -
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
98 CAP (pn_sound_data->pcm_data[1][i * 2]>>9,
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
99 (pn_image_data->height>>2)-1);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
100
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
101 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
102 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
103
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
104 /* draw the line. */
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
105 for (i = 1; i < 256; i++)
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
106 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
107 pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
108
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
109 if ( opts[0].val.ival == 0 )
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
110 pn_draw_line(x2_pos[i - 1], y2_pos[i - 1], x2_pos[i], y2_pos[i], value);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
111 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
112
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
113 g_free(x_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
114 g_free(y_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
115 g_free(x2_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
116 g_free(y2_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
117 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
118
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
119 static void
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
120 wave_horizontal_exec (const struct pn_actuator_option *opts,
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
121 gpointer data)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
122 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
123 if (opts[2].val.bval == TRUE)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
124 wave_horizontal_exec_lines(opts, data);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
125 else
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
126 wave_horizontal_exec_dots(opts, data);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
127 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
128
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
129 struct pn_actuator_desc builtin_wave_horizontal =
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
130 {
155
adf9f4b26039 [svn] - user-friendly names (UI side unimplemented still)
nenolod
parents: 149
diff changeset
131 "wave_horizontal", "Horizontal Waveform",
adf9f4b26039 [svn] - user-friendly names (UI side unimplemented still)
nenolod
parents: 149
diff changeset
132 "Draws one or two waveforms horizontally across "
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
133 "the drawing surface",
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
134 0, wave_horizontal_opts,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
135 NULL, NULL, wave_horizontal_exec
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
136 };
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
137
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
138 /* **************** wave_vertical **************** */
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
139 struct pn_actuator_option_desc wave_vertical_opts[] =
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
140 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
141 {"channels", "Which sound channels to use: negative = channel 1, \npositive = channel 2, "
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
142 "zero = both (two wave-forms.)", OPT_TYPE_INT, {ival: -1} },
183
37b53a5a9aa4 [svn] - allow waves to be drawn with a custom value instead of just 255
nenolod
parents: 155
diff changeset
143 {"value", "The colour value to use.", OPT_TYPE_INT, {ival: 255} },
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
144 {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} },
188
0d826917c56f [svn] - 64-bit safety (pass 1 of 2)
nenolod
parents: 183
diff changeset
145 { NULL }
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
146 };
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
147
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
148 static void
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
149 wave_vertical_exec_dots (const struct pn_actuator_option *opts,
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
150 gpointer data)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
151 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
152 int i;
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
153 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1;
183
37b53a5a9aa4 [svn] - allow waves to be drawn with a custom value instead of just 255
nenolod
parents: 155
diff changeset
154 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival;
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
155
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
156 for (i=0; i<pn_image_data->height; i++) {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
157 if ( opts[0].val.ival ) {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
158 pn_image_data->surface[0][PN_IMG_INDEX ((pn_image_data->width>>1)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
159 - CAP (pn_sound_data->pcm_data[channel]
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
160 [i*512/pn_image_data->height]>>8,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
161 (pn_image_data->width>>1)-1), i)]
183
37b53a5a9aa4 [svn] - allow waves to be drawn with a custom value instead of just 255
nenolod
parents: 155
diff changeset
162 = value;
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
163 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
164 else {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
165 pn_image_data->surface[0][PN_IMG_INDEX ((pn_image_data->width>>2)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
166 - CAP (pn_sound_data->pcm_data[0]
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
167 [i*512/pn_image_data->height]>>9,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
168 (pn_image_data->width>>2)-1), i)]
183
37b53a5a9aa4 [svn] - allow waves to be drawn with a custom value instead of just 255
nenolod
parents: 155
diff changeset
169 = value;
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
170 pn_image_data->surface[0][PN_IMG_INDEX ((3*pn_image_data->width>>2)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
171 -CAP (pn_sound_data->pcm_data[1]
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
172 [i*512/pn_image_data->height]>>9,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
173 (pn_image_data->width>>2)-1), i)]
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
174
183
37b53a5a9aa4 [svn] - allow waves to be drawn with a custom value instead of just 255
nenolod
parents: 155
diff changeset
175 = value;
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
176 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
177 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
178 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
179
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
180 static void
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
181 wave_vertical_exec_lines (const struct pn_actuator_option *opts,
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
182 gpointer data)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
183 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
184 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1;
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
185 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival;
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
186 int *x_pos, *y_pos; /* dynamic tables which store the positions for the line */
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
187 int *x2_pos, *y2_pos; /* dynamic tables which store the positions for the line */
269
69f309c8bd71 [svn] - properly calculate points
nenolod
parents: 238
diff changeset
188 int i;
69f309c8bd71 [svn] - properly calculate points
nenolod
parents: 238
diff changeset
189 float step;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
190
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
191 x_pos = g_new0(int, 129);
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
192 y_pos = g_new0(int, 129);
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
193 x2_pos = g_new0(int, 129);
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
194 y2_pos = g_new0(int, 129);
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
195
269
69f309c8bd71 [svn] - properly calculate points
nenolod
parents: 238
diff changeset
196 step = pn_image_data->height / 128.;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
197
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
198 /* calculate the line. */
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
199 for (i = 0; i < 128; i++)
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
200 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
201 if (opts[0].val.ival != 0)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
202 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
203 x_pos[i] = (pn_image_data->width>>1) -
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
204 CAP (pn_sound_data->pcm_data[channel]
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
205 [i*4]>>8,
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
206 (pn_image_data->width>>1)-1);
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
207 y_pos[i] = i * step;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
208 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
209 else
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
210 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
211 x_pos[i] = (pn_image_data->width>>2)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
212 - CAP (pn_sound_data->pcm_data[0]
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
213 [i*4]>>9,
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
214 (pn_image_data->width>>2)-1);
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
215 y_pos[i] = i * step;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
216
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
217 x2_pos[i] = 3*(pn_image_data->width>>2)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
218 - CAP (pn_sound_data->pcm_data[1]
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
219 [i*4]>>9,
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
220 (pn_image_data->width>>2)-1);
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
221 y2_pos[i] = i * step;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
222 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
223 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
224
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
225 /* draw the line. */
194
5e8cf0611af3 [svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents: 193
diff changeset
226 for (i = 1; i < 128; i++)
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
227 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
228 pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
229
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
230 if ( opts[0].val.ival == 0 )
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
231 pn_draw_line(x2_pos[i - 1], y2_pos[i - 1], x2_pos[i], y2_pos[i], value);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
232 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
233
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
234 g_free(x_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
235 g_free(y_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
236 g_free(x2_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
237 g_free(y2_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
238 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
239
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
240 static void
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
241 wave_vertical_exec (const struct pn_actuator_option *opts,
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
242 gpointer data)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
243 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
244 if (opts[2].val.bval == TRUE)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
245 wave_vertical_exec_lines(opts, data);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
246 else
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
247 wave_vertical_exec_dots(opts, data);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
248 }
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
249
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
250 struct pn_actuator_desc builtin_wave_vertical =
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
251 {
155
adf9f4b26039 [svn] - user-friendly names (UI side unimplemented still)
nenolod
parents: 149
diff changeset
252 "wave_vertical", "Vertical Waveform",
adf9f4b26039 [svn] - user-friendly names (UI side unimplemented still)
nenolod
parents: 149
diff changeset
253 "Draws one or two waveforms vertically across "
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
254 "the drawing surface",
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
255 0, wave_vertical_opts,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
256 NULL, NULL, wave_vertical_exec
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
257 };
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
258
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
259 /* FIXME: allow for only 1 channel for wave_normalize & wave_smooth */
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
260 /* **************** wave_normalize **************** */
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
261 static struct pn_actuator_option_desc wave_normalize_opts[] =
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
262 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
263 { "height", "If positive, the height, in pixels, to which the waveform will be "
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
264 "normalized; if negative, hfrac is used", OPT_TYPE_INT, { ival: -1 } },
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
265 { "hfrac", "If positive, the fraction of the horizontal image size to which the "
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
266 "waveform will be normalized; if negative, vfrac is used",
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
267 OPT_TYPE_FLOAT, { fval: -1 } },
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
268 { "vfrac", "If positive, the fraction of the vertical image size to which the "
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
269 "waveform will be normalized",
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
270 OPT_TYPE_FLOAT, { fval: .125 } },
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
271 { "channels", "Which sound channel(s) to normalize: negative = channel 1,\n"
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
272 "\tpositive = channel 2, 0 = both channels.",
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
273 OPT_TYPE_INT, { ival: 0 } },
188
0d826917c56f [svn] - 64-bit safety (pass 1 of 2)
nenolod
parents: 183
diff changeset
274 { NULL }
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
275 };
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
276
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
277 static void
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
278 wave_normalize_exec (const struct pn_actuator_option *opts,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
279 gpointer data)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
280 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
281 int i, j, max=0;
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
282 float denom;
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
283
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
284 for (j=0; j<2; j++)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
285 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
286 if ( !(opts[3].val.ival) || (opts[3].val.ival < 0 && j == 0) ||
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
287 (opts[3].val.ival > 0 && j == 1) ) {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
288
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
289 for (i=0; i<512; i++)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
290 if (abs(pn_sound_data->pcm_data[j][i]) > max)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
291 max = abs(pn_sound_data->pcm_data[j][i]);
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
292
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
293 if (opts[0].val.ival > 0)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
294 denom = max/(opts[0].val.ival<<8);
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
295 else if (opts[1].val.fval > 0)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
296 denom = max/(opts[1].val.fval * (pn_image_data->width<<8));
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
297 else
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
298 denom = max/(opts[2].val.fval * (pn_image_data->height<<8));
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
299
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
300 if (denom > 0)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
301 for (i=0; i<512; i++)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
302 pn_sound_data->pcm_data[j][i]
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
303 /= denom;
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
304 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
305 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
306 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
307
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
308 struct pn_actuator_desc builtin_wave_normalize =
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
309 {
155
adf9f4b26039 [svn] - user-friendly names (UI side unimplemented still)
nenolod
parents: 149
diff changeset
310 "wave_normalize", "Normalize Waveform Data",
adf9f4b26039 [svn] - user-friendly names (UI side unimplemented still)
nenolod
parents: 149
diff changeset
311 "Normalizes the waveform data used by the wave_* actuators",
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
312 0, wave_normalize_opts,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
313 NULL, NULL, wave_normalize_exec
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
314 };
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
315
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
316 /* **************** wave_smooth **************** */
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
317 struct pn_actuator_option_desc wave_smooth_opts[] =
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
318 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
319 { "channels", "Which sound channel(s) to smooth: negative = channel 1, \n"
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
320 "\tpositive = channel 2, 0 = both channels.",
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
321 OPT_TYPE_INT, { ival: 0 } },
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
322 {0}
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
323 };
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
324
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
325 static void
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
326 wave_smooth_exec (const struct pn_actuator_option *opts,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
327 gpointer data)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
328 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
329 int i, j, k;
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
330 gint16 tmp[512];
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
331
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
332 for (j=0; j<2; j++)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
333 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
334 if ( !(opts[0].val.ival) || (opts[0].val.ival < 0 && j == 0) ||
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
335 (opts[0].val.ival > 0 && j == 1) ) {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
336
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
337 for (i=4; i<508; i++)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
338 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
339 k = (pn_sound_data->pcm_data[j][i]<<3)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
340 + (pn_sound_data->pcm_data[j][i+1]<<2)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
341 + (pn_sound_data->pcm_data[j][i-1]<<2)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
342 + (pn_sound_data->pcm_data[j][i+2]<<2)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
343 + (pn_sound_data->pcm_data[j][i-2]<<2)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
344 + (pn_sound_data->pcm_data[j][i+3]<<1)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
345 + (pn_sound_data->pcm_data[j][i-3]<<1)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
346 + (pn_sound_data->pcm_data[j][i+4]<<1)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
347 + (pn_sound_data->pcm_data[j][i-4]<<1);
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
348 tmp[i] = k >> 5;
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
349 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
350 memcpy (pn_sound_data->pcm_data[j]+4, tmp, sizeof (gint16) * 504);
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
351 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
352 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
353 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
354
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
355 struct pn_actuator_desc builtin_wave_smooth =
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
356 {
155
adf9f4b26039 [svn] - user-friendly names (UI side unimplemented still)
nenolod
parents: 149
diff changeset
357 "wave_smooth", "Smooth Waveform Data",
adf9f4b26039 [svn] - user-friendly names (UI side unimplemented still)
nenolod
parents: 149
diff changeset
358 "Smooth out the waveform data used by the wave_* actuators",
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
359 0, wave_smooth_opts,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
360 NULL, NULL, wave_smooth_exec
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
361 };
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
362
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
363 /* **************** wave_radial **************** */
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
364 static struct pn_actuator_option_desc wave_radial_opts[] =
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
365 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
366 { "base_radius", " ",
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
367 OPT_TYPE_FLOAT, { fval: 0 } },
183
37b53a5a9aa4 [svn] - allow waves to be drawn with a custom value instead of just 255
nenolod
parents: 155
diff changeset
368 {"value", "The colour value to use.", OPT_TYPE_INT, {ival: 255} },
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
369 /* {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} }, */
188
0d826917c56f [svn] - 64-bit safety (pass 1 of 2)
nenolod
parents: 183
diff changeset
370 { NULL }
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
371 };
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
372
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
373 static void
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
374 wave_radial_exec (const struct pn_actuator_option *opts,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
375 gpointer data)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
376 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
377 int i, x, y;
183
37b53a5a9aa4 [svn] - allow waves to be drawn with a custom value instead of just 255
nenolod
parents: 155
diff changeset
378 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival;
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
379
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
380 for(i=0; i<360; i++)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
381 {
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
382 x = (pn_image_data->width>>1)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
383 + (opts[0].val.fval + (pn_sound_data->pcm_data[0][(int)(i*(512.0/360.0))]>>8))
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
384 * cos_val[i];
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
385 y = (pn_image_data->height>>1)
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
386 + (opts[0].val.fval + (pn_sound_data->pcm_data[0][(int)(i*(512.0/360.0))]>>8))
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
387 * sin_val[i];
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
388
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
389 pn_image_data->surface[0][PN_IMG_INDEX (CAPHILO(x,pn_image_data->width,0),
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
390 CAPHILO(y,pn_image_data->height,0))]
183
37b53a5a9aa4 [svn] - allow waves to be drawn with a custom value instead of just 255
nenolod
parents: 155
diff changeset
391 = value;
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
392 }
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
393 };
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
394
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
395 struct pn_actuator_desc builtin_wave_radial =
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
396 {
155
adf9f4b26039 [svn] - user-friendly names (UI side unimplemented still)
nenolod
parents: 149
diff changeset
397 "wave_radial", "Radial Waveform",
adf9f4b26039 [svn] - user-friendly names (UI side unimplemented still)
nenolod
parents: 149
diff changeset
398 "Draws a single waveform varying"
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
399 " radially from the center of the image",
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
400 0, wave_radial_opts,
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
401 NULL, NULL, wave_radial_exec
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
402 };
292
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
403
283
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
404 /* **************** wave_scope **************** */
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
405
283
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
406 static struct pn_actuator_option_desc wave_scope_opts[] =
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
407 {
297
44ad758c2d98 [svn] - better default values for Scope.
nenolod
parents: 292
diff changeset
408 {"init_script", "Initialization script.", OPT_TYPE_STRING, {sval: "n = 800; t = -0.05;"} },
44ad758c2d98 [svn] - better default values for Scope.
nenolod
parents: 292
diff changeset
409 {"frame_script", "Script to run at the beginning of each frame.", OPT_TYPE_STRING, {sval: "t = t + 0.05;"} },
44ad758c2d98 [svn] - better default values for Scope.
nenolod
parents: 292
diff changeset
410 {"sample_script", "Script to run for each sample.", OPT_TYPE_STRING, {sval: "d = index + value; r = t + index * 3.141952924 * 4; x = cos(r) * d; y = sin(r) * d;"} },
283
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
411 {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} },
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
412 { NULL }
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
413 };
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
414
283
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
415 struct pn_scope_data
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
416 {
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
417 expression_t *expr_on_init, *expr_on_frame, *expr_on_sample;
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
418 symbol_dict_t *dict;
292
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
419 gboolean reset;
283
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
420 };
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
421
292
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
422 static void
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
423 wave_scope_init(gpointer *data)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
424 {
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
425 *data = g_new0(struct pn_scope_data, 1);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
426
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
427 /* the expressions will need to be compiled, so prepare for that */
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
428 ((struct pn_scope_data *)*data)->reset = TRUE;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
429 }
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
430
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
431 static void
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
432 wave_scope_cleanup(gpointer op_data)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
433 {
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
434 struct pn_scope_data *data = (struct pn_scope_data *) op_data;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
435
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
436 g_return_if_fail(data != NULL);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
437
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
438 if (data->expr_on_init)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
439 expr_free(data->expr_on_init);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
440
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
441 if (data->expr_on_frame)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
442 expr_free(data->expr_on_frame);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
443
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
444 if (data->expr_on_sample)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
445 expr_free(data->expr_on_sample);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
446
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
447 if (data->dict)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
448 dict_free(data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
449
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
450 if (data)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
451 g_free(data);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
452 }
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
453
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
454 static void
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
455 wave_scope_exec(const struct pn_actuator_option *opts,
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
456 gpointer op_data)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
457 {
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
458 struct pn_scope_data *data = (struct pn_scope_data *) op_data;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
459 gint i;
304
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 297
diff changeset
460 gdouble *xf, *yf, *index, *value, *points;
292
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
461
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
462 if (data->reset)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
463 {
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
464 if (data->dict)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
465 dict_free(data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
466
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
467 data->dict = dict_new();
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
468
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
469 if (opts[0].val.sval != NULL)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
470 data->expr_on_init = expr_compile_string(opts[0].val.sval, data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
471
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
472 if (opts[1].val.sval != NULL)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
473 data->expr_on_frame = expr_compile_string(opts[1].val.sval,
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
474 data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
475
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
476 if (opts[2].val.sval != NULL)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
477 data->expr_on_sample = expr_compile_string(opts[2].val.sval,
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
478 data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
479
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
480 if (data->expr_on_init != NULL)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
481 expr_execute(data->expr_on_init, data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
482
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
483 data->reset = FALSE;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
484 }
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
485
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
486 xf = dict_variable(data->dict, "x");
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
487 yf = dict_variable(data->dict, "y");
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
488 index = dict_variable(data->dict, "index");
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
489 value = dict_variable(data->dict, "value");
304
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 297
diff changeset
490 points = dict_variable(data->dict, "points");
292
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
491
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
492 if (data->expr_on_frame != NULL)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
493 expr_execute(data->expr_on_frame, data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
494
304
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 297
diff changeset
495 if (*points > 513 || *points == 0)
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 297
diff changeset
496 *points = 513;
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 297
diff changeset
497
292
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
498 if (data->expr_on_sample != NULL)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
499 {
304
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 297
diff changeset
500 for (i = 0; i < *points; i++)
292
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
501 {
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
502 gint x, y;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
503 static gint oldx, oldy;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
504
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
505 *value = 1.0 * pn_sound_data->pcm_data[0][i & 511] / 32768.0;
304
3d0b7ca9c8eb [svn] - add pn_draw_dot() and convert some functions to use that instead of redundant checks all over the code.
nenolod
parents: 297
diff changeset
506 *index = i / (*points - 1);
292
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
507
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
508 expr_execute(data->expr_on_sample, data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
509
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
510 x = (gint)(((*xf + 1.0) * (pn_image_data->width - 1) / 2) + 0.5);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
511 y = (gint)(((*yf + 1.0) * (pn_image_data->height - 1) / 2) + 0.5);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
512
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
513 if (i != 0)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
514 pn_draw_line(oldx, oldy, x, y, 255);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
515
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
516 oldx = x;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
517 oldy = y;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
518 }
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
519 }
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
520 }
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
521
283
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
522 struct pn_actuator_desc builtin_wave_scope =
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
523 {
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
524 "wave_scope", "Scope",
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
525 "A programmable scope.",
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
526 0, wave_scope_opts,
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
527 wave_scope_init, wave_scope_cleanup, wave_scope_exec
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
528 };