Supprimer 'test2.cpp'
This commit is contained in:
parent
b957ceedd0
commit
ab591aff5a
1 changed files with 0 additions and 100 deletions
100
test2.cpp
100
test2.cpp
|
@ -1,100 +0,0 @@
|
|||
void TraitementSonsSuivants() {
|
||||
SAMPLE_TYPE* bufs[3];
|
||||
bufs[0] = _TamponDroit;
|
||||
bufs[1] = _TamponGauche;
|
||||
bufs[2] = _TamponAvant;
|
||||
int err;
|
||||
if ((err = snd_pcm_readn(_capture_handle, (void**) bufs, _TailleTampon))!= _TailleTampon) {
|
||||
fprintf(stderr, "Echec de la lecture de l'interface audio (%s)\n",snd_strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// compute the sound level (i.e. "loudness" of the sound):
|
||||
SAMPLE_TYPE Niveau = CalculNiv(_TamponDroit, _TamponGauche, _TamponAvant);
|
||||
// update the average sound level with this new measure:
|
||||
_MoyNivSonore->nvelleValeur(Niveau);
|
||||
// relative sound level of this sample compared to average:
|
||||
float NivRelatif = (float) Niveau / (float) _MoyNivSonore->getMean();
|
||||
//cout << "level " << level << ", relative " << NivRelatif << endl;
|
||||
|
||||
int minDiff = INT_MAX;
|
||||
int minDiff2 = INT_MAX;
|
||||
int minDiff3 = INT_MAX;
|
||||
int minDiffTime = -1;
|
||||
int minDiffTime2 = -1;
|
||||
int minDiffTime3 = -1;
|
||||
// glisse sur l'axe du temps pour trouver la différence sonore minimum entre les microphones Droit et Gauche
|
||||
for (int t = -_nbEchantillonsDiffMax; t < _nbEchantillonsDiffMax; t++) {
|
||||
// calcule la somme des différences pour simuler une mesure de corrélation croisée:
|
||||
int diff = 0;
|
||||
for (int i = _nbEchantillonsDiffMax; i < _TailleTampon - _nbEchantillonsDiffMax - 1; i++) {
|
||||
diff += abs(_TamponGauche[i] - _TamponDroit[i + t]);
|
||||
diff2 += abs(_TamponGauche[i] - _TamponAvant[i + t]);
|
||||
diff3 += abs(_TamponAvant[i] - _TamponDroit[i + t]);
|
||||
}
|
||||
if (diff < minDiff) {
|
||||
minDiff = diff;
|
||||
minDiffTime = t;
|
||||
}
|
||||
if (diff2 < minDiff2) {
|
||||
minDiff2 = diff2;
|
||||
minDiffTime2 = t;
|
||||
}
|
||||
if (diff3 < minDiff3) {
|
||||
minDiff3 = diff3;
|
||||
minDiffTime3 = t;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (minDiffTime<minDiffTime2 && minDiffTime<minDiffTime3) {
|
||||
// Si le son est assez fort et pas extrême (= ce qui entraine généralement de fausses
|
||||
// mesures), alors on le dessine:
|
||||
if ((NivRelatif > _NiveauSonMin) && (minDiffTime > -_nbEchantillonsDiffMax) && (minDiffTime < _nbEchantillonsDiffMax)) {
|
||||
// computation of angle depending on diff time, sampling rates,
|
||||
// and geometry
|
||||
float angle = -(float) asin((minDiffTime * _Vson) / (_TauxEchantillonnageSon* _DistanceMic));
|
||||
cout << angle << ";" << NivRelatif << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (minDiffTime2<minDiffTime && minDiffTime2<minDiffTime3) {
|
||||
// Si le son est assez fort et pas extrême (= ce qui entraine généralement de fausses
|
||||
// mesures), alors on le dessine:
|
||||
if ((NivRelatif > _NiveauSonMin) && (minDiffTime2 > -_nbEchantillonsDiffMax) && (minDiffTime2 < _nbEchantillonsDiffMax)) {
|
||||
// computation of angle depending on diff time, sampling rates,
|
||||
// and geometry
|
||||
float angle = -(float) asin((minDiffTime2 * _Vson) / (_TauxEchantillonnageSon* _DistanceMic));
|
||||
cout << angle << ";" << NivRelatif << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (minDiffTime3<minDiffTime && minDiffTime3<minDiffTime2) {
|
||||
// Si le son est assez fort et pas extrême (= ce qui entraine généralement de fausses
|
||||
// mesures), alors on le dessine:
|
||||
if ((NivRelatif > _NiveauSonMin) && (minDiffTime3 > -_nbEchantillonsDiffMax) && (minDiffTime3 < _nbEchantillonsDiffMax)) {
|
||||
// computation of angle depending on diff time, sampling rates,
|
||||
// and geometry
|
||||
float angle = -(float) asin((minDiffTime3 * _Vson) / (_TauxEchantillonnageSon* _DistanceMic));
|
||||
cout << angle << ";" << NivRelatif << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcule du niveau sonore moyen (la puissance) pour les canaux gauche et droit.
|
||||
*/
|
||||
SAMPLE_TYPE CalculNiv(SAMPLE_TYPE Droit[], SAMPLE_TYPE Gauche[], SAMPLE_TYPE Avant[]) {
|
||||
float Niveau = 0;
|
||||
for (int i = 0; i < _TailleTampon; i++) {
|
||||
float s = (Gauche[i] + Droit[i]+ Avant[i]) / 3;
|
||||
Niveau += (s * s);
|
||||
}
|
||||
Niveau /= _TailleTampon;
|
||||
Niveau = sqrt(Niveau);
|
||||
return (SAMPLE_TYPE) Niveau;
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue