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