Mercurial > audlegacy-plugins
annotate src/paranormal/wave.c @ 2284:d19b53359b24
cleaned up the sndfile wav plugin, currently limiting it ONLY TO WAV
PLAYBACK. if somebody is more experienced with it and wants to restore
the other formats, go ahead (maybe change the name of the plugin too?).
author | mf0102 <0102@gmx.at> |
---|---|
date | Wed, 09 Jan 2008 15:41:22 +0100 |
parents | 56bb18dd3fdd |
children | f1b6f1b2cdb3 |
rev | line source |
---|---|
1892
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
1 /* |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
2 * paranormal: iterated pipeline-driven visualization plugin |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
3 * Copyright (c) 2006, 2007 William Pitcock <nenolod@dereferenced.org> |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
4 * Portions copyright (c) 2001 Jamie Gennis <jgennis@mindspring.com> |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
5 * |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
8 * the Free Software Foundation; under version 2 of the License. |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
9 * |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
13 * GNU General Public License for more details. |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
14 * |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
16 * along with this program; if not, write to the Free Software |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
18 */ |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
304
diff
changeset
|
19 |
1943
56bb18dd3fdd
paranormal: CONFIG_H removal
William Pitcock <nenolod@atheme.org>
parents:
1892
diff
changeset
|
20 #include <config.h> |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
21 |
194
5e8cf0611af3
[svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents:
193
diff
changeset
|
22 #include <math.h> |
5e8cf0611af3
[svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents:
193
diff
changeset
|
23 |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
24 #include "paranormal.h" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
25 #include "actuators.h" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
26 #include "pn_utils.h" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
27 |
203 | 28 #include "drawing.h" |
29 | |
283 | 30 #include "libcalc/calc.h" |
31 | |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
32 /* **************** wave_horizontal **************** */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
33 struct pn_actuator_option_desc wave_horizontal_opts[] = |
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 {"channels", "Which sound channels to use: negative = channel 1, \npositive = channel 2, " |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
36 "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
|
37 {"value", "The colour value to use.", OPT_TYPE_INT, {ival: 255} }, |
193 | 38 {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} }, |
188 | 39 { NULL } |
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 static void |
193 | 43 wave_horizontal_exec_dots (const struct pn_actuator_option *opts, |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
44 gpointer data) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
45 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
46 int i; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
47 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
|
48 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
|
49 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
50 for (i=0; i<pn_image_data->width; i++) { |
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 /*single channel, centered horz.*/ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
53 if ( opts[0].val.ival ) { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
54 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
|
55 - CAP (pn_sound_data->pcm_data[channel] |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
56 [i*512/pn_image_data->width]>>8, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
57 (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
|
58 = value; |
149
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 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
61 /*both channels, at 1/4 and 3/4 of the screen*/ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
62 else { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
63 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
|
64 CAP( (pn_sound_data->pcm_data[0] |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
65 [i*512/pn_image_data->width]>>9), |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
66 (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
|
67 = value; |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
68 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
69 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
|
70 CAP( (pn_sound_data->pcm_data[1] |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
71 [i*512/pn_image_data->width]>>9), |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
72 (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
|
73 = value; |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
74 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
75 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
76 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
77 |
193 | 78 void |
79 wave_horizontal_exec_lines (const struct pn_actuator_option *opts, | |
80 gpointer data) | |
81 { | |
82 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1; | |
83 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival; | |
84 int *x_pos, *y_pos; /* dynamic tables which store the positions for the line */ | |
85 int *x2_pos, *y2_pos; /* dynamic tables which store the positions for the line */ | |
269 | 86 int i; |
87 float step; | |
193 | 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 = g_new0(int, 257); |
5e8cf0611af3
[svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents:
193
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 |
269 | 94 step = pn_image_data->width / 256.; |
193 | 95 |
96 /* calculate the line. */ | |
194
5e8cf0611af3
[svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents:
193
diff
changeset
|
97 for (i = 0; i < 256; i++) |
193 | 98 { |
99 if (opts[0].val.ival != 0) | |
100 { | |
194
5e8cf0611af3
[svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents:
193
diff
changeset
|
101 x_pos[i] = i * step; |
193 | 102 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
|
103 CAP (pn_sound_data->pcm_data[channel][i * 2]>>8, |
193 | 104 (pn_image_data->height>>1)-1); |
105 } | |
106 else | |
107 { | |
194
5e8cf0611af3
[svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents:
193
diff
changeset
|
108 x_pos[i] = i * step; |
193 | 109 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
|
110 CAP (pn_sound_data->pcm_data[0][i * 2]>>9, |
193 | 111 (pn_image_data->height>>2)-1); |
112 | |
194
5e8cf0611af3
[svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents:
193
diff
changeset
|
113 x2_pos[i] = i * step; |
193 | 114 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
|
115 CAP (pn_sound_data->pcm_data[1][i * 2]>>9, |
193 | 116 (pn_image_data->height>>2)-1); |
117 | |
118 } | |
119 } | |
120 | |
121 /* draw the line. */ | |
194
5e8cf0611af3
[svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents:
193
diff
changeset
|
122 for (i = 1; i < 256; i++) |
193 | 123 { |
124 pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value); | |
125 | |
126 if ( opts[0].val.ival == 0 ) | |
127 pn_draw_line(x2_pos[i - 1], y2_pos[i - 1], x2_pos[i], y2_pos[i], value); | |
128 } | |
129 | |
130 g_free(x_pos); | |
131 g_free(y_pos); | |
132 g_free(x2_pos); | |
133 g_free(y2_pos); | |
134 } | |
135 | |
136 static void | |
137 wave_horizontal_exec (const struct pn_actuator_option *opts, | |
138 gpointer data) | |
139 { | |
140 if (opts[2].val.bval == TRUE) | |
141 wave_horizontal_exec_lines(opts, data); | |
142 else | |
143 wave_horizontal_exec_dots(opts, data); | |
144 } | |
145 | |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
146 struct pn_actuator_desc builtin_wave_horizontal = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
147 { |
155
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
148 "wave_horizontal", "Horizontal Waveform", |
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
149 "Draws one or two waveforms horizontally across " |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
150 "the drawing surface", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
151 0, wave_horizontal_opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
152 NULL, NULL, wave_horizontal_exec |
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 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
155 /* **************** wave_vertical **************** */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
156 struct pn_actuator_option_desc wave_vertical_opts[] = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
157 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
158 {"channels", "Which sound channels to use: negative = channel 1, \npositive = channel 2, " |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
159 "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
|
160 {"value", "The colour value to use.", OPT_TYPE_INT, {ival: 255} }, |
193 | 161 {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} }, |
188 | 162 { NULL } |
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 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
165 static void |
193 | 166 wave_vertical_exec_dots (const struct pn_actuator_option *opts, |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
167 gpointer data) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
168 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
169 int i; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
170 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
|
171 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
|
172 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
173 for (i=0; i<pn_image_data->height; i++) { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
174 if ( opts[0].val.ival ) { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
175 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
|
176 - CAP (pn_sound_data->pcm_data[channel] |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
177 [i*512/pn_image_data->height]>>8, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
178 (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
|
179 = value; |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
180 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
181 else { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
182 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
|
183 - CAP (pn_sound_data->pcm_data[0] |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
184 [i*512/pn_image_data->height]>>9, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
185 (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
|
186 = value; |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
187 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
|
188 -CAP (pn_sound_data->pcm_data[1] |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
189 [i*512/pn_image_data->height]>>9, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
190 (pn_image_data->width>>2)-1), i)] |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
191 |
183
37b53a5a9aa4
[svn] - allow waves to be drawn with a custom value instead of just 255
nenolod
parents:
155
diff
changeset
|
192 = value; |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
193 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
194 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
195 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
196 |
193 | 197 static void |
198 wave_vertical_exec_lines (const struct pn_actuator_option *opts, | |
199 gpointer data) | |
200 { | |
201 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1; | |
202 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival; | |
203 int *x_pos, *y_pos; /* dynamic tables which store the positions for the line */ | |
204 int *x2_pos, *y2_pos; /* dynamic tables which store the positions for the line */ | |
269 | 205 int i; |
206 float step; | |
193 | 207 |
194
5e8cf0611af3
[svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents:
193
diff
changeset
|
208 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
|
209 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
|
210 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
|
211 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
|
212 |
269 | 213 step = pn_image_data->height / 128.; |
193 | 214 |
215 /* calculate the line. */ | |
194
5e8cf0611af3
[svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents:
193
diff
changeset
|
216 for (i = 0; i < 128; i++) |
193 | 217 { |
218 if (opts[0].val.ival != 0) | |
219 { | |
220 x_pos[i] = (pn_image_data->width>>1) - | |
221 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
|
222 [i*4]>>8, |
193 | 223 (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
|
224 y_pos[i] = i * step; |
193 | 225 } |
226 else | |
227 { | |
228 x_pos[i] = (pn_image_data->width>>2) | |
229 - 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
|
230 [i*4]>>9, |
193 | 231 (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
|
232 y_pos[i] = i * step; |
193 | 233 |
234 x2_pos[i] = 3*(pn_image_data->width>>2) | |
235 - 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
|
236 [i*4]>>9, |
193 | 237 (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
|
238 y2_pos[i] = i * step; |
193 | 239 } |
240 } | |
241 | |
242 /* draw the line. */ | |
194
5e8cf0611af3
[svn] - faster line calculation algorithm (only calculates 256 or 128 points of the waveform)
nenolod
parents:
193
diff
changeset
|
243 for (i = 1; i < 128; i++) |
193 | 244 { |
245 pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value); | |
246 | |
247 if ( opts[0].val.ival == 0 ) | |
248 pn_draw_line(x2_pos[i - 1], y2_pos[i - 1], x2_pos[i], y2_pos[i], value); | |
249 } | |
250 | |
251 g_free(x_pos); | |
252 g_free(y_pos); | |
253 g_free(x2_pos); | |
254 g_free(y2_pos); | |
255 } | |
256 | |
257 static void | |
258 wave_vertical_exec (const struct pn_actuator_option *opts, | |
259 gpointer data) | |
260 { | |
261 if (opts[2].val.bval == TRUE) | |
262 wave_vertical_exec_lines(opts, data); | |
263 else | |
264 wave_vertical_exec_dots(opts, data); | |
265 } | |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
266 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
267 struct pn_actuator_desc builtin_wave_vertical = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
268 { |
155
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
269 "wave_vertical", "Vertical Waveform", |
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
270 "Draws one or two waveforms vertically across " |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
271 "the drawing surface", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
272 0, wave_vertical_opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
273 NULL, NULL, wave_vertical_exec |
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 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
276 /* FIXME: allow for only 1 channel for wave_normalize & wave_smooth */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
277 /* **************** wave_normalize **************** */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
278 static struct pn_actuator_option_desc wave_normalize_opts[] = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
279 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
280 { "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
|
281 "normalized; if negative, hfrac is used", OPT_TYPE_INT, { ival: -1 } }, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
282 { "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
|
283 "waveform will be normalized; if negative, vfrac is used", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
284 OPT_TYPE_FLOAT, { fval: -1 } }, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
285 { "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
|
286 "waveform will be normalized", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
287 OPT_TYPE_FLOAT, { fval: .125 } }, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
288 { "channels", "Which sound channel(s) to normalize: negative = channel 1,\n" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
289 "\tpositive = channel 2, 0 = both channels.", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
290 OPT_TYPE_INT, { ival: 0 } }, |
188 | 291 { NULL } |
149
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 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
294 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
295 wave_normalize_exec (const struct pn_actuator_option *opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
296 gpointer data) |
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 int i, j, max=0; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
299 float denom; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
300 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
301 for (j=0; j<2; j++) |
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 if ( !(opts[3].val.ival) || (opts[3].val.ival < 0 && j == 0) || |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
304 (opts[3].val.ival > 0 && j == 1) ) { |
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 for (i=0; i<512; i++) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
307 if (abs(pn_sound_data->pcm_data[j][i]) > max) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
308 max = abs(pn_sound_data->pcm_data[j][i]); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
309 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
310 if (opts[0].val.ival > 0) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
311 denom = max/(opts[0].val.ival<<8); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
312 else if (opts[1].val.fval > 0) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
313 denom = max/(opts[1].val.fval * (pn_image_data->width<<8)); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
314 else |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
315 denom = max/(opts[2].val.fval * (pn_image_data->height<<8)); |
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 if (denom > 0) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
318 for (i=0; i<512; i++) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
319 pn_sound_data->pcm_data[j][i] |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
320 /= denom; |
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 } |
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 struct pn_actuator_desc builtin_wave_normalize = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
326 { |
155
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
327 "wave_normalize", "Normalize Waveform Data", |
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
328 "Normalizes the waveform data used by the wave_* actuators", |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
329 0, wave_normalize_opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
330 NULL, NULL, wave_normalize_exec |
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 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
333 /* **************** wave_smooth **************** */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
334 struct pn_actuator_option_desc wave_smooth_opts[] = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
335 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
336 { "channels", "Which sound channel(s) to smooth: negative = channel 1, \n" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
337 "\tpositive = channel 2, 0 = both channels.", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
338 OPT_TYPE_INT, { ival: 0 } }, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
339 {0} |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
340 }; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
341 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
342 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
343 wave_smooth_exec (const struct pn_actuator_option *opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
344 gpointer data) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
345 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
346 int i, j, k; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
347 gint16 tmp[512]; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
348 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
349 for (j=0; j<2; j++) |
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 if ( !(opts[0].val.ival) || (opts[0].val.ival < 0 && j == 0) || |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
352 (opts[0].val.ival > 0 && j == 1) ) { |
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 for (i=4; i<508; i++) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
355 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
356 k = (pn_sound_data->pcm_data[j][i]<<3) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
357 + (pn_sound_data->pcm_data[j][i+1]<<2) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
358 + (pn_sound_data->pcm_data[j][i-1]<<2) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
359 + (pn_sound_data->pcm_data[j][i+2]<<2) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
360 + (pn_sound_data->pcm_data[j][i-2]<<2) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
361 + (pn_sound_data->pcm_data[j][i+3]<<1) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
362 + (pn_sound_data->pcm_data[j][i-3]<<1) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
363 + (pn_sound_data->pcm_data[j][i+4]<<1) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
364 + (pn_sound_data->pcm_data[j][i-4]<<1); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
365 tmp[i] = k >> 5; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
366 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
367 memcpy (pn_sound_data->pcm_data[j]+4, tmp, sizeof (gint16) * 504); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
368 } |
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 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
372 struct pn_actuator_desc builtin_wave_smooth = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
373 { |
155
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
374 "wave_smooth", "Smooth Waveform Data", |
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
375 "Smooth out the waveform data used by the wave_* actuators", |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
376 0, wave_smooth_opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
377 NULL, NULL, wave_smooth_exec |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
378 }; |
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 /* **************** wave_radial **************** */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
381 static struct pn_actuator_option_desc wave_radial_opts[] = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
382 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
383 { "base_radius", " ", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
384 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
|
385 {"value", "The colour value to use.", OPT_TYPE_INT, {ival: 255} }, |
193 | 386 /* {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} }, */ |
188 | 387 { NULL } |
149
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 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
390 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
391 wave_radial_exec (const struct pn_actuator_option *opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
392 gpointer data) |
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 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
|
395 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
|
396 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
397 for(i=0; i<360; i++) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
398 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
399 x = (pn_image_data->width>>1) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
400 + (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
|
401 * cos_val[i]; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
402 y = (pn_image_data->height>>1) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
403 + (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
|
404 * sin_val[i]; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
405 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
406 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
|
407 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
|
408 = value; |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
409 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
410 }; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
411 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
412 struct pn_actuator_desc builtin_wave_radial = |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
413 { |
155
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
414 "wave_radial", "Radial Waveform", |
adf9f4b26039
[svn] - user-friendly names (UI side unimplemented still)
nenolod
parents:
149
diff
changeset
|
415 "Draws a single waveform varying" |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
416 " radially from the center of the image", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
417 0, wave_radial_opts, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
418 NULL, NULL, wave_radial_exec |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
419 }; |
292 | 420 |
283 | 421 /* **************** wave_scope **************** */ |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
422 |
283 | 423 static struct pn_actuator_option_desc wave_scope_opts[] = |
424 { | |
297 | 425 {"init_script", "Initialization script.", OPT_TYPE_STRING, {sval: "n = 800; t = -0.05;"} }, |
426 {"frame_script", "Script to run at the beginning of each frame.", OPT_TYPE_STRING, {sval: "t = t + 0.05;"} }, | |
427 {"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 | 428 {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} }, |
429 { NULL } | |
430 }; | |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
431 |
283 | 432 struct pn_scope_data |
433 { | |
434 expression_t *expr_on_init, *expr_on_frame, *expr_on_sample; | |
435 symbol_dict_t *dict; | |
292 | 436 gboolean reset; |
283 | 437 }; |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
438 |
292 | 439 static void |
440 wave_scope_init(gpointer *data) | |
441 { | |
442 *data = g_new0(struct pn_scope_data, 1); | |
443 | |
444 /* the expressions will need to be compiled, so prepare for that */ | |
445 ((struct pn_scope_data *)*data)->reset = TRUE; | |
446 } | |
447 | |
448 static void | |
449 wave_scope_cleanup(gpointer op_data) | |
450 { | |
451 struct pn_scope_data *data = (struct pn_scope_data *) op_data; | |
452 | |
453 g_return_if_fail(data != NULL); | |
454 | |
455 if (data->expr_on_init) | |
456 expr_free(data->expr_on_init); | |
457 | |
458 if (data->expr_on_frame) | |
459 expr_free(data->expr_on_frame); | |
460 | |
461 if (data->expr_on_sample) | |
462 expr_free(data->expr_on_sample); | |
463 | |
464 if (data->dict) | |
465 dict_free(data->dict); | |
466 | |
467 if (data) | |
468 g_free(data); | |
469 } | |
470 | |
471 static void | |
472 wave_scope_exec(const struct pn_actuator_option *opts, | |
473 gpointer op_data) | |
474 { | |
475 struct pn_scope_data *data = (struct pn_scope_data *) op_data; | |
476 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
|
477 gdouble *xf, *yf, *index, *value, *points; |
292 | 478 |
479 if (data->reset) | |
480 { | |
481 if (data->dict) | |
482 dict_free(data->dict); | |
483 | |
484 data->dict = dict_new(); | |
485 | |
486 if (opts[0].val.sval != NULL) | |
487 data->expr_on_init = expr_compile_string(opts[0].val.sval, data->dict); | |
488 | |
489 if (opts[1].val.sval != NULL) | |
490 data->expr_on_frame = expr_compile_string(opts[1].val.sval, | |
491 data->dict); | |
492 | |
493 if (opts[2].val.sval != NULL) | |
494 data->expr_on_sample = expr_compile_string(opts[2].val.sval, | |
495 data->dict); | |
496 | |
497 if (data->expr_on_init != NULL) | |
498 expr_execute(data->expr_on_init, data->dict); | |
499 | |
500 data->reset = FALSE; | |
501 } | |
502 | |
503 xf = dict_variable(data->dict, "x"); | |
504 yf = dict_variable(data->dict, "y"); | |
505 index = dict_variable(data->dict, "index"); | |
506 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
|
507 points = dict_variable(data->dict, "points"); |
292 | 508 |
509 if (data->expr_on_frame != NULL) | |
510 expr_execute(data->expr_on_frame, data->dict); | |
511 | |
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
|
512 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
|
513 *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
|
514 |
292 | 515 if (data->expr_on_sample != NULL) |
516 { | |
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
|
517 for (i = 0; i < *points; i++) |
292 | 518 { |
519 gint x, y; | |
520 static gint oldx, oldy; | |
521 | |
522 *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
|
523 *index = i / (*points - 1); |
292 | 524 |
525 expr_execute(data->expr_on_sample, data->dict); | |
526 | |
527 x = (gint)(((*xf + 1.0) * (pn_image_data->width - 1) / 2) + 0.5); | |
528 y = (gint)(((*yf + 1.0) * (pn_image_data->height - 1) / 2) + 0.5); | |
529 | |
530 if (i != 0) | |
531 pn_draw_line(oldx, oldy, x, y, 255); | |
532 | |
533 oldx = x; | |
534 oldy = y; | |
535 } | |
536 } | |
537 } | |
538 | |
283 | 539 struct pn_actuator_desc builtin_wave_scope = |
540 { | |
541 "wave_scope", "Scope", | |
542 "A programmable scope.", | |
543 0, wave_scope_opts, | |
544 wave_scope_init, wave_scope_cleanup, wave_scope_exec | |
545 }; |