Debian Codegraph @

plugins/actor/JESS/analyser.c

raw
1 /* Libvisual-plugins - Standard plugins for libvisual
2 *
3 * Copyright (C) 2000, 2001 Remi Arquier <[email protected]>
4 *
5 * Authors: Remi Arquier <[email protected]>
6 * Dennis Smit <[email protected]>
7 *
8 * $Id: analyser.c,v 1.6 2006/01/30 19:06:46 synap Exp $
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25 #include <sys/time.h>
26 #include <stdlib.h>
27
28 #include "struct.h"
29 #include "analyser_struct.h"
30 #include "analyser.h"
31 #include "def.h"
32 #include "jess.h"
33
34 int detect_beat(JessPrivate *priv)
35 {
36 if ((priv->lys.E / priv->lys.E_moyen > LEVEL_ONE))
37 {
38 priv->lys.beat = OUI;
39
40 }
41
42 return 0;
43 }
44
45 /* Energie discrete moyenne temporellie*/
46 void spectre_moyen(JessPrivate *priv, short data_freq_tmp[2][256])
47 {
48 int i;
49 float aux,N;
50 N = T_AVERAGE_SPECTRAL;
51
52 for (i=0 ; i<256 ; i++)
53 {
54 aux = (float) (data_freq_tmp[0][i] + data_freq_tmp[1][i]) * 0.5 / 65536;
55 aux = aux * aux;
56 priv->lys.Ed_moyen[i] = (N - 1.0) / N * priv->lys.Ed_moyen[i] + 1.0 / N * aux;
57
58 if (aux / priv->lys.Ed_moyen[i] > 9) /* discret beat */
59 priv->lys.dbeat[i] = OUI;
60 }
61 }
62
63
64 /* Derivee temporelle de l'energie moyenne */
65 /* Doit etre appelle apres C_E_moyen */
66 void C_dEdt_moyen(JessPrivate *priv)
67 {
68 float new, N;
69
70 N = T_AVERAGE_DEDT;
71
72 new = (priv->lys.E_moyen - priv->E_old1) / priv->lys.dt;
73
74 priv->lys.dEdt_moyen = (N - 1.0) / N * priv->lys.dEdt_moyen + 1.0 / N * new;
75
76 priv->E_old1 = priv->lys.E_moyen;
77 }
78
79 void C_dEdt(JessPrivate *priv)
80 {
81 float new, N;
82
83 N = T_DEDT; /* on met un petit filtre qd meme */
84
85 new = (priv->lys.E_moyen - priv->E_old2) / priv->lys.dt;
86
87 priv->lys.dEdt = (N - 1.0) / N * priv->lys.dEdt_moyen + 1.0 / N * new;
88
89 priv->E_old2 = priv->lys.E_moyen;
90 }
91
92 /* Energie moyenne temporelle */
93 void C_E_moyen(JessPrivate *priv, short data_freq_tmp[2][256])
94 {
95 float N;
96 N = T_AVERAGE_E;
97
98 priv->lys.E_moyen = (N - 1.0) / N * priv->lys.E_moyen + 1.0 / N * energy(priv, data_freq_tmp,1);
99 }
100
101 /* Energie courante */
102 float energy(JessPrivate *priv, short data_freq_tmp[2][256], int type_E)
103 {
104 int i, tmp;
105 float energy_ = 0;
106
107 for (i = 0; i < 256; i++) {
108 tmp = ( data_freq_tmp[1][i] ) >> 8 ;
109 energy_+= tmp * tmp ;
110 }
111
112 energy_ = energy_ / 65536 / 256 * 256; /*ahahah*/ /* synap: Yes, indeed */
113
114 priv->lys.E = energy_;
115
116 return energy_;
117 }
118
119 /* TICK REPLACEMENT */
120
121 int start_ticks(JessPrivate *priv)
122 {
123 gettimeofday(&priv->start, NULL);
124
125 return 0;
126 }
127
128 int get_ticks(JessPrivate *priv)
129 {
130 struct timeval now;
131 int ticks;
132
133 gettimeofday(&now, NULL);
134 ticks = (now.tv_sec - priv->start.tv_sec) * 1000 +
135 (now.tv_usec - priv->start.tv_usec) / 1000;
136
137 return ticks;
138 }
139
140 /* REINIT */
141 float time_last(JessPrivate *priv, int i, int reinit)
142 {
143 float new_time = get_ticks(priv);
144 float delta_t;
145
146 delta_t = (new_time - priv->lys.last_time[i]) / 1000;
147
148 if (reinit == OUI)
149 priv->lys.last_time[i] = new_time;
150
151 return delta_t;
152 }
153
154
155
156 void ips(JessPrivate *priv)
157 {
158 priv->conteur.dt = time_last(priv, FOUR, NON);
159 priv->conteur.fps = (int) 1 / time_last(priv, FOUR, REINIT);
160 }
161