Debian Codegraph @

plugins/actor/oinksie/gfx-scope.c

raw
1 /* Libvisual-plugins - Standard plugins for libvisual
2 *
3 * Copyright (C) 2002, 2003, 2004, 2005, 2006 Dennis Smit <[email protected]>
4 *
5 * Authors: Dennis Smit <[email protected]>
6 *
7 * $Id: gfx-scope.c,v 1.8 2006/01/22 13:25:26 synap Exp $
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include <math.h>
25
26 #include "common.h"
27 #include "screen.h"
28 #include "audio.h"
29 #include "table.h"
30 #include "misc.h"
31 #include "gfx-misc.h"
32 #include "gfx-scope.h"
33
34
35 void _oink_gfx_scope_stereo (OinksiePrivate *priv, uint8_t *buf, int color1, int color2, int height, int space, int rotate)
36 {
37 int adder = priv->screen_width > 512 ? (priv->screen_width - 512) / 2 : 0;
38
39 int x = 0;
40
41 int xc = 0;
42
43 int xc1r = 0;
44 int xc2r = 0;
45
46 int xc_old = 0;
47
48 int xc1_oldr = 0;
49 int xc2_oldr = 0;
50
51 int y1;
52 int y2;
53
54 int y1r;
55 int y2r;
56
57 int y1_old;
58 int y2_old;
59
60 int y1_oldr;
61 int y2_oldr;
62
63 int base = priv->screen_halfheight - (space / 2);
64 int base2 = priv->screen_halfheight + (space / 2);
65
66 y1_old = ((base) + (priv->audio.pcm[0][0]) * height);
67 y2_old = ((base2) + (priv->audio.pcm[1][0]) * height);
68
69 if (rotate != 0)
70 {
71 y1_oldr = y1_old - priv->screen_halfheight;
72 y2_oldr = y2_old - priv->screen_halfheight;
73
74 _oink_pixel_rotate (&xc1_oldr, &y1_oldr, rotate);
75 _oink_pixel_rotate (&xc2_oldr, &y2_oldr, rotate);
76 }
77
78 for (x = 1; x < priv->screen_width && x < 512; x++)
79 {
80 y1 = ((base) + (priv->audio.pcm[0][x >> 1]) * height);
81 y2 = ((base2) + (priv->audio.pcm[1][x >> 1]) * height);
82
83 if (y1 < 0)
84 y1 = 0;
85 else if (y1 > priv->screen_height)
86 y1 = priv->screen_height - 1;
87
88 if (y2 < 0)
89 y2 = 0;
90 else if (y2 > priv->screen_height)
91 y2= priv->screen_height - 1;
92
93 xc = x + adder;
94
95 if (rotate != 0)
96 {
97 xc1r = xc - priv->screen_halfwidth;
98 xc2r = xc - priv->screen_halfwidth;
99
100 xc1_oldr = xc_old - priv->screen_halfwidth;
101 xc2_oldr = xc_old - priv->screen_halfwidth;
102
103 y1r = y1 - priv->screen_halfheight;
104 y2r = y2 - priv->screen_halfheight;
105
106 y1_oldr = y1_old - priv->screen_halfheight;
107 y2_oldr = y2_old - priv->screen_halfheight;
108
109 _oink_pixel_rotate (&xc1r, &y1r, rotate);
110 _oink_pixel_rotate (&xc2r, &y2r, rotate);
111
112 _oink_pixel_rotate (&xc1_oldr, &y1_oldr, rotate);
113 _oink_pixel_rotate (&xc2_oldr, &y2_oldr, rotate);
114
115 _oink_gfx_line (priv, buf, color1, xc1r + priv->screen_halfwidth,
116 y1r + priv->screen_halfheight, xc1_oldr + priv->screen_halfwidth,
117 y1_oldr + priv->screen_halfheight);
118 _oink_gfx_line (priv, buf, color2, xc2r + priv->screen_halfwidth,
119 y2r + priv->screen_halfheight, xc2_oldr + priv->screen_halfwidth,
120 y2_oldr + priv->screen_halfheight);
121 }
122 else
123 {
124 _oink_gfx_vline (priv, buf, color1, xc, y1, y1_old);
125 _oink_gfx_vline (priv, buf, color2, xc, y2, y2_old);
126 }
127
128 y1_old = y1;
129 y2_old = y2;
130
131 xc_old = xc;
132 }
133 }
134
135 void _oink_gfx_scope_bulbous (OinksiePrivate *priv, uint8_t *buf, int color, int height)
136 {
137 int adder = priv->screen_width > 512 ? (priv->screen_width - 512) / 2 : 0;
138 float tabadd = priv->screen_width > 512 ? ((float) OINK_TABLE_NORMAL_SIZE / 512.00) / 2.00 :
139 ((float) OINK_TABLE_NORMAL_SIZE / priv->screen_width) / 2.00;
140 float tab = 0;
141 int x;
142 int y;
143 int y2;
144 int y_old;
145
146 y = ((priv->screen_halfheight) + (((priv->audio.pcm[2][0]) * height) * _oink_table_sin[(int) tab]));
147
148 y_old = y;
149
150 for (x = 0; x < priv->screen_width && x < 512; x++)
151 {
152 tab += tabadd;
153
154 y = ((priv->screen_halfheight) + (((priv->audio.pcm[2][x >> 1]) * height) * _oink_table_sin[(int) tab]));
155 y2 = ((priv->screen_halfheight) + ((((priv->audio.pcm[2][x >> 1]) * height) * _oink_table_sin[(int) tab]) * 1.4));
156
157 if (y < 0)
158 y = 0;
159 else if (y > priv->screen_height)
160 y = priv->screen_height - 1;
161
162 if (y2 < 0)
163 y2 = 0;
164 else if (y2 > priv->screen_height)
165 y2 = priv->screen_height - 1;
166
167 _oink_gfx_vline (priv, buf, color, x + adder, y, y2);
168 _oink_gfx_vline (priv, buf, color, x + adder, y, y_old);
169
170 y_old = y;
171 }
172 }
173
174 void _oink_gfx_scope_normal (OinksiePrivate *priv, uint8_t *buf, int color, int height)
175 {
176 VisRectangle rect;
177 int i;
178 float fx[512];
179 float fy[512];
180 int x[512];
181 int y[512];
182 int yold = priv->screen_halfheight;
183
184 visual_rectangle_set (&rect, 0, 0, priv->screen_width, priv->screen_height);
185
186 for (i = 0; i < 512; i++) {
187 fx[i] = (1.0 / 512.0) * i;
188 fy[i] = (1 + sin(i)) * 0.5;
189 fy[i] = 0.5 + ((priv->audio.pcm[2][i]) * 0.2);
190 }
191
192 visual_rectangle_denormalise_many_values (&rect, fx, fy, x, y, 512);
193
194 for (i = 0; i < 512; i++) {
195 _oink_gfx_vline (priv, buf, color, x[i], y[i], yold);
196 yold = y[i];
197 }
198 }
199
200 void _oink_gfx_scope_circle (OinksiePrivate *priv, uint8_t *buf, int color, int size, int x, int y)
201 {
202 int i;
203
204 int xs1;
205 int ys1;
206
207 int xs2;
208 int ys2;
209
210 int xcon;
211 int ycon;
212
213 int adder = (OINK_TABLE_NORMAL_SIZE - 1) / 50;
214 int tab = 0;
215
216 xs2 = (_oink_table_sin[tab] * ((priv->audio.pcm[2][0]) + size)) + x;
217 ys2 = (_oink_table_cos[tab] * ((priv->audio.pcm[2][0]) + size)) + y;
218
219 xcon = xs2;
220 ycon = ys2;
221
222 for (i = 0; i < 50; i++)
223 {
224 xs1 = (_oink_table_sin[tab] * ((priv->audio.pcm[2][i >> 1] * 50) + size)) + x;
225 ys1 = (_oink_table_cos[tab] * ((priv->audio.pcm[2][i >> 1] * 50) + size)) + y;
226
227 tab += adder;
228
229 _oink_gfx_line (priv, buf, color, xs1, ys1, xs2, ys2);
230
231 xs2 = xs1;
232 ys2 = ys1;
233 }
234
235 _oink_gfx_line (priv, buf, color, xcon, ycon, xs1, ys1);
236 }
237