annotate src/rovascope/wave.c @ 1263:458d46e65a86

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