Mercurial > audlegacy-plugins
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 |
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 | 11 #include "drawing.h" |
12 | |
283 | 13 #include "libcalc/calc.h" |
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 | 21 {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} }, |
188 | 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 | 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 | 61 void |
62 wave_horizontal_exec_lines (const struct pn_actuator_option *opts, | |
63 gpointer data) | |
64 { | |
65 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1; | |
66 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival; | |
67 int *x_pos, *y_pos; /* dynamic tables which store the positions for the line */ | |
68 int *x2_pos, *y2_pos; /* dynamic tables which store the positions for the line */ | |
269 | 69 int i; |
70 float step; | |
193 | 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 | 77 step = pn_image_data->width / 256.; |
193 | 78 |
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 | 81 { |
82 if (opts[0].val.ival != 0) | |
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 | 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 | 87 (pn_image_data->height>>1)-1); |
88 } | |
89 else | |
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 | 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 | 94 (pn_image_data->height>>2)-1); |
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 | 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 | 99 (pn_image_data->height>>2)-1); |
100 | |
101 } | |
102 } | |
103 | |
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 | 106 { |
107 pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value); | |
108 | |
109 if ( opts[0].val.ival == 0 ) | |
110 pn_draw_line(x2_pos[i - 1], y2_pos[i - 1], x2_pos[i], y2_pos[i], value); | |
111 } | |
112 | |
113 g_free(x_pos); | |
114 g_free(y_pos); | |
115 g_free(x2_pos); | |
116 g_free(y2_pos); | |
117 } | |
118 | |
119 static void | |
120 wave_horizontal_exec (const struct pn_actuator_option *opts, | |
121 gpointer data) | |
122 { | |
123 if (opts[2].val.bval == TRUE) | |
124 wave_horizontal_exec_lines(opts, data); | |
125 else | |
126 wave_horizontal_exec_dots(opts, data); | |
127 } | |
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 | 144 {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} }, |
188 | 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 | 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 | 180 static void |
181 wave_vertical_exec_lines (const struct pn_actuator_option *opts, | |
182 gpointer data) | |
183 { | |
184 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1; | |
185 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival; | |
186 int *x_pos, *y_pos; /* dynamic tables which store the positions for the line */ | |
187 int *x2_pos, *y2_pos; /* dynamic tables which store the positions for the line */ | |
269 | 188 int i; |
189 float step; | |
193 | 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 | 196 step = pn_image_data->height / 128.; |
193 | 197 |
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 | 200 { |
201 if (opts[0].val.ival != 0) | |
202 { | |
203 x_pos[i] = (pn_image_data->width>>1) - | |
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 | 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 | 208 } |
209 else | |
210 { | |
211 x_pos[i] = (pn_image_data->width>>2) | |
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 | 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 | 216 |
217 x2_pos[i] = 3*(pn_image_data->width>>2) | |
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 | 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 | 222 } |
223 } | |
224 | |
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 | 227 { |
228 pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value); | |
229 | |
230 if ( opts[0].val.ival == 0 ) | |
231 pn_draw_line(x2_pos[i - 1], y2_pos[i - 1], x2_pos[i], y2_pos[i], value); | |
232 } | |
233 | |
234 g_free(x_pos); | |
235 g_free(y_pos); | |
236 g_free(x2_pos); | |
237 g_free(y2_pos); | |
238 } | |
239 | |
240 static void | |
241 wave_vertical_exec (const struct pn_actuator_option *opts, | |
242 gpointer data) | |
243 { | |
244 if (opts[2].val.bval == TRUE) | |
245 wave_vertical_exec_lines(opts, data); | |
246 else | |
247 wave_vertical_exec_dots(opts, data); | |
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 | 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 | 369 /* {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} }, */ |
188 | 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 | 403 |
283 | 404 /* **************** wave_scope **************** */ |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
405 |
283 | 406 static struct pn_actuator_option_desc wave_scope_opts[] = |
407 { | |
297 | 408 {"init_script", "Initialization script.", OPT_TYPE_STRING, {sval: "n = 800; t = -0.05;"} }, |
409 {"frame_script", "Script to run at the beginning of each frame.", OPT_TYPE_STRING, {sval: "t = t + 0.05;"} }, | |
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 | 411 {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} }, |
412 { NULL } | |
413 }; | |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
414 |
283 | 415 struct pn_scope_data |
416 { | |
417 expression_t *expr_on_init, *expr_on_frame, *expr_on_sample; | |
418 symbol_dict_t *dict; | |
292 | 419 gboolean reset; |
283 | 420 }; |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
421 |
292 | 422 static void |
423 wave_scope_init(gpointer *data) | |
424 { | |
425 *data = g_new0(struct pn_scope_data, 1); | |
426 | |
427 /* the expressions will need to be compiled, so prepare for that */ | |
428 ((struct pn_scope_data *)*data)->reset = TRUE; | |
429 } | |
430 | |
431 static void | |
432 wave_scope_cleanup(gpointer op_data) | |
433 { | |
434 struct pn_scope_data *data = (struct pn_scope_data *) op_data; | |
435 | |
436 g_return_if_fail(data != NULL); | |
437 | |
438 if (data->expr_on_init) | |
439 expr_free(data->expr_on_init); | |
440 | |
441 if (data->expr_on_frame) | |
442 expr_free(data->expr_on_frame); | |
443 | |
444 if (data->expr_on_sample) | |
445 expr_free(data->expr_on_sample); | |
446 | |
447 if (data->dict) | |
448 dict_free(data->dict); | |
449 | |
450 if (data) | |
451 g_free(data); | |
452 } | |
453 | |
454 static void | |
455 wave_scope_exec(const struct pn_actuator_option *opts, | |
456 gpointer op_data) | |
457 { | |
458 struct pn_scope_data *data = (struct pn_scope_data *) op_data; | |
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 | 461 |
462 if (data->reset) | |
463 { | |
464 if (data->dict) | |
465 dict_free(data->dict); | |
466 | |
467 data->dict = dict_new(); | |
468 | |
469 if (opts[0].val.sval != NULL) | |
470 data->expr_on_init = expr_compile_string(opts[0].val.sval, data->dict); | |
471 | |
472 if (opts[1].val.sval != NULL) | |
473 data->expr_on_frame = expr_compile_string(opts[1].val.sval, | |
474 data->dict); | |
475 | |
476 if (opts[2].val.sval != NULL) | |
477 data->expr_on_sample = expr_compile_string(opts[2].val.sval, | |
478 data->dict); | |
479 | |
480 if (data->expr_on_init != NULL) | |
481 expr_execute(data->expr_on_init, data->dict); | |
482 | |
483 data->reset = FALSE; | |
484 } | |
485 | |
486 xf = dict_variable(data->dict, "x"); | |
487 yf = dict_variable(data->dict, "y"); | |
488 index = dict_variable(data->dict, "index"); | |
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 | 491 |
492 if (data->expr_on_frame != NULL) | |
493 expr_execute(data->expr_on_frame, data->dict); | |
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 | 498 if (data->expr_on_sample != NULL) |
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 | 501 { |
502 gint x, y; | |
503 static gint oldx, oldy; | |
504 | |
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 | 507 |
508 expr_execute(data->expr_on_sample, data->dict); | |
509 | |
510 x = (gint)(((*xf + 1.0) * (pn_image_data->width - 1) / 2) + 0.5); | |
511 y = (gint)(((*yf + 1.0) * (pn_image_data->height - 1) / 2) + 0.5); | |
512 | |
513 if (i != 0) | |
514 pn_draw_line(oldx, oldy, x, y, 255); | |
515 | |
516 oldx = x; | |
517 oldy = y; | |
518 } | |
519 } | |
520 } | |
521 | |
283 | 522 struct pn_actuator_desc builtin_wave_scope = |
523 { | |
524 "wave_scope", "Scope", | |
525 "A programmable scope.", | |
526 0, wave_scope_opts, | |
527 wave_scope_init, wave_scope_cleanup, wave_scope_exec | |
528 }; |