|
Wave Arts VQE
1.00
Voice Quality Enhancement
|
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 */ 00023 #ifndef _WA_AUDIO_DEV_H 00024 #define _WA_AUDIO_DEV_H 00025 00026 #include <stdlib.h> 00027 #include "WaPlatform.h" 00028 00033 typedef enum { 00034 WadUnknownFmt = 0, 00035 WadInt16, 00036 WadFloat32 00037 } WadSampFmt; 00038 00041 typedef enum { 00042 WadPriorityNorm, 00043 WadPriorityHigh, 00044 WadPriorityMax 00045 } WadPriority; 00046 00052 typedef struct { 00053 WadSampFmt sampFmt; 00054 int numChan; 00055 int sampRate; 00056 int framesPerBuf; 00057 } WadStreamFormat; 00058 00060 #define WadSampSize(sampFmt) ((sampFmt == WadInt16) ? sizeof(short) : sizeof(float)) 00061 00070 typedef struct { 00071 int inDev; 00072 WadStreamFormat inFmt; 00073 int outDev; 00074 WadStreamFormat outFmt; 00075 WadPriority priority; 00076 int inBufTimeMsec; 00077 int outBufTimeMsec; 00078 } WadParam; 00079 00081 #define WAD_NAME_LEN 64 00082 00085 typedef struct { 00086 int numInChan; 00087 int numOutChan; 00088 char name[WAD_NAME_LEN]; 00089 } WadDevInfo; 00090 00102 typedef int WadCallbackFn(void *buf, WadStreamFormat *fmt, void *arg); 00103 00104 #define WAD_MAX_ERROR_TEXT 128 00105 00111 enum WadStatus { 00112 WAD_OK = 0, 00113 WAD_ERR_INTERNAL, 00114 WAD_ERR_UNSUPPORTED, 00115 WAD_ERR_INVALID_ARG, 00116 WAD_ERR_NOT_INITIALIZED, 00117 WAD_ERR_NOT_OPEN, 00118 WAD_ERR_INVALID_DEVICE, 00119 // Use GetClosestFormat() to return suggestions for unsupported formats 00120 WAD_ERR_IN_FORMAT, 00121 WAD_ERR_OUT_FORMAT, 00122 // more detail... 00123 WAD_ERR_IN_SAMPRATE, 00124 WAD_ERR_OUT_SAMPRATE, 00125 WAD_ERR_IN_NUMCHAN, 00126 WAD_ERR_OUT_NUMCHAN, 00127 WAD_ERR_IN_SAMPFORMAT, 00128 WAD_ERR_OUT_SAMPFORMAT, 00129 WAD_ERR_IN_FRAMESPERBUF, 00130 WAD_ERR_OUT_FRAMESPERBUF, 00131 }; 00132 00133 // Up to here definitions are C compatible. They used to be in a separate 00134 // file in case C code wanted to interact with the API. That's why 00135 // the callback returns int rather than bool. 00136 00137 00140 typedef enum { 00141 WadAPI_None, 00142 WadAPI_File, 00143 WadAPI_WinMME, 00144 WadAPI_WinWASAPI, 00145 WadAPI_MacHAL 00146 } WadAPI; 00147 00148 class WaAudioDev; 00149 00199 class WaAudioDevPort { 00200 public: 00201 WaAudioDevPort() {} 00202 virtual ~WaAudioDevPort() {} 00203 00218 virtual int Open(WadParam *param, WadCallbackFn *inFn, WadCallbackFn *outFn, void *arg) = 0; 00219 00224 virtual int Start() = 0; 00225 00230 virtual int Stop() = 0; 00231 00238 virtual void Wait() = 0; 00239 00246 virtual void Close() = 0; 00247 00252 virtual bool IsOpen() = 0; 00253 00258 virtual WaAudioDev *GetDevice() = 0; 00259 }; 00260 00261 // options for WadMake 00262 #define WAD_MAKE_MME 0x01 //!< make MME interface, even on Vista and Win7 00263 #define WAD_MAKE_FILE 0x02 //!< make file interface, usually for testing 00264 00289 class WaAudioDev : public WaAudioDevPort { 00290 public: 00291 WaAudioDev(); 00292 virtual ~WaAudioDev(); 00293 00298 virtual WadAPI GetAPI() = 0; 00299 00308 virtual int Init() = 0; 00309 00314 virtual int GetNumDevices(int *pNumDev) = 0; 00315 00321 virtual int GetDevInfo(int devId, WadDevInfo *pInfo) = 0; 00322 00327 virtual int GetDefaultInDevId(int *pId) = 0; 00328 00333 virtual int GetDefaultOutDevId(int *pId) = 0; 00334 00339 void SetMeteringEnable(bool enable); 00340 00348 bool GetInPeak(float *pPeakVal); 00349 00357 bool GetOutPeak(float *pPeakVal); 00358 00363 float GetLastInPeak(); 00364 00369 float GetLastOutPeak(); 00370 00375 void ResetMetering(); 00376 00377 // helper functions 00387 static float PeakToDb(float peak, float minDb, float maxDb); 00388 00394 static int CalcPeakInt16(short *buf, unsigned int numSamps); 00395 00401 static float CalcPeakFloat32(float *buf, unsigned int numSamps); 00402 00403 // 00404 // Instead of a generalized property interface, we provide methods to 00405 // get and set individual properties. By default they are unsupported. 00406 // 00407 00417 virtual int SetVol(int devId, bool isOutput, float vol); 00418 00428 virtual int GetVol(int devId, bool isOutput, float *pVol); 00429 00439 virtual int GetBufTime(bool isOutput, int *pBufTimeMsec); 00440 00451 virtual int GetClosestFormat(bool isOutput, WadStreamFormat *pFormat); 00452 00460 WaAudioDev *GetDevice(); 00461 00471 virtual char *GetErrorText(); 00472 00474 bool IsInitialized(); 00476 bool IsOpen(); 00478 bool IsInOpen(); 00480 bool IsOutOpen(); 00481 00490 virtual bool IsRunning() = 0; 00491 00499 void SetErrorText(char *text); 00500 00509 static WaAudioDev *WadMake(int options); 00510 00511 #if WA_WINDOWS 00512 00513 static bool IsVistaOrAbove(); 00514 #endif 00515 00516 protected: 00517 // metering 00518 // implementations can call these to do the peak detection 00520 void ProcInPeakInt16(short *buf, unsigned int numSamps); 00522 void ProcInPeakFloat32(float *buf, unsigned int numSamps); 00524 void ProcOutPeakInt16(short *buf, unsigned int numSamps); 00526 void ProcOutPeakFloat32(float *buf, unsigned int numSamps); 00528 void SetIsInitialized(bool isInitialized); 00529 00530 // peak metering 00532 float inPeak; 00534 float lastInPeak; 00536 float outPeak; 00538 float lastOutPeak; 00540 bool inPeakIsValid; 00542 bool outPeakIsValid; 00543 00545 WadParam param; 00547 bool isInitialized; 00549 bool isMeteringEnabled; 00551 bool isOpen; 00553 char errorText[WAD_MAX_ERROR_TEXT]; 00554 }; 00555 00556 00567 class WaAudioDevPortObj : public WaAudioDevPort { 00568 protected: 00569 WaAudioDevPort *devPort; 00570 public: 00571 WaAudioDevPortObj(WaAudioDevPort *devPort); 00572 virtual ~WaAudioDevPortObj(); 00573 // partial implementation of WaAudioDevPort 00574 int Start(); 00575 int Stop(); 00576 void Wait(); 00577 WaAudioDev *GetDevice(); 00578 bool IsOpen(); 00579 // 00581 // 00582 virtual void Reset(); 00583 }; 00584 00585 #endif
1.7.5.1