Wave Arts VQE  1.00
Voice Quality Enhancement
AecObjects.h
Go to the documentation of this file.
00001 /*
00002  * This file is part of the Wave Arts VQE library.
00003  * Copyright (C) 2011 Wave Arts, Inc. (http://wavearts.com)
00004  *
00005  * VQE is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * VQE is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * A copy of the GNU General Public License is included with VQE,
00016  * and can be found online at <http://www.gnu.org/licenses/>.
00017  *
00018  * If you'd like to distribute a closed-source product which uses VQE,
00019  * you must obtain a commercial VQE license from Wave Arts.
00020  */
00021 //
00022 // AEC class objects and calibrator. The calibrator could be put in
00023 // a separate file which would eliminate this file's dependency on WaAudioDev.h.
00024 //
00025 
00026 
00031 #ifndef _AEC_OBJECTS_H
00032 #define _AEC_OBJECTS_H
00033 
00034 #include "WaAudioDev.h"
00035 #include "AecCal.h"
00036 #include "AecLatCal.h"
00037 #include "Aes.h"
00038 #include "Aec.h"
00039 #include "WaList.h"
00040 
00043 class AecProcessor {
00044 public:
00046         virtual ~AecProcessor();
00047 
00069         virtual void Process(float *refBuf, float *recBuf, int n) = 0;
00070 
00080         virtual void Reset(bool isHard) = 0;
00081 
00093         virtual void SetLatency(int latency);
00094 };
00095 
00096 
00097 //=============================================================================
00098 
00100 typedef struct {
00101         char inDevName[128];    
00102         char outDevName[128];   
00103         int sampRate;                   
00104         int latency;                    
00105 } AecLatData;
00106 
00108 typedef struct AecLatDataItem_tag {
00109         struct AecLatDataItem_tag *next;        
00110         AecLatData data;                                        
00111 } AecLatDataItem;
00112 
00113 class AecLatencyCache {
00114 public:
00115         static AecLatencyCache *GetInstance();
00116         bool GetData(AecLatData *data);
00117         void SetData(AecLatData *data);
00118 private:
00119         AecLatencyCache();
00120         bool EqualData(AecLatData *a, AecLatData *b);
00127         AecLatData *FindData(AecLatData *data);
00128         LIST list;
00129 };
00130 
00131 //=============================================================================
00132 
00138 class AecLatCalObject : public AecProcessor {
00139 public:
00145         AecLatCalObject(AecLatCalParam *param, AecProcessor *aec);
00147         ~AecLatCalObject();
00148         void Process(float *refBuf, float *recBuf, int n);
00149         void Reset(bool isHard);
00151         AecLatCal *GetLatCal();
00153         bool GetLatency(int *pLatency);
00154 protected:
00155         AecLatCal *latCal;      
00156         AecProcessor *aec;      
00157         bool isComplete;        
00158         int latency;            
00159 };
00160 
00161 //=============================================================================
00162 
00167 class AesObject : public AecProcessor {
00168 public:
00173         AesObject(AesParam *param);
00174         ~AesObject();
00175         void Process(float *refBuf, float *recBuf, int n);
00176         void Reset(bool isHard);
00177         void SetLatency(int latency);
00179         Aes *GetAes();
00180 
00181 protected:
00182         Aes *aes;       
00183 };
00184 
00185 
00186 //=============================================================================
00187 
00188 
00193 class AecObject : public AecProcessor {
00194 public:
00199         AecObject(AecParam *param);
00201         ~AecObject();
00202         void Process(float *refBuf, float *recBuf, int n);
00203         void Reset(bool isHard);
00204         void SetLatency(int latency);
00205         Aec *GetAec();  
00206 
00207 protected:
00208         Aec *aec;       
00209 };
00210 
00211 //=============================================================================
00212 
00218 typedef struct {
00219         CalParam calParam;              
00220         bool tryUpsampling;             
00221         double syncThresh;              
00222 } AecCalibratorParam;
00223 
00234 typedef void AecCalibratorRecFn(void *arg, float *buf, int n, int sampRate);
00235 
00262 class AecCalibrator {
00263 public:
00269         AecCalibrator(WaAudioDev *dev, AecCalibratorParam *calibParam);
00270 
00272         ~AecCalibrator();
00273 
00289         AecCalErr Calibrate(WadParam *param, AecSyncParam *syncParam, float inVol, float outVol);
00290 
00292         int InCallback(float *buf, int numFrames, int numChan);
00294         int OutCallback(float *buf, int numFrames, int numChan);
00295 
00303         void GetLastResults(CalResults *pResults);
00304 
00307         void SetRecCallback(AecCalibratorRecFn *fn, void *arg);
00308 
00312         static void GetDefaultParam(AecCalibratorParam *calibParam);
00313 
00314 protected:
00315         WaAudioDev *dev;        
00316         float inVol;            
00317         float outVol;           
00318         float *playBuf;         
00319         int playLen;            
00320         int playIndex;          
00321         float *recBuf;          
00322         int recLen;                     
00323         int recIndex;           
00324         AecCalibratorParam calibParam;  
00325         CalResults results;     
00326         AecCalibratorRecFn *recFn;      
00327         void *arg;                      
00328 
00330         bool TryUpsampling();
00332         bool IsSynchronized(double ratio);
00334         AecCalErr CalDeviceAtRateBufs(WadParam *param, int devSampRate, CalResults *results);
00336         AecCalErr CalDeviceAtRate(WadParam *param, int devSampRate, CalResults *results);
00337 };
00338 
00339 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines