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]); } if (diff < minDiff) { minDiff = diff; minDiffTime = t; } } for (int t2 = -_nbEchantillonsDiffMax; t2 < _nbEchantillonsDiffMax; t2++) { int diff2 = 0; for (int i = _nbEchantillonsDiffMax; i < _TailleTampon - _nbEchantillonsDiffMax - 1; i++) { diff2 += abs(_TamponGauche[i] - _TamponAvant[i + t2]); } if (diff2 < minDiff2) { minDiff2 = diff2; minDiffTime2 = t2; } } for (int t3 = -_nbEchantillonsDiffMax; t3 < _nbEchantillonsDiffMax; t3++) { int diff3 = 0; for (int i = _nbEchantillonsDiffMax; i < _TailleTampon - _nbEchantillonsDiffMax - 1; i++) { diff3 += abs(_TamponAvant[i] - _TamponDroit[i + t3]); } if (diff3 < minDiff3) { minDiff3 = diff3; minDiffTime3 = t3; } } if (t _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 (t2 _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 (t3 _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; } };