Wave Arts VQE  1.00
Voice Quality Enhancement
WadMme.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 // WaAudioDev C++ wrapper around MME audio functions.
00023 // Original MME code from 1998 wavio.
00024 //
00025 // Bill Gardner, Oct, 2010
00026 //
00027 
00034 
00035 
00036 #ifndef _WAD_MME_H
00037 #define _WAD_MME_H
00038 
00039 #include <windows.h>
00040 #include "WaAudioDev.h"
00041 #include "WaList.h"
00042 #include "MMSystem.h"
00043 
00048 typedef struct {
00049         WadDevInfo info;        
00050         int id;                         
00051 } WadMmeDevInfo;
00052 
00053 
00059 class WadMme : public WaAudioDev {
00060 protected:
00061 
00062         void *m_OutBuf;         
00063         void *m_InBuf;          
00064         HANDLE m_QuitEvent;     
00065         HANDLE m_ThreadHandle;  
00066 
00067         // device table
00068         WadMmeDevInfo *m_Devs;  
00069         int m_NumDevs;                  
00070 
00071         // input vars
00072         bool m_InIsOpen;        
00073         int m_InBufLen;         
00074         int m_NumInBuf;         
00075         LIST m_InList;          
00076         LIST m_InItemList;      
00077         HWAVEIN m_In;           
00078         WAVEHDR *m_InWHdr;      
00079 
00080         // output vars
00081         bool m_OutIsOpen;       
00082         int m_OutBufLen;        
00083         int m_NumOutBuf;        
00084         LIST m_OutList;         
00085         LIST m_OutItemList;     
00086         HWAVEOUT m_Out;         
00087         WAVEHDR *m_OutWHdr;     
00088 
00089         void *m_Arg;            
00090         WadCallbackFn *m_InFn;  
00091         WadCallbackFn *m_OutFn; 
00092 
00093         //
00096         //
00097         CRITICAL_SECTION m_OutBufLock;
00098 
00099         //
00103         //
00104         HANDLE m_OutputReadyEvent;
00105 
00106         //
00109         //
00110         CRITICAL_SECTION m_InBufLock;
00111 
00112         //
00117         //
00118         HANDLE m_InputReadyEvent;
00119 
00120         // internal methods
00121         void Release();                         
00122         void CloseInternal();           
00123         bool Prime();                           
00124         int GetMmeDevId(int devId);     
00125 
00126         // output methods
00128         bool WriteWHdr();
00130         void FreeOutWhdrItem(ITEM *item);
00132         void FreeOutBuffers();
00134         void CloseOut();
00136         int OpenWaveOut(int outDev, int sampRate, int numChan);
00138         int OpenOut(
00139                 int outDev,             // device
00140                 int sampRate,   // sampling rate
00141                 int numChan,    // number of channels, 1 or 2
00142                 WadSampFmt smpFmt,      // sample format
00143                 int numBuf,             // number of buffers to allocate in queue
00144                 int bufLen);    // buffer size in sample frames
00146         bool StartOut();
00148         bool StopOut();
00149 
00150         // input methods
00152         void FreeInWhdrItem(ITEM *item);
00154         void FreeInBuffers();
00156         void CloseIn();
00158         int OpenWaveIn(int inDev, int sampRate, int numChan);
00160         int OpenIn(
00161                 int inDev,              // input device
00162                 int sampRate,   // sampling rate
00163                 int numChan,    // number of channels, 1 or 2
00164                 WadSampFmt smpFmt,              // sample format
00165                 int numBuf,             // number of buffers to allocate in queue
00166                 int bufLen);    // buffer size in sample frames
00168         bool StartIn();
00170         bool StopIn();
00171 
00173         static bool AllocBufList(
00174                 int numBuf,             // number of buffers
00175                 int bufLen,             // number of samples (not frames) in buffer
00176                 int sampBytes,  // size of a sample in bytes
00177                 LIST *list);            // pointer to list
00178 
00179 public:
00181         WadMme();
00183         ~WadMme();
00184         WadAPI GetAPI();
00185         int Init();
00186 
00187         // implement WaAudioDev
00188         int GetNumDevices(int *pNumDev);
00189         int GetDevInfo(int devId, WadDevInfo *pInfo);
00190         int GetDefaultInDevId(int *pId);
00191         int GetDefaultOutDevId(int *pId);
00192         int Open(WadParam *param, WadCallbackFn *inFn, WadCallbackFn *outFn, void *arg);
00193         int Start();
00194         int Stop();
00195         void Close();
00196         void Wait();
00197         int SetVol(int devId, bool isOutput, float vol);
00198         int GetVol(int devId, bool isOutput, float *pVol);
00199         int GetBufTime(bool isOutput, int *pBufTimeMsec);
00200         bool IsRunning();
00201         bool IsInOpen();
00202         bool IsOutOpen();
00203         
00205         void WaveOutProc(
00206                 HWAVEOUT hwo,
00207                 UINT uMsg,
00208                 DWORD dwInstance,
00209                 DWORD dwParam1,
00210                 DWORD dwParam2);
00212         void WaveInProc(
00213                 HWAVEIN hwi,
00214                 UINT uMsg,
00215                 DWORD dwInstance,
00216                 DWORD dwParam1,
00217                 DWORD dwParam2);
00219         DWORD Thread(void *arg);
00220 };
00221 
00222 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines