/* ---------------------------------------------------------------------------- WAVES.hpp Contains a wave object, the base component of a waveform. The wave object 'operates' on a supplied memory location, it does not own the memory containing the waveform. In this way an arbitrary structure containing the actual waveform values can be passed to FFT's or sound buffers completely independent from its associated WAVE object. As you would expect, waveforms can be added, subtracted and assigned. A WAVE can be copied: HOWEVER only the operator parameters are in fact copied, the existing memory which the wave operator is attached to is not copied. In order that waveforms may be modfied quickly and efficiently during the high speed NULL search, the "make" method calculates and stores the base waveform in two arrays allocated dynamically by the "make" method. COSbase and SINbase. Where COSbase = cos( wt + Phase ); New wave forms are then calculated as: A * ( C1 * COSbase[t] + C2 * SINbase[t] ) and require only multiplication and add operations, NO trig functions or complex operations are requried after the initial calculations of COSbase & SINbase. Some typical call sequences are given below: WAVE wave1 ,wave2 ,wave3;// Construction taking defaults WAVE waveTX; wave1.link( &data.wave1 ); // Links waveform operator to memory wave1.make( 256 ,0.5 ,0.0 ); // Creates the waveform (24bits left justified in 32bits) wave2.link( &data.wave2 ); wave2.make( 258 ,0.6 ,0.0 ); wave3.link( &data.wave3 ); wave3.make( 254 ,0.6 ,0.0 ); waveTX.link( &data.waveTX ); waveTX = wave1 + wave2 + wave3; waveTX = 0.9 * waveTX + 0.077; // This would also be nice */ #ifndef _WAVE_ #define _WAVE_ #include "misctyps.h" #include "globals.h" #include "matrix.hpp" #include "fundtypes.h" #define WAVE_SIZE ( 4 * FAST_FFT_SZ ) #define CYCLEINTERCEPT 21.75154568 // Paste these from Latency.xls #define CYCLESLOPE -0.002125175 class WAVE { //------------- Class construction/destruction public: WAVE ( void ); WAVE ( uint unWaveLength ); WAVE ( void *pvMem ); WAVE ( VECTOR &Tones ,uInt16 *pBins ); WAVE ( void *pvMem ,VECTOR &Tones ,uInt16 *pBins ); WAVE ( WAVE &refWAVE ); WAVE ( WAVE *pWAVE ); ~WAVE ( void ); //------------- Class overloaded operators WAVE &operator += ( WAVE &rhs ); // rhs means right hand side of equation WAVE operator + ( WAVE &rhs ); // Addition operator WAVE &operator -= ( WAVE &rhs ); WAVE operator - ( void ); // Negation or unary minus WAVE operator - ( WAVE &rhs ); // Subtraction WAVE &operator = ( WAVE &rhs ); // Assignment operator /* friend WAVE operator * ( WAVE &lhs ,double Amp ); friend WAVE operator * ( double Amp ,WAVE &rhs ); friend WAVE operator *= ( double Amp ); friend WAVE operator / ( WAVE &lhs ,double Amp ); friend WAVE operator / ( double Amp ,WAVE &rhs ); friend WAVE operator /= ( double Amp ); */ //------------- Class methods void wave ( void ); // Common construction void make ( void ); // Calculates a waveform void link ( void *pWave ); // Links waveform to memory location void modify ( VECTOR &Tones ,uInt16 *pBins ); // Changes a waveform void modify ( float *pfWAVE ); // Changes a waveform void convert ( WAVEPTR pWAVEtoConvert ,long WaveLen ); // Converts binary waveform to floating point waveform void show ( uint NumPtsToShow ); // Prints out part of a waveform void show ( void ); // dumps whole waveform private: void Init ( void *pvMem ,VECTOR &Tones ,uInt16 *pBins ); // Performs common initialization void copy ( WAVE *pWAVE ); // Workhorse copy construction //------------- Member variables public: VECTOR m_Tones; // Vector of tones describing the waveform uInt16 *m_pBins; // List of FFT bins (@ fast FFT size) WAVEPTR m_pWAVE ,m_pWVcopy; // Ultimate storage of the waveform uint m_Init; // Flag for tracking initialization //------------- Global to all waveforms, otherwise +/-/= become fuzzy or at least overly awkward static uint g_Width; // Total bit width of waveform static int g_Shifts; // Justification of waveform static long g_Len; // Length of waveform for all wave objects static uint g_Count; // Instantiation count private: }; #endif