1 #include "sound_tester.h"
7 #define BIG_GOOM_DURATION 100
8 #define BIG_GOOM_SPEED_LIMIT 0.1f
10 #define ACCEL_MULT 0.95f
11 #define SPEED_MULT 0.99f
15 evaluate_sound (gint16 data[2][512], SoundInfo * info)
25 for (i = 0; i < 512; i += 2) {
26 if (incvar < data[0][i])
30 if (incvar > info->allTimesMax)
31 info->allTimesMax = incvar;
34 info->volume = (float) incvar / (float) info->allTimesMax;
35 memcpy (info->samples[0], data[0], 512 * sizeof (short));
36 memcpy (info->samples[1], data[1], 512 * sizeof (short));
38 difaccel = info->accelvar;
39 info->accelvar = info->volume; /* accel entre 0 et 1 */
41 /* transformations sur la vitesse du son */
42 if (info->speedvar > 1.0f)
43 info->speedvar = 1.0f;
45 if (info->speedvar < 0.1f)
46 info->accelvar *= (1.0f - (float) info->speedvar);
47 else if (info->speedvar < 0.3f)
48 info->accelvar *= (0.9f - (float) (info->speedvar - 0.1f) / 2.0f);
50 info->accelvar *= (0.8f - (float) (info->speedvar - 0.3f) / 4.0f);
52 /* adoucissement de l'acceleration */
53 info->accelvar *= ACCEL_MULT;
54 if (info->accelvar < 0)
57 difaccel = info->accelvar - difaccel;
61 /* mise a jour de la vitesse */
62 prevspeed = info->speedvar;
63 info->speedvar = (info->speedvar + difaccel * 0.5f) / 2;
64 info->speedvar *= SPEED_MULT;
65 info->speedvar = (info->speedvar + 3.0f * prevspeed) / 4.0f;
66 if (info->speedvar < 0)
68 if (info->speedvar > 1)
72 info->timeSinceLastGoom++;
73 info->timeSinceLastBigGoom++;
76 /* detection des nouveaux gooms */
77 if ((info->speedvar > (float) IVAL (info->biggoom_speed_limit_p) / 100.0f)
78 && (info->accelvar > info->bigGoomLimit)
79 && (info->timeSinceLastBigGoom > BIG_GOOM_DURATION)) {
80 info->timeSinceLastBigGoom = 0;
83 if (info->accelvar > info->goom_limit) {
84 /* TODO: tester && (info->timeSinceLastGoom > 20)) { */
86 info->timeSinceLastGoom = 0;
87 info->goomPower = info->accelvar - info->goom_limit;
90 if (info->accelvar > info->prov_max)
91 info->prov_max = info->accelvar;
93 if (info->goom_limit > 1)
96 /* toute les 2 secondes : vérifier si le taux de goom est correct
97 * et le modifier sinon.. */
98 if (info->cycle % 64 == 0) {
99 if (info->speedvar < 0.01f)
100 info->goom_limit *= 0.91;
101 if (info->totalgoom > 4) {
102 info->goom_limit += 0.02;
104 if (info->totalgoom > 7) {
105 info->goom_limit *= 1.03f;
106 info->goom_limit += 0.03;
108 if (info->totalgoom > 16) {
109 info->goom_limit *= 1.05f;
110 info->goom_limit += 0.04;
112 if (info->totalgoom == 0) {
113 info->goom_limit = info->prov_max - 0.02;
115 if ((info->totalgoom == 1) && (info->goom_limit > 0.02))
116 info->goom_limit -= 0.01;
119 info->goom_limit * (1.0f +
120 (float) IVAL (info->biggoom_factor_p) / 500.0f);
124 /* mise a jour des parametres pour la GUI */
125 FVAL (info->volume_p) = info->volume;
126 info->volume_p.change_listener (&info->volume_p);
127 FVAL (info->speed_p) = info->speedvar * 4;
128 info->speed_p.change_listener (&info->speed_p);
129 FVAL (info->accel_p) = info->accelvar;
130 info->accel_p.change_listener (&info->accel_p);
132 FVAL (info->goom_limit_p) = info->goom_limit;
133 info->goom_limit_p.change_listener (&info->goom_limit_p);
134 FVAL (info->goom_power_p) = info->goomPower;
135 info->goom_power_p.change_listener (&info->goom_power_p);
136 FVAL (info->last_goom_p) = 1.0 - ((float) info->timeSinceLastGoom / 20.0f);
137 info->last_goom_p.change_listener (&info->last_goom_p);
138 FVAL (info->last_biggoom_p) =
139 1.0 - ((float) info->timeSinceLastBigGoom / 40.0f);
140 info->last_biggoom_p.change_listener (&info->last_biggoom_p);
142 /* bigGoomLimit ==goomLimit*9/8+7 ? */