00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_GLIBC
00024 #ifndef _ISOC9X_SOURCE
00025 #define _ISOC9X_SOURCE
00026 #endif
00027 #endif
00028
00029
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <math.h>
00033 #include <float.h>
00034
00035 #include "BeamDipole.hh"
00036
00037
00038 clBeamDipole::clBeamDipole (clArrayDipole *ArrayPtr, GDT fIntegrationTime,
00039 int iSampleRate, long lWindowSize, bool bEnableDebug)
00040 {
00041 long lSensCntr;
00042
00043 bDebug = bEnableDebug;
00044 Array = ArrayPtr;
00045 lWinSize = lWindowSize;
00046 lSampleCount = (long) ((GDT) iSampleRate * fIntegrationTime + (GDT) 0.5);
00047 if ((lSampleCount % lWinSize) > (lWinSize / 2))
00048 lSampleCount += lSampleCount % lWinSize;
00049 else
00050 lSampleCount -= lSampleCount % lWinSize;
00051 fIntTime = (GDT) lSampleCount / (GDT) iSampleRate;
00052 if (bDebug) printf("Integration time %f -> %f\n", fIntegrationTime,
00053 fIntTime);
00054 lBaseIdx = Array->GetMaxDelay();
00055 if (bDebug) printf("Integration buffers %li/%li samples (%li/%li bytes)\n",
00056 lSampleCount, lBaseIdx + lSampleCount,
00057 lSampleCount * (long) sizeof(GDT),
00058 (lBaseIdx + lSampleCount) * (long) sizeof(GDT));
00059 for (lSensCntr = 0; lSensCntr < 2; lSensCntr++)
00060 {
00061 Data[lSensCntr].Size((lBaseIdx + lSampleCount) * sizeof(GDT));
00062 DSPBank[lSensCntr].Zero((GDT *) Data[lSensCntr],
00063 lBaseIdx + lSampleCount);
00064 }
00065 }
00066
00067
00068 clBeamDipole::~clBeamDipole ()
00069 {
00070 }
00071
00072
00073 bool clBeamDipole::AddData ()
00074 {
00075 long lReBufRes;
00076 long lSensCntr;
00077 GDT *fpSensPtr;
00078
00079 for (lSensCntr = 0; lSensCntr < 2; lSensCntr++)
00080 {
00081 fpSensPtr = Data[lSensCntr];
00082 lReBufRes = DSPBank[lSensCntr].ReBuffer(&fpSensPtr[lBaseIdx],
00083 Array->GetFiltPtr(lSensCntr), lSampleCount, lWinSize);
00084 }
00085 if (lReBufRes >= 1) return true;
00086 return false;
00087 }
00088
00089
00090 GDT clBeamDipole::Process (GDT fDirection)
00091 {
00092 long lWorkCntr;
00093 long lDelay1;
00094 long lDelay2;
00095 GDT fWorkMix;
00096 GDT fWorkEnergy;
00097 GDT *fpDataPtr1;
00098 GDT *fpDataPtr2;
00099
00100 lDelay1 = Array->GetDelaySamples(0, fDirection);
00101 lDelay2 = Array->GetDelaySamples(1, fDirection);
00102 fpDataPtr1 = Data[0];
00103 fpDataPtr2 = Data[1];
00104 fWorkEnergy = (GDT) 0.0;
00105 for (lWorkCntr = 0; lWorkCntr < lSampleCount; lWorkCntr++)
00106 {
00107 fWorkMix = (fpDataPtr1[lBaseIdx - lDelay1 + lWorkCntr] +
00108 fpDataPtr2[lBaseIdx - lDelay2 + lWorkCntr]) * (GDT) 0.5;
00109 #ifndef _ISOC9X_SOURCE
00110 fWorkEnergy += fWorkMix * fWorkMix;
00111 #else
00112 #if (GDT == float)
00113 fWorkEnergy = fmaf(fWorkMix, fWorkMix, fWorkEnergy);
00114 #elif (GDT == double)
00115 fWorkEnergy = fma(fWorkMix, fWorkMix, fWorkEnergy);
00116 #else
00117 #error Unknown FP type
00118 #endif
00119 #endif
00120 }
00121 return (fWorkEnergy / (GDT) lSampleCount);
00122 }
00123
00124
00125 void clBeamDipole::SetHistory ()
00126 {
00127 long lSensCntr;
00128 GDT *fpDataPtr;
00129
00130 for (lSensCntr = 0; lSensCntr < 2; lSensCntr++)
00131 {
00132 fpDataPtr = Data[lSensCntr];
00133 DSPBank[lSensCntr].Copy(fpDataPtr, &fpDataPtr[lSampleCount],
00134 lBaseIdx);
00135 }
00136 }
00137
00138
00139 GDT clBeamDipole::GetPeakLevel ()
00140 {
00141 long lSensCntr;
00142 GDT fBufMin;
00143 GDT fBufMax;
00144 GDT fRealMax;
00145 GDT *fpDataPtr;
00146
00147 fRealMax = (GDT) 0.0;
00148 for (lSensCntr = 0; lSensCntr < 2; lSensCntr++)
00149 {
00150 fpDataPtr = Data[lSensCntr];
00151 DSPBank[lSensCntr].MinMax(&fBufMin, &fBufMax, &fpDataPtr[lBaseIdx],
00152 lSampleCount);
00153 fBufMin = (GDT) fabs(fBufMin);
00154 if (fBufMin > fRealMax) fRealMax = fBufMin;
00155 else if (fBufMax > fRealMax) fRealMax = fBufMax;
00156 }
00157 if (fRealMax > (GDT) 0.0)
00158 return ((GDT) (20.0 * log10(fRealMax)));
00159 return (-DIR_DB_SCALE);
00160 }
00161