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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
0c5e3d562d99 [svn] - include drawing.h
nenolod
parents: 194
diff changeset
28 #include "drawing.h"
0c5e3d562d99 [svn] - include drawing.h
nenolod
parents: 194
diff changeset
29
283
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
30 #include "libcalc/calc.h"
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
38 {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} },
188
0d826917c56f [svn] - 64-bit safety (pass 1 of 2)
nenolod
parents: 183
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
78 void
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
79 wave_horizontal_exec_lines (const struct pn_actuator_option *opts,
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
80 gpointer data)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
81 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
82 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1;
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
83 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival;
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
84 int *x_pos, *y_pos; /* dynamic tables which store the positions for the line */
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
85 int *x2_pos, *y2_pos; /* dynamic tables which store the positions for the line */
269
69f309c8bd71 [svn] - properly calculate points
nenolod
parents: 238
diff changeset
86 int i;
69f309c8bd71 [svn] - properly calculate points
nenolod
parents: 238
diff changeset
87 float step;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
69f309c8bd71 [svn] - properly calculate points
nenolod
parents: 238
diff changeset
94 step = pn_image_data->width / 256.;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
95
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
98 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
99 if (opts[0].val.ival != 0)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
104 (pn_image_data->height>>1)-1);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
105 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
106 else
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
111 (pn_image_data->height>>2)-1);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
116 (pn_image_data->height>>2)-1);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
117
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
118 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
119 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
120
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
123 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
124 pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
125
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
126 if ( opts[0].val.ival == 0 )
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
127 pn_draw_line(x2_pos[i - 1], y2_pos[i - 1], x2_pos[i], y2_pos[i], value);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
128 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
129
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
130 g_free(x_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
131 g_free(y_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
132 g_free(x2_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
133 g_free(y2_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
134 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
135
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
136 static void
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
137 wave_horizontal_exec (const struct pn_actuator_option *opts,
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
138 gpointer data)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
139 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
140 if (opts[2].val.bval == TRUE)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
141 wave_horizontal_exec_lines(opts, data);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
142 else
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
143 wave_horizontal_exec_dots(opts, data);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
144 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
161 {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} },
188
0d826917c56f [svn] - 64-bit safety (pass 1 of 2)
nenolod
parents: 183
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
197 static void
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
198 wave_vertical_exec_lines (const struct pn_actuator_option *opts,
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
199 gpointer data)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
200 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
201 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1;
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
202 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival;
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
203 int *x_pos, *y_pos; /* dynamic tables which store the positions for the line */
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
204 int *x2_pos, *y2_pos; /* dynamic tables which store the positions for the line */
269
69f309c8bd71 [svn] - properly calculate points
nenolod
parents: 238
diff changeset
205 int i;
69f309c8bd71 [svn] - properly calculate points
nenolod
parents: 238
diff changeset
206 float step;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
69f309c8bd71 [svn] - properly calculate points
nenolod
parents: 238
diff changeset
213 step = pn_image_data->height / 128.;
193
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
214
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
217 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
218 if (opts[0].val.ival != 0)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
219 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
220 x_pos[i] = (pn_image_data->width>>1) -
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
225 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
226 else
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
227 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
228 x_pos[i] = (pn_image_data->width>>2)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
233
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
234 x2_pos[i] = 3*(pn_image_data->width>>2)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
239 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
240 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
241
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
244 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
245 pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
246
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
247 if ( opts[0].val.ival == 0 )
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
248 pn_draw_line(x2_pos[i - 1], y2_pos[i - 1], x2_pos[i], y2_pos[i], value);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
249 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
250
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
251 g_free(x_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
252 g_free(y_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
253 g_free(x2_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
254 g_free(y2_pos);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
255 }
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
256
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
257 static void
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
258 wave_vertical_exec (const struct pn_actuator_option *opts,
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
259 gpointer data)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
260 {
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
261 if (opts[2].val.bval == TRUE)
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
262 wave_vertical_exec_lines(opts, data);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
263 else
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
264 wave_vertical_exec_dots(opts, data);
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
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
0d826917c56f [svn] - 64-bit safety (pass 1 of 2)
nenolod
parents: 183
diff changeset
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
4b48e6e9b3cb [svn] - rewrite line drawing algorithm for speed
nenolod
parents: 188
diff changeset
386 /* {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} }, */
188
0d826917c56f [svn] - 64-bit safety (pass 1 of 2)
nenolod
parents: 183
diff changeset
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
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
420
283
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
421 /* **************** wave_scope **************** */
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
422
283
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
423 static struct pn_actuator_option_desc wave_scope_opts[] =
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
424 {
297
44ad758c2d98 [svn] - better default values for Scope.
nenolod
parents: 292
diff changeset
425 {"init_script", "Initialization script.", OPT_TYPE_STRING, {sval: "n = 800; t = -0.05;"} },
44ad758c2d98 [svn] - better default values for Scope.
nenolod
parents: 292
diff changeset
426 {"frame_script", "Script to run at the beginning of each frame.", OPT_TYPE_STRING, {sval: "t = t + 0.05;"} },
44ad758c2d98 [svn] - better default values for Scope.
nenolod
parents: 292
diff changeset
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
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
428 {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} },
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
429 { NULL }
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
430 };
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
431
283
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
432 struct pn_scope_data
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
433 {
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
434 expression_t *expr_on_init, *expr_on_frame, *expr_on_sample;
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
435 symbol_dict_t *dict;
292
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
436 gboolean reset;
283
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
437 };
149
fd9c0a5871ac [svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff changeset
438
292
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
439 static void
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
440 wave_scope_init(gpointer *data)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
441 {
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
442 *data = g_new0(struct pn_scope_data, 1);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
443
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
444 /* the expressions will need to be compiled, so prepare for that */
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
445 ((struct pn_scope_data *)*data)->reset = TRUE;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
446 }
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
447
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
448 static void
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
449 wave_scope_cleanup(gpointer op_data)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
450 {
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
451 struct pn_scope_data *data = (struct pn_scope_data *) op_data;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
452
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
453 g_return_if_fail(data != NULL);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
454
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
455 if (data->expr_on_init)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
456 expr_free(data->expr_on_init);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
457
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
458 if (data->expr_on_frame)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
459 expr_free(data->expr_on_frame);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
460
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
461 if (data->expr_on_sample)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
462 expr_free(data->expr_on_sample);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
463
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
464 if (data->dict)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
465 dict_free(data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
466
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
467 if (data)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
468 g_free(data);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
469 }
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
470
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
471 static void
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
472 wave_scope_exec(const struct pn_actuator_option *opts,
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
473 gpointer op_data)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
474 {
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
475 struct pn_scope_data *data = (struct pn_scope_data *) op_data;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
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
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
478
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
479 if (data->reset)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
480 {
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
481 if (data->dict)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
482 dict_free(data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
483
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
484 data->dict = dict_new();
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
485
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
486 if (opts[0].val.sval != NULL)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
487 data->expr_on_init = expr_compile_string(opts[0].val.sval, data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
488
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
489 if (opts[1].val.sval != NULL)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
490 data->expr_on_frame = expr_compile_string(opts[1].val.sval,
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
491 data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
492
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
493 if (opts[2].val.sval != NULL)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
494 data->expr_on_sample = expr_compile_string(opts[2].val.sval,
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
495 data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
496
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
497 if (data->expr_on_init != NULL)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
498 expr_execute(data->expr_on_init, data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
499
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
500 data->reset = FALSE;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
501 }
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
502
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
503 xf = dict_variable(data->dict, "x");
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
504 yf = dict_variable(data->dict, "y");
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
505 index = dict_variable(data->dict, "index");
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
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
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
508
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
509 if (data->expr_on_frame != NULL)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
510 expr_execute(data->expr_on_frame, data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
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
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
515 if (data->expr_on_sample != NULL)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
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
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
518 {
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
519 gint x, y;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
520 static gint oldx, oldy;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
521
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
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
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
524
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
525 expr_execute(data->expr_on_sample, data->dict);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
526
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
527 x = (gint)(((*xf + 1.0) * (pn_image_data->width - 1) / 2) + 0.5);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
528 y = (gint)(((*yf + 1.0) * (pn_image_data->height - 1) / 2) + 0.5);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
529
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
530 if (i != 0)
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
531 pn_draw_line(oldx, oldy, x, y, 255);
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
532
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
533 oldx = x;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
534 oldy = y;
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
535 }
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
536 }
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
537 }
4fc6f8d2c000 [svn] - Scope implementation, not yet hooked up.
nenolod
parents: 283
diff changeset
538
283
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
539 struct pn_actuator_desc builtin_wave_scope =
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
540 {
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
541 "wave_scope", "Scope",
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
542 "A programmable scope.",
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
543 0, wave_scope_opts,
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
544 wave_scope_init, wave_scope_cleanup, wave_scope_exec
6b3773478f9e [svn] - some base code for Scope, not yet enabled.
nenolod
parents: 269
diff changeset
545 };