|
Wave Arts VQE
1.00
Voice Quality Enhancement
|
WaAudioDev implemention of MME audio API. More...
#include <WadMme.h>
Public Member Functions | |
| WadMme () | |
| Creator. | |
| ~WadMme () | |
| Destructor. | |
| WadAPI | GetAPI () |
| return API enum | |
| int | Init () |
| initialize the OS API and discover all devices | |
| int | GetNumDevices (int *pNumDev) |
| Get the count of devices discovered. | |
| int | GetDevInfo (int devId, WadDevInfo *pInfo) |
| Get device information. | |
| int | GetDefaultInDevId (int *pId) |
| Get the default input device. | |
| int | GetDefaultOutDevId (int *pId) |
| Get the default output device. | |
| int | Open (WadParam *param, WadCallbackFn *inFn, WadCallbackFn *outFn, void *arg) |
| Open devices for streaming. | |
| int | Start () |
| Start streaming. | |
| int | Stop () |
| Stop streaming. | |
| void | Close () |
| Close devices and release memory. | |
| void | Wait () |
| Wait for stream to complete. | |
| int | SetVol (int devId, bool isOutput, float vol) |
| Set volume. | |
| int | GetVol (int devId, bool isOutput, float *pVol) |
| Get volume. | |
| int | GetBufTime (bool isOutput, int *pBufTimeMsec) |
| Get buffer time. | |
| bool | IsRunning () |
| Test if stream I/O thread is running. | |
| bool | IsInOpen () |
| return T/F if device is open for input streaming | |
| bool | IsOutOpen () |
| return T/F if device is open for output streaming | |
| void | WaveOutProc (HWAVEOUT hwo, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) |
| output callback from MME | |
| void | WaveInProc (HWAVEIN hwi, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) |
| input callback from MME | |
| DWORD | Thread (void *arg) |
| thread entry | |
Protected Member Functions | |
| void | Release () |
| release memory | |
| void | CloseInternal () |
| close | |
| bool | Prime () |
| prime output with zeros | |
| int | GetMmeDevId (int devId) |
| get the MME device ID for given WaAudioDev ID | |
| bool | WriteWHdr () |
| Write current WAVEHDR. | |
| void | FreeOutWhdrItem (ITEM *item) |
| Free WAVEHDR list item. | |
| void | FreeOutBuffers () |
| Free all output buffers. | |
| void | CloseOut () |
| Close output wave driver. | |
| int | OpenWaveOut (int outDev, int sampRate, int numChan) |
| Open wave output driver. | |
| int | OpenOut (int outDev, int sampRate, int numChan, WadSampFmt smpFmt, int numBuf, int bufLen) |
| Open output device. | |
| bool | StartOut () |
| Start output streaming. | |
| bool | StopOut () |
| Stop output streaming. | |
| void | FreeInWhdrItem (ITEM *item) |
| Free input WAVEHDR list item. | |
| void | FreeInBuffers () |
| Free input buffers. | |
| void | CloseIn () |
| Close input wave driver. | |
| int | OpenWaveIn (int inDev, int sampRate, int numChan) |
| Open input wave driver. | |
| int | OpenIn (int inDev, int sampRate, int numChan, WadSampFmt smpFmt, int numBuf, int bufLen) |
| Open input device. | |
| bool | StartIn () |
| Start input streaming. | |
| bool | StopIn () |
| Stop input streaming. | |
Static Protected Member Functions | |
| static bool | AllocBufList (int numBuf, int bufLen, int sampBytes, LIST *list) |
| Allocate a list of WAVEHDRs, using the WHDR_ITEM list item. | |
Protected Attributes | |
| void * | m_OutBuf |
| allocated output buffer in user sample format for callbacks | |
| void * | m_InBuf |
| allocated input buffer in user sample format for callbacks | |
| HANDLE | m_QuitEvent |
| signal when you want WadMmeThread to quit | |
| HANDLE | m_ThreadHandle |
| I/O thread handle. | |
| WadMmeDevInfo * | m_Devs |
| device table | |
| int | m_NumDevs |
| number of devices | |
| bool | m_InIsOpen |
| is input already open? | |
| int | m_InBufLen |
| input buffer length, samples | |
| int | m_NumInBuf |
| number of input buffers | |
| LIST | m_InList |
| list of input buffers with recorded data | |
| LIST | m_InItemList |
| list of all input WHDR_ITEMs not in m_InList | |
| HWAVEIN | m_In |
| handle to wave in driver | |
| WAVEHDR * | m_InWHdr |
| current WAVEHDR being read | |
| bool | m_OutIsOpen |
| is output already open? | |
| int | m_OutBufLen |
| output buffer length, samples | |
| int | m_NumOutBuf |
| number of output buffers | |
| LIST | m_OutList |
| list of output buffers waiting to be filled | |
| LIST | m_OutItemList |
| list of all output WHDR_ITEMs not in m_OutList | |
| HWAVEOUT | m_Out |
| handle to wave out driver | |
| WAVEHDR * | m_OutWHdr |
| current WAVEHDR being filled | |
| void * | m_Arg |
| argument to callback functions | |
| WadCallbackFn * | m_InFn |
| input (record) callback | |
| WadCallbackFn * | m_OutFn |
| output (play) callback | |
| CRITICAL_SECTION | m_OutBufLock |
| This lock is set whenever the output buffer queues are accessed by the main thread or the callback thread. | |
| HANDLE | m_OutputReadyEvent |
| If not signaled, output is blocked because there are no free buffers, or because things haven't initialized yet. | |
| CRITICAL_SECTION | m_InBufLock |
| This lock is set whenever the input buffer queues are accessed by the main thread or the callback thread. | |
| HANDLE | m_InputReadyEvent |
| If not signaled, input is blocked because there are no filled buffers, or because things haven't initialized yet. | |
WaAudioDev implemention of MME audio API.
This is based on original MME "wavio" code written in 1998. It's pretty verbose, and uses a lot of lists to keep track of used and free buffers.
| void WadMme::Close | ( | ) | [virtual] |
Close devices and release memory.
Close the devices and release all memory associated with streaming. Different devices can be re-opened with different parameters without having to recreate the WaAudioDev object.
Implements WaAudioDevPort.
| WadAPI WadMme::GetAPI | ( | ) | [virtual] |
| int WadMme::GetBufTime | ( | bool | isOutput, |
| int * | pBufTimeMsec | ||
| ) | [virtual] |
Get buffer time.
| [in] | isOutput | true if get output buffer time, else get input buffer time |
| [out] | pBufTimeMsec | pointer to buffer time in milliseconds |
Return total buffer times in msec for the currently open devices. This is useful in case we want to increase the buffering because we're getting dropouts.
Reimplemented from WaAudioDev.
| int WadMme::GetDefaultInDevId | ( | int * | pId | ) | [virtual] |
Get the default input device.
| [out] | pId | pointer to default input device ID |
Implements WaAudioDev.
| int WadMme::GetDefaultOutDevId | ( | int * | pId | ) | [virtual] |
Get the default output device.
| [out] | pId | pointer to default output device ID |
Implements WaAudioDev.
| int WadMme::GetDevInfo | ( | int | devId, |
| WadDevInfo * | pInfo | ||
| ) | [virtual] |
Get device information.
| [in] | devId | the device ID, 0 to numDev-1 |
| [out] | pInfo | pointer to device info |
Implements WaAudioDev.
| int WadMme::GetNumDevices | ( | int * | pNumDev | ) | [virtual] |
Get the count of devices discovered.
| [out] | pNumDev | pointer to number of devices |
Implements WaAudioDev.
| int WadMme::GetVol | ( | int | devId, |
| bool | isOutput, | ||
| float * | pVol | ||
| ) | [virtual] |
Get volume.
| [in] | devId | device ID |
| [in] | isOutput | true if get output volume, else get input volume |
| [out] | vol | pointer to volume, 0.0 (min) to 1.0 (max) |
Get volume of device. Any discovered device can be specified and the device does not need to be open for streaming.
Reimplemented from WaAudioDev.
| int WadMme::Init | ( | ) | [virtual] |
initialize the OS API and discover all devices
Initialize, which means do device discovery. The idea is that the devices are enumerated at Init time, and from then on only this device set can be used. Any dynamic changes to the device set can be caught via messages and then this WaAudioDev object must be recreated to discover the new devices updating the device table.
Implements WaAudioDev.
| bool WadMme::IsRunning | ( | ) | [virtual] |
Test if stream I/O thread is running.
Implement this to return false if the I/O thread has exited perhaps because a callback has returned false. This is a non-blocking alternative to Wait(). But why can't we just use IsOpen()? Ah, because the thread terminating doesn't automatically close the device, that's why.
Implements WaAudioDev.
| int WadMme::Open | ( | WadParam * | param, |
| WadCallbackFn * | inFn, | ||
| WadCallbackFn * | outFn, | ||
| void * | arg | ||
| ) | [virtual] |
Open devices for streaming.
Open devices for streaming with provided parameters. Asynchronous callbacks fetch and deliver sample buffers: inFn delivers input sample buffers and outFn fetches output sample buffers. Streaming directions are determined by valid device IDs in parameter structure, at least one direction must be enabled. Pass NULL for callback if that direction is not enabled.
| [in] | param | Stream parameters |
| [in] | inFn | Input callback function, or NULL |
| [in] | outFn | Output callback function, or NULL |
| [in] | arg | Argument to callbacks |
Implements WaAudioDevPort.
| int WadMme::SetVol | ( | int | devId, |
| bool | isOutput, | ||
| float | vol | ||
| ) | [virtual] |
Set volume.
| [in] | devId | device ID |
| [in] | isOutput | true if set output volume, else set input volume |
| [in] | vol | volume, 0.0 (min) to 1.0 (max) |
Set volume of device. Any discovered device can be specified and the device does not need to be open for streaming.
Reimplemented from WaAudioDev.
| int WadMme::Start | ( | ) | [virtual] |
Start streaming.
Start streaming audio. This must be called after Open to actually start stream.
Implements WaAudioDevPort.
| int WadMme::Stop | ( | ) | [virtual] |
Stop streaming.
Stop streaming audio. Stream can be restarted by calling Start().
Implements WaAudioDevPort.
| void WadMme::Wait | ( | ) | [virtual] |
Wait for stream to complete.
Wait for streaming I/O thread to terminate. This call blocks and should only be called if the callbacks will return false status to stop streaming and terminate I/O thread.
Implements WaAudioDevPort.
CRITICAL_SECTION WadMme::m_InBufLock [protected] |
This lock is set whenever the input buffer queues are accessed by the main thread or the callback thread.
HANDLE WadMme::m_InputReadyEvent [protected] |
If not signaled, input is blocked because there are no filled buffers, or because things haven't initialized yet.
This is initially reset, reset when no filled buffers remain, and set when a filled buffer becomes available.
CRITICAL_SECTION WadMme::m_OutBufLock [protected] |
This lock is set whenever the output buffer queues are accessed by the main thread or the callback thread.
HANDLE WadMme::m_OutputReadyEvent [protected] |
If not signaled, output is blocked because there are no free buffers, or because things haven't initialized yet.
This is initially set, reset when free buffers run out, and set when a buffer becomes available.
1.7.5.1