• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Goom Project
2  * Copyright (C) <2003> iOS-Software
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 
23 #include <gst/gst.h>
24 
25 #include "goom_config.h"
26 
27 #include "goom_plugin_info.h"
28 #include "goom_fx.h"
29 #include "drawmethods.h"
30 #include <math.h>
31 #include <stdio.h>
32 #ifdef HAVE_ORC
33 #include <orc/orc.h>
34 #endif
35 
36 
37 #if defined (HAVE_CPU_PPC64) || defined (HAVE_CPU_PPC)
38 #include "ppc_zoom_ultimate.h"
39 #include "ppc_drawings.h"
40 #endif /* HAVE_CPU_PPC64 || HAVE_CPU_PPC */
41 
42 
43 #ifdef HAVE_MMX
44 #include "mmx.h"
45 #endif /* HAVE_MMX */
46 
47 #include <string.h>
48 
49 GST_DEBUG_CATEGORY_EXTERN (goom_debug);
50 #define GST_CAT_DEFAULT goom_debug
51 
52 static void
setOptimizedMethods(PluginInfo * p)53 setOptimizedMethods (PluginInfo * p)
54 {
55 #ifdef HAVE_ORC
56   unsigned int cpuFlavour =
57       orc_target_get_default_flags (orc_target_get_by_name ("mmx"));
58 #else
59   unsigned int cpuFlavour = 0;
60 #endif
61 
62   /* set default methods */
63   p->methods.draw_line = draw_line;
64   p->methods.zoom_filter = zoom_filter_c;
65 /*    p->methods.create_output_with_brightness = create_output_with_brightness;*/
66 
67   GST_INFO ("orc cpu flags: 0x%08x", cpuFlavour);
68 
69 /* FIXME: what about HAVE_CPU_X86_64 ? */
70 #ifdef HAVE_CPU_I386
71 #ifdef HAVE_MMX
72 #ifdef HAVE_ORC
73   GST_INFO ("have an x86");
74   if (cpuFlavour & ORC_TARGET_MMX_MMXEXT) {
75     GST_INFO ("Extended MMX detected. Using the fastest methods!");
76     p->methods.draw_line = draw_line_xmmx;
77     p->methods.zoom_filter = zoom_filter_xmmx;
78   } else if (cpuFlavour & ORC_TARGET_MMX_MMX) {
79     GST_INFO ("MMX detected. Using fast methods!");
80     p->methods.draw_line = draw_line_mmx;
81     p->methods.zoom_filter = zoom_filter_mmx;
82   } else {
83     GST_INFO ("Too bad ! No SIMD optimization available for your CPU.");
84   }
85 #endif
86 #endif
87 #endif /* HAVE_CPU_I386 */
88 
89 /* disable all PPC stuff until someone finds out what to use here instead of
90  * CPU_OPTION_64_BITS, and until someone fixes the assembly build for ppc */
91 #if 0
92 #ifdef HAVE_CPU_PPC64
93   if ((cpuFlavour & CPU_OPTION_64_BITS) != 0) {
94 /*            p->methods.create_output_with_brightness = ppc_brightness_G5;        */
95     p->methods.zoom_filter = ppc_zoom_generic;
96   }
97 #endif /* HAVE_CPU_PPC64 */
98 
99 #ifdef HAVE_CPU_PPC
100   if ((cpuFlavour & ORC_TARGET_ALTIVEC_ALTIVEC) != 0) {
101 /*            p->methods.create_output_with_brightness = ppc_brightness_G4;        */
102     p->methods.zoom_filter = ppc_zoom_G4;
103   } else {
104 /*            p->methods.create_output_with_brightness = ppc_brightness_generic;*/
105     p->methods.zoom_filter = ppc_zoom_generic;
106   }
107 #endif /* HAVE_CPU_PPC */
108 #endif
109 }
110 
111 void
plugin_info_init(PluginInfo * pp,int nbVisuals)112 plugin_info_init (PluginInfo * pp, int nbVisuals)
113 {
114 
115   int i;
116 
117   memset (pp, 0, sizeof (PluginInfo));
118 
119   pp->sound.speedvar = pp->sound.accelvar = pp->sound.totalgoom = 0;
120   pp->sound.prov_max = 0;
121   pp->sound.goom_limit = 1;
122   pp->sound.allTimesMax = 1;
123   pp->sound.timeSinceLastGoom = 1;
124   pp->sound.timeSinceLastBigGoom = 1;
125   pp->sound.cycle = 0;
126 
127   secure_f_feedback (&pp->sound.volume_p, "Sound Volume");
128   secure_f_feedback (&pp->sound.accel_p, "Sound Acceleration");
129   secure_f_feedback (&pp->sound.speed_p, "Sound Speed");
130   secure_f_feedback (&pp->sound.goom_limit_p, "Goom Limit");
131   secure_f_feedback (&pp->sound.last_goom_p, "Goom Detection");
132   secure_f_feedback (&pp->sound.last_biggoom_p, "Big Goom Detection");
133   secure_f_feedback (&pp->sound.goom_power_p, "Goom Power");
134 
135   secure_i_param (&pp->sound.biggoom_speed_limit_p, "Big Goom Speed Limit");
136   IVAL (pp->sound.biggoom_speed_limit_p) = 10;
137   IMIN (pp->sound.biggoom_speed_limit_p) = 0;
138   IMAX (pp->sound.biggoom_speed_limit_p) = 100;
139   ISTEP (pp->sound.biggoom_speed_limit_p) = 1;
140 
141   secure_i_param (&pp->sound.biggoom_factor_p, "Big Goom Factor");
142   IVAL (pp->sound.biggoom_factor_p) = 10;
143   IMIN (pp->sound.biggoom_factor_p) = 0;
144   IMAX (pp->sound.biggoom_factor_p) = 100;
145   ISTEP (pp->sound.biggoom_factor_p) = 1;
146 
147   plugin_parameters (&pp->sound.params, "Sound", 11);
148 
149   pp->nbParams = 0;
150   pp->params = NULL;
151   pp->nbVisuals = nbVisuals;
152   pp->visuals = (VisualFX **) malloc (sizeof (VisualFX *) * nbVisuals);
153 
154   pp->sound.params.params[0] = &pp->sound.biggoom_speed_limit_p;
155   pp->sound.params.params[1] = &pp->sound.biggoom_factor_p;
156   pp->sound.params.params[2] = 0;
157   pp->sound.params.params[3] = &pp->sound.volume_p;
158   pp->sound.params.params[4] = &pp->sound.accel_p;
159   pp->sound.params.params[5] = &pp->sound.speed_p;
160   pp->sound.params.params[6] = 0;
161   pp->sound.params.params[7] = &pp->sound.goom_limit_p;
162   pp->sound.params.params[8] = &pp->sound.goom_power_p;
163   pp->sound.params.params[9] = &pp->sound.last_goom_p;
164   pp->sound.params.params[10] = &pp->sound.last_biggoom_p;
165 
166   pp->statesNumber = 8;
167   pp->statesRangeMax = 510;
168   {
169     GoomState states[8] = {
170       {1, 0, 0, 1, 4, 0, 100}
171       ,
172       {1, 0, 0, 0, 1, 101, 140}
173       ,
174       {1, 0, 0, 1, 2, 141, 200}
175       ,
176       {0, 1, 0, 1, 2, 201, 260}
177       ,
178       {0, 1, 0, 1, 0, 261, 330}
179       ,
180       {0, 1, 1, 1, 4, 331, 400}
181       ,
182       {0, 0, 1, 0, 5, 401, 450}
183       ,
184       {0, 0, 1, 1, 1, 451, 510}
185     };
186     for (i = 0; i < 8; ++i)
187       pp->states[i] = states[i];
188   }
189   pp->curGState = &(pp->states[6]);
190 
191   /* datas for the update loop */
192   pp->update.lockvar = 0;
193   pp->update.goomvar = 0;
194   pp->update.loopvar = 0;
195   pp->update.stop_lines = 0;
196   pp->update.ifs_incr = 1;      /* dessiner l'ifs (0 = non: > = increment) */
197   pp->update.decay_ifs = 0;     /* disparition de l'ifs */
198   pp->update.recay_ifs = 0;     /* dedisparition de l'ifs */
199   pp->update.cyclesSinceLastChange = 0;
200   pp->update.drawLinesDuration = 80;
201   pp->update.lineMode = pp->update.drawLinesDuration;
202 
203   pp->update.switchMultAmount = (29.0f / 30.0f);
204   pp->update.switchIncrAmount = 0x7f;
205   pp->update.switchMult = 1.0f;
206   pp->update.switchIncr = pp->update.switchIncrAmount;
207 
208   pp->update.stateSelectionRnd = 0;
209   pp->update.stateSelectionBlocker = 0;
210   pp->update.previousZoomSpeed = 128;
211 
212   {
213     ZoomFilterData zfd = {
214       127, 8, 16,
215       1, 1, 0, NORMAL_MODE,
216       0, 0, 0, 0, 0
217     };
218     pp->update.zoomFilterData = zfd;
219   }
220 
221   setOptimizedMethods (pp);
222 
223   for (i = 0; i < 0xffff; i++) {
224     pp->sintable[i] =
225         (int) (1024 * sin ((double) i * 360 / (sizeof (pp->sintable) /
226                 sizeof (pp->sintable[0]) - 1) * 3.141592 / 180) + .5);
227     /* sintable [us] = (int)(1024.0f * sin (us*2*3.31415f/0xffff)) ; */
228   }
229 }
230 
231 void
plugin_info_add_visual(PluginInfo * p,int i,VisualFX * visual)232 plugin_info_add_visual (PluginInfo * p, int i, VisualFX * visual)
233 {
234   p->visuals[i] = visual;
235   if (i == p->nbVisuals - 1) {
236     ++i;
237     p->nbParams = 1;
238     while (i--) {
239       if (p->visuals[i]->params)
240         p->nbParams++;
241     }
242     p->params =
243         (PluginParameters *) malloc (sizeof (PluginParameters) * p->nbParams);
244     i = p->nbVisuals;
245     p->nbParams = 1;
246     p->params[0] = p->sound.params;
247     while (i--) {
248       if (p->visuals[i]->params)
249         p->params[p->nbParams++] = *(p->visuals[i]->params);
250     }
251   }
252 }
253 
254 void
plugin_info_free(PluginInfo * p)255 plugin_info_free (PluginInfo * p)
256 {
257   goom_plugin_parameters_free (&p->sound.params);
258 
259   if (p->params)
260     free (p->params);
261   free (p->visuals);
262 }
263