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

SpectDir.cc

Go to the documentation of this file.
00001 /*
00002 
00003     Direction calculation from spectrum
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 
00027 #include "SpectDir.hh"
00028 
00029 
00030 clSpectDir::clSpectDir ()
00031 {
00032     lDirCount = 0;
00033     fpDirections = NULL;
00034     fPI = acos(-1.0);
00035     fHalfPI = asin(1.0);
00036 }
00037 
00038 
00039 clSpectDir::~clSpectDir ()
00040 {
00041 }
00042 
00043 
00044 void clSpectDir::SetSensorSpacing (GDT fSpacing)
00045 {
00046     fSensorSpacing = fSpacing;
00047 }
00048 
00049 
00050 void clSpectDir::SetSoundSpeed (GDT fSoundSpeed)
00051 {
00052     fArrayFreq = fSoundSpeed / fSensorSpacing / 2;
00053 }
00054 
00055 
00056 GDT clSpectDir::GetDirection (GDT fFrequency, GDT fDPhase)
00057 {
00058     GDT fDf;
00059     GDT fDirection;
00060 
00061     fDf = fArrayFreq / fFrequency;
00062     fDirection = fDf * (fDPhase / 2);
00063     return fDirection;
00064 }
00065 
00066 
00067 void clSpectDir::SetDirectionCount (long lCount)
00068 {
00069     lDirCount = lCount;
00070     fpDirections = (GDT *) DirBuf.Size(lDirCount * sizeof(GDT));
00071     DSP.Zero(fpDirections, lDirCount);
00072 }
00073 
00074 
00075 void clSpectDir::SetDirection (GDT fFrequency, GDT fLevel, GDT fDPhase)
00076 {
00077     long lFreqIdx;
00078     GDT fDirection;
00079     GDT fDirRes;
00080 
00081     fDirection = GetDirection(fFrequency, fDPhase);
00082     fDirRes = lDirCount / fPI;
00083     lFreqIdx = DSP.Round(fDirection * fDirRes) + lDirCount / 2;
00084     if (lFreqIdx >= 0l && lFreqIdx < lDirCount)
00085         fpDirections[lFreqIdx] += fLevel;
00086 }
00087 
00088 
00089 GDT *clSpectDir::GetDirections (GDT *fpDest)
00090 {
00091     if (fpDest != NULL) DSP.Scale01(fpDest, fpDirections, lDirCount);
00092     return fpDirections;
00093 }
00094 
00095 
00096 void clSpectDir::ResetDirections ()
00097 {
00098     DSP.Zero(fpDirections, lDirCount);
00099 }
00100 

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