File: analyser.c

package info (click to toggle)
libvisual-plugins 0.4.0.dfsg.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,228 kB
  • ctags: 1,065
  • sloc: ansic: 9,357; sh: 8,809; cpp: 871; makefile: 217; sed: 16
file content (161 lines) | stat: -rw-r--r-- 3,653 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* Libvisual-plugins - Standard plugins for libvisual
 * 
 * Copyright (C) 2000, 2001 Remi Arquier <arquier@crans.org>
 *
 * Authors: Remi Arquier <arquier@crans.org>
 *	    Dennis Smit <ds@nerds-incorporated.org>
 *
 * $Id: analyser.c,v 1.6 2006/01/30 19:06:46 synap Exp $
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include <sys/time.h>
#include <stdlib.h>

#include "struct.h"
#include "analyser_struct.h"
#include "analyser.h"
#include "def.h"
#include "jess.h"

int detect_beat(JessPrivate *priv)
{
	if ((priv->lys.E / priv->lys.E_moyen > LEVEL_ONE))
	{
		priv->lys.beat = OUI;

	}

	return 0;
}

/* Energie discrete moyenne temporellie*/
void spectre_moyen(JessPrivate *priv, short data_freq_tmp[2][256])
{
	int i;
	float aux,N;
	N = T_AVERAGE_SPECTRAL;

	for (i=0 ; i<256 ; i++)
	{
		aux = (float) (data_freq_tmp[0][i] + data_freq_tmp[1][i]) * 0.5 / 65536;
		aux = aux * aux;
		priv->lys.Ed_moyen[i] = (N - 1.0) / N * priv->lys.Ed_moyen[i] + 1.0 / N * aux;

		if (aux / priv->lys.Ed_moyen[i] > 9) /* discret beat */
			priv->lys.dbeat[i] = OUI;
	}
}


/* Derivee temporelle de l'energie moyenne */
/* Doit etre appelle apres C_E_moyen */
void C_dEdt_moyen(JessPrivate *priv)
{
	float new, N;

	N = T_AVERAGE_DEDT;

	new = (priv->lys.E_moyen - priv->E_old1) / priv->lys.dt;

	priv->lys.dEdt_moyen = (N - 1.0) / N * priv->lys.dEdt_moyen + 1.0 / N * new; 

	priv->E_old1 = priv->lys.E_moyen;
}

void C_dEdt(JessPrivate *priv)
{
	float new, N;

	N = T_DEDT; /* on met un petit filtre qd meme */

	new = (priv->lys.E_moyen - priv->E_old2) / priv->lys.dt;

	priv->lys.dEdt = (N - 1.0) / N * priv->lys.dEdt_moyen + 1.0 / N * new; 

	priv->E_old2 = priv->lys.E_moyen;
}
  
/* Energie moyenne temporelle */
void C_E_moyen(JessPrivate *priv, short data_freq_tmp[2][256])
{
	float N;
	N = T_AVERAGE_E;

	priv->lys.E_moyen = (N - 1.0) / N * priv->lys.E_moyen + 1.0 / N * energy(priv, data_freq_tmp,1);
}

/* Energie courante */
float energy(JessPrivate *priv, short data_freq_tmp[2][256], int type_E)
{
	int i, tmp;
	float energy_ = 0;

	for (i = 0; i < 256; i++) {
		tmp = ( data_freq_tmp[1][i]  ) >> 8 ;
		energy_+= tmp * tmp ;
	}

	energy_ =  energy_ / 65536 / 256 * 256; /*ahahah*/ /* synap: Yes, indeed */

	priv->lys.E = energy_;

	return energy_;
}

/* TICK REPLACEMENT */

int start_ticks(JessPrivate *priv)
{
	gettimeofday(&priv->start, NULL);

	return 0;
}

int get_ticks(JessPrivate *priv)
{
	struct timeval now;
	int ticks;

	gettimeofday(&now, NULL);
	ticks = (now.tv_sec - priv->start.tv_sec) * 1000 +
		(now.tv_usec - priv->start.tv_usec) / 1000;

	return ticks;
}

/* REINIT */
float time_last(JessPrivate *priv, int i, int reinit)
{
	float new_time = get_ticks(priv);
	float delta_t;

	delta_t = (new_time - priv->lys.last_time[i]) / 1000;

	if (reinit == OUI)
		priv->lys.last_time[i] = new_time;

	return delta_t;
} 



void ips(JessPrivate *priv)
{
	priv->conteur.dt = time_last(priv, FOUR, NON);
	priv->conteur.fps = (int) 1 / time_last(priv, FOUR, REINIT);
}