Wave Arts VQE  1.00
Voice Quality Enhancement
WaVQE.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  */
00027 #ifndef _WA_VQE_H
00028 #define _WA_VQE_H
00029 
00030 #include "WaAudioDev.h"
00031 #include "AecCal.h"
00032 #include "AecObjects.h"
00033 #include "AFileMaker.h"
00034 #include "AutoGain.h"
00035 #include "DeclipLpf.h"
00036 #include "WaPlatform.h"
00037 
00273 /*
00274 @section sec_style Notes on coding style
00275 
00276 I'm basically a old school C/assembly programmer who adopted C++ for doing difficult
00277 object oriented tasks that demanded inheritance and virtual methods. Most low level
00278 signal processing and utility code I write in C out of habit. I quite like C++ and should probably
00279 start using it exclusively, but I am definitely not a C++ guru and I tend to use only a limited
00280 subset of features, e.g., I haven't started using signals and templates routinely. I'm also
00281 not obsessive about typing. I do strive to write readable and well commented code, because
00282 otherwise I can't understand what I've written.
00283 */
00284 
00285 //
00290 //
00291 #define USE_MEM_FILES           0
00292 #define MAX_MEM_FILE_TIME       30              //!< maximum of 30 second output files
00293 
00301 class AecInFifo {
00302 public:
00309         AecInFifo(int numBufs, int bufLen, int numChan);
00310 
00312         ~AecInFifo();
00313 
00320         bool WriteBuf(float *p);
00321 
00328         bool ReadBuf(float *p);
00329 
00331         float *GetReadBuf();
00333         float *GetLastReadBuf();
00335         int GetCount();
00337         int GetSize();
00339         void Reset();
00340 
00341 protected:
00342         float *buf;             
00343         int bufLen;             
00344         int numChan;    
00345         int bufLenSamps;        
00346         int numBufs;            
00347         int readIndex;          
00348         int writeIndex;         
00349         int count;                      
00350 };
00351 
00353 typedef enum {
00354         WaAlgNone,      
00355         WaAlgAEC,       
00356         WaAlgAES        
00357 } WaAECAlg;
00358 
00397 typedef struct {
00398         AecSyncParam syncParam; 
00399         WaAECAlg alg;                   
00400 
00401         union {
00402                 AecParam aecParam;
00403                 AesParam aesParam;
00404         } param;
00405         int fifoPrimeThresh;    
00406         int runCountThresh;     
00407         bool cacheLatency;      
00408         bool hasAutoGain;       
00409         AutoGainParam autoGainParam;    
00410         bool hasDeclip;         
00411         DeclipLpfParam declipParam;             
00412         bool matlabDump;        
00413         bool dumpFiles;         
00414         bool dumpResponse;      
00415         char in0Name[32];       
00416         char in1Name[32];       
00417         char out0Name[32];      
00418         char out1Name[32];      
00419         char dumpDir[256];      
00420 } VQEParam;
00421 
00422 #define kMaxBurst       5       //!< longest buffer burst to track
00423 
00441 class WaVQE : public WaAudioDevPortObj {
00442 public:
00448         WaVQE(WaAudioDevPort *devPort, VQEParam *vqeParam);
00450         ~WaVQE();
00451 
00453         VQEParam *GetParam();
00454         int Open(WadParam *param, WadCallbackFn *inFn, WadCallbackFn *outFn, void *arg);
00455         void Close();
00456 
00457         // Public so C callback can access.
00458         // Callbacks for normal streaming operation.
00460         int InCallback(float *buf, int numFrames, int numChan);
00462         int OutCallback(float *buf, int numFrames, int numChan);
00463 
00468         void SetAecEnable(bool isAecEnabled);
00469 
00475         void AutoGainSetFn(bool isIncr, float incr);
00476 
00481         static void GetDefaultParam(VQEParam *vqeParam);
00482         
00487         void SetAutoGainEnable(bool enable);
00488 
00493         void SetDeclipEnable(bool enable);
00494 
00508         void SetInjectNoise(bool enable);
00509 
00510 protected:
00512         void Reset();
00514         bool OpenDumpFile(AFileOut **pAfo, char *name, int sampRate, int numChan);
00516         void OpenDumpFiles(WadParam *param);
00518         void PreProcess(float *buf, int numFrames, int numChan);
00520         void PostProcess(float *buf, int numFrames, int numChan);
00522         void InjectShortNoise(short *buf, int n);
00524         void InjectFloatNoise(float *buf, int n);
00526         bool DeliverInputBuf(float *buf);
00528         bool FetchOutputBuf(float *buf);
00530         void MakeDumpPath(char *path, unsigned maxLen, char *name);
00532         void DumpResponse();
00534         void SetAecProcessor(AecProcessor *aec);
00536         void FillAecLatData(AecLatData *data);
00537 
00538         WaAudioDevPortObj *resPort;     
00539         WadParam param;                 
00540         VQEParam vqeParam;      
00541         bool syncBuffers;       
00542         AecLatCalObject *aecLatCal;     
00543         // this is a bit messy keeping both pointers, we could have latCal delete embedded aec
00544         AecProcessor *aecObj;   
00545         AecProcessor *aecProcessor;     
00546         WadCallbackFn *appInFn; 
00547         WadCallbackFn *appOutFn;        
00548         void *appArg;           
00549         bool isAecEnabled;      
00550         AecInFifo *inFifo;      
00551         bool isInputReady;      
00552         int overCount;          
00553         int underCount;         
00554         // optional file dumping
00555         AFileOut *afoIn0;               
00556         AFileOut *afoIn1;               
00557         AFileOut *afoOut0;              
00558         AFileOut *afoOut1;              
00559         int numIn;                              
00560         int numOut;                             
00561         int inHist[kMaxBurst];  
00562         int outHist[kMaxBurst]; 
00563         int totalNumIn;                 
00564         int totalNumOut;                
00565         int totalNumAppIn;              
00566         int totalNumAppOut;             
00567         int numUnder;                   
00568         int numOver;                    
00569         short *shortOutBuf;             
00570         short *shortInBuf;              
00571         float *lastRefBuf;              
00572         float *recBuf;                  
00573         AutoGain *autoGain;             
00574         bool isAutoGainEnabled; 
00575         DeclipLpf *declip;              
00576         bool isDeclipEnabled;   
00577         // MLS noise generation
00578         bool injectNoise;       
00579         int mlsReg;                     
00580         int mlsMask;            
00581         int mlsMsbMask;         
00582 };
00583 
00584 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines