Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

LocateSensor.cc

Go to the documentation of this file.
00001 /*
00002 
00003     Sensor matrix processing for locating sound sources
00004     Copyright (C) 2000-2001 Jussi Laako
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 */
00021 
00022 
00023 #include <stdio.h>
00024 #include <math.h>
00025 #include <float.h>
00026 #include <string.h>
00027 
00028 #include "LocateSensor.hh"
00029 
00030 
00031 inline void clLocateSensor::Clear ()
00032 {
00033     memset(fpLocMatrix, 0x00, lWidth * lHeight * sizeof(GDT));
00034 }
00035 
00036 
00037 inline void clLocateSensor::SetValue (long lX, long lY, GDT fValue)
00038 {
00039     if (lX < 0 || lX >= lWidth) return;
00040     if (lY < 0 || lY >= lHeight) return;
00041     fpLocMatrix[lY * lWidth + lX] += fValue;
00042 }
00043 
00044 
00045 void clLocateSensor::SetDirection (GDT fDirection, GDT fLevel, GDT fFrequency)
00046 {
00047     long lX1;
00048     long lY1;
00049     long lX2 = 0;
00050     long lY2 = 0;
00051     GDT fDistance;
00052     GDT fThisDir;
00053     GDT fAbsCoeff;
00054     GDT fPropLoss;
00055     GDT fNewLevel;
00056 
00057     if (!b3D && (fDirection < -fHalfPI || fDirection > fHalfPI))
00058         return;
00059     fDistance = 1;
00060     fAbsCoeff = 0.05 * pow(fFrequency / 1000, 1.4);
00061     do {
00062         //fNewLevel = fLevel;
00063         fPropLoss = 15 * log10(fDistance) + fAbsCoeff * 
00064             fDistance * pow(10, -3);
00065         fNewLevel = fLevel * pow(10, fPropLoss / 20);
00066         fThisDir = fDirection + fAzimuth;
00067         lX1 = DSP.Round(sin(fThisDir) * fDistance) + lPosX;
00068         lY1 = DSP.Round(cos(fThisDir) * fDistance) + lPosY;
00069         SetValue(lX1, lY1, fNewLevel);
00070         if (!b3D)
00071         {
00072             fThisDir = fPI - fDirection + fAzimuth;
00073             lX2 = DSP.Round(sin(fThisDir) * fDistance) + lPosX;
00074             lY2 = DSP.Round(cos(fThisDir) * fDistance) + lPosY;
00075             SetValue(lX2, lY2, fNewLevel);
00076         }
00077         fDistance += 1;
00078     } while ((lX1 >= 0 && lX1 < lWidth && lY1 >= 0 && lY1 < lHeight) ||
00079         (lX2 >= 0 && lX2 < lWidth && lY2 >= 0 && lY2 < lHeight));
00080 }
00081 
00082 
00083 clLocateSensor::clLocateSensor ()
00084 {
00085     bInitialized = false;
00086     fPI = acos(-1.0);
00087     fHalfPI = acos(-1.0) / 2.0;
00088 }
00089 
00090 
00091 clLocateSensor::~clLocateSensor ()
00092 {
00093     if (bInitialized) Uninitialize();
00094 }
00095 
00096 
00097 bool clLocateSensor::Initialize (long lW, long lH, long lX, long lY, 
00098     GDT fA, bool bTD)
00099 {
00100     lWidth = lW;
00101     lHeight = lH;
00102     lPosX = lX;
00103     lPosY = lY;
00104     fAzimuth = -fA;
00105     b3D = bTD;
00106     try 
00107     {
00108         fpLocMatrix = (GDT *) LocMatrix.Size(lWidth * lHeight * sizeof(GDT));
00109     } 
00110     catch (...)
00111     {
00112         return false;
00113     }
00114     Clear();
00115     return true;
00116 }
00117 
00118 
00119 void clLocateSensor::Uninitialize ()
00120 {
00121     // NOP
00122 }
00123 
00124 
00125 void clLocateSensor::SetDirectionValues (const GDT *fpLevelValues, 
00126     const GDT *fpDirectionValues, long lValueCount,
00127     long lMinBin, long lMaxBin, GDT fFreqResolution)
00128 {
00129     long lValueCntr;
00130 
00131     Clear();
00132     for (lValueCntr = lMinBin; lValueCntr < lMaxBin; lValueCntr++)
00133     {
00134         /*printf("%f %f %f\n", fpDirectionValues[lValueCntr], 
00135             20 * log10(fpLevelValues[lValueCntr]),
00136             (GDT) lValueCntr * fFreqResolution);*/
00137         SetDirection(fpDirectionValues[lValueCntr], fpLevelValues[lValueCntr],
00138             (GDT) lValueCntr * fFreqResolution);
00139     }
00140 }
00141 

Generated on Sun Oct 26 19:11:21 2003 for HASAS by doxygen 1.3.3