Mercurial > audlegacy-plugins
comparison src/paranormal/wave.c @ 193:4b48e6e9b3cb trunk
[svn] - rewrite line drawing algorithm for speed
- use lines instead of dots by default in horizontal and vertical waveforms
author | nenolod |
---|---|
date | Fri, 03 Nov 2006 02:54:12 -0800 |
parents | 0d826917c56f |
children | 5e8cf0611af3 |
comparison
equal
deleted
inserted
replaced
192:a7c823478180 | 193:4b48e6e9b3cb |
---|---|
10 struct pn_actuator_option_desc wave_horizontal_opts[] = | 10 struct pn_actuator_option_desc wave_horizontal_opts[] = |
11 { | 11 { |
12 {"channels", "Which sound channels to use: negative = channel 1, \npositive = channel 2, " | 12 {"channels", "Which sound channels to use: negative = channel 1, \npositive = channel 2, " |
13 "zero = both (two wave-forms.)", OPT_TYPE_INT, {ival: -1} }, | 13 "zero = both (two wave-forms.)", OPT_TYPE_INT, {ival: -1} }, |
14 {"value", "The colour value to use.", OPT_TYPE_INT, {ival: 255} }, | 14 {"value", "The colour value to use.", OPT_TYPE_INT, {ival: 255} }, |
15 {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} }, | |
15 { NULL } | 16 { NULL } |
16 }; | 17 }; |
17 | 18 |
18 static void | 19 static void |
19 wave_horizontal_exec (const struct pn_actuator_option *opts, | 20 wave_horizontal_exec_dots (const struct pn_actuator_option *opts, |
20 gpointer data) | 21 gpointer data) |
21 { | 22 { |
22 int i; | 23 int i; |
23 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1; | 24 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1; |
24 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival; | 25 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival; |
49 = value; | 50 = value; |
50 } | 51 } |
51 } | 52 } |
52 } | 53 } |
53 | 54 |
55 void | |
56 wave_horizontal_exec_lines (const struct pn_actuator_option *opts, | |
57 gpointer data) | |
58 { | |
59 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1; | |
60 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival; | |
61 int *x_pos, *y_pos; /* dynamic tables which store the positions for the line */ | |
62 int *x2_pos, *y2_pos; /* dynamic tables which store the positions for the line */ | |
63 int i; | |
64 | |
65 x_pos = g_new0(int, pn_image_data->width + 1); | |
66 y_pos = g_new0(int, pn_image_data->width + 1); | |
67 x2_pos = g_new0(int, pn_image_data->width + 1); | |
68 y2_pos = g_new0(int, pn_image_data->width + 1); | |
69 | |
70 /* calculate the line. */ | |
71 for (i = 0; i < pn_image_data->width; i++) | |
72 { | |
73 if (opts[0].val.ival != 0) | |
74 { | |
75 x_pos[i] = i; | |
76 y_pos[i] = (pn_image_data->height>>1) - | |
77 CAP (pn_sound_data->pcm_data[channel][i*512/pn_image_data->width]>>8, | |
78 (pn_image_data->height>>1)-1); | |
79 } | |
80 else | |
81 { | |
82 x_pos[i] = i; | |
83 y_pos[i] = (pn_image_data->height>>2) - | |
84 CAP (pn_sound_data->pcm_data[0][i*512/pn_image_data->width]>>9, | |
85 (pn_image_data->height>>2)-1); | |
86 | |
87 x2_pos[i] = i; | |
88 y2_pos[i] = 3*(pn_image_data->height>>2) - | |
89 CAP (pn_sound_data->pcm_data[1][i*512/pn_image_data->width]>>9, | |
90 (pn_image_data->height>>2)-1); | |
91 | |
92 } | |
93 } | |
94 | |
95 /* draw the line. */ | |
96 for (i = 1; i < pn_image_data->width; i++) | |
97 { | |
98 pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value); | |
99 | |
100 if ( opts[0].val.ival == 0 ) | |
101 pn_draw_line(x2_pos[i - 1], y2_pos[i - 1], x2_pos[i], y2_pos[i], value); | |
102 } | |
103 | |
104 g_free(x_pos); | |
105 g_free(y_pos); | |
106 g_free(x2_pos); | |
107 g_free(y2_pos); | |
108 } | |
109 | |
110 static void | |
111 wave_horizontal_exec (const struct pn_actuator_option *opts, | |
112 gpointer data) | |
113 { | |
114 if (opts[2].val.bval == TRUE) | |
115 wave_horizontal_exec_lines(opts, data); | |
116 else | |
117 wave_horizontal_exec_dots(opts, data); | |
118 } | |
119 | |
54 struct pn_actuator_desc builtin_wave_horizontal = | 120 struct pn_actuator_desc builtin_wave_horizontal = |
55 { | 121 { |
56 "wave_horizontal", "Horizontal Waveform", | 122 "wave_horizontal", "Horizontal Waveform", |
57 "Draws one or two waveforms horizontally across " | 123 "Draws one or two waveforms horizontally across " |
58 "the drawing surface", | 124 "the drawing surface", |
64 struct pn_actuator_option_desc wave_vertical_opts[] = | 130 struct pn_actuator_option_desc wave_vertical_opts[] = |
65 { | 131 { |
66 {"channels", "Which sound channels to use: negative = channel 1, \npositive = channel 2, " | 132 {"channels", "Which sound channels to use: negative = channel 1, \npositive = channel 2, " |
67 "zero = both (two wave-forms.)", OPT_TYPE_INT, {ival: -1} }, | 133 "zero = both (two wave-forms.)", OPT_TYPE_INT, {ival: -1} }, |
68 {"value", "The colour value to use.", OPT_TYPE_INT, {ival: 255} }, | 134 {"value", "The colour value to use.", OPT_TYPE_INT, {ival: 255} }, |
135 {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} }, | |
69 { NULL } | 136 { NULL } |
70 }; | 137 }; |
71 | 138 |
72 static void | 139 static void |
73 wave_vertical_exec (const struct pn_actuator_option *opts, | 140 wave_vertical_exec_dots (const struct pn_actuator_option *opts, |
74 gpointer data) | 141 gpointer data) |
75 { | 142 { |
76 int i; | 143 int i; |
77 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1; | 144 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1; |
78 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival; | 145 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival; |
99 = value; | 166 = value; |
100 } | 167 } |
101 } | 168 } |
102 } | 169 } |
103 | 170 |
171 static void | |
172 wave_vertical_exec_lines (const struct pn_actuator_option *opts, | |
173 gpointer data) | |
174 { | |
175 int channel = ( opts[0].val.ival < 0 ) ? 0 : 1; | |
176 guchar value = (opts[1].val.ival < 0 || opts[1].val.ival > 255) ? 255 : opts[1].val.ival; | |
177 int *x_pos, *y_pos; /* dynamic tables which store the positions for the line */ | |
178 int *x2_pos, *y2_pos; /* dynamic tables which store the positions for the line */ | |
179 int i; | |
180 | |
181 x_pos = g_new0(int, pn_image_data->height + 1); | |
182 y_pos = g_new0(int, pn_image_data->height + 1); | |
183 x2_pos = g_new0(int, pn_image_data->height + 1); | |
184 y2_pos = g_new0(int, pn_image_data->height + 1); | |
185 | |
186 /* calculate the line. */ | |
187 for (i = 0; i < pn_image_data->height; i++) | |
188 { | |
189 if (opts[0].val.ival != 0) | |
190 { | |
191 x_pos[i] = (pn_image_data->width>>1) - | |
192 CAP (pn_sound_data->pcm_data[channel] | |
193 [i*512/pn_image_data->height]>>8, | |
194 (pn_image_data->width>>1)-1); | |
195 y_pos[i] = i; | |
196 } | |
197 else | |
198 { | |
199 x_pos[i] = (pn_image_data->width>>2) | |
200 - CAP (pn_sound_data->pcm_data[0] | |
201 [i*512/pn_image_data->height]>>9, | |
202 (pn_image_data->width>>2)-1); | |
203 y_pos[i] = i; | |
204 | |
205 x2_pos[i] = 3*(pn_image_data->width>>2) | |
206 - CAP (pn_sound_data->pcm_data[1] | |
207 [i*512/pn_image_data->height]>>9, | |
208 (pn_image_data->width>>2)-1); | |
209 y2_pos[i] = i; | |
210 } | |
211 } | |
212 | |
213 /* draw the line. */ | |
214 for (i = 1; i < pn_image_data->width; i++) | |
215 { | |
216 pn_draw_line(x_pos[i - 1], y_pos[i - 1], x_pos[i], y_pos[i], value); | |
217 | |
218 if ( opts[0].val.ival == 0 ) | |
219 pn_draw_line(x2_pos[i - 1], y2_pos[i - 1], x2_pos[i], y2_pos[i], value); | |
220 } | |
221 | |
222 g_free(x_pos); | |
223 g_free(y_pos); | |
224 g_free(x2_pos); | |
225 g_free(y2_pos); | |
226 } | |
227 | |
228 static void | |
229 wave_vertical_exec (const struct pn_actuator_option *opts, | |
230 gpointer data) | |
231 { | |
232 if (opts[2].val.bval == TRUE) | |
233 wave_vertical_exec_lines(opts, data); | |
234 else | |
235 wave_vertical_exec_dots(opts, data); | |
236 } | |
104 | 237 |
105 struct pn_actuator_desc builtin_wave_vertical = | 238 struct pn_actuator_desc builtin_wave_vertical = |
106 { | 239 { |
107 "wave_vertical", "Vertical Waveform", | 240 "wave_vertical", "Vertical Waveform", |
108 "Draws one or two waveforms vertically across " | 241 "Draws one or two waveforms vertically across " |
219 static struct pn_actuator_option_desc wave_radial_opts[] = | 352 static struct pn_actuator_option_desc wave_radial_opts[] = |
220 { | 353 { |
221 { "base_radius", " ", | 354 { "base_radius", " ", |
222 OPT_TYPE_FLOAT, { fval: 0 } }, | 355 OPT_TYPE_FLOAT, { fval: 0 } }, |
223 {"value", "The colour value to use.", OPT_TYPE_INT, {ival: 255} }, | 356 {"value", "The colour value to use.", OPT_TYPE_INT, {ival: 255} }, |
357 /* {"lines", "Use lines instead of dots.", OPT_TYPE_BOOLEAN, {bval: TRUE} }, */ | |
224 { NULL } | 358 { NULL } |
225 }; | 359 }; |
226 | 360 |
227 static void | 361 static void |
228 wave_radial_exec (const struct pn_actuator_option *opts, | 362 wave_radial_exec (const struct pn_actuator_option *opts, |