Wave Arts VQE  1.00
Voice Quality Enhancement
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
WaAudioDev Class Reference

Audio device. More...

#include <WaAudioDev.h>

Inheritance diagram for WaAudioDev:
WaAudioDevPort WadFile WadMacHAL WadMme WadWASAPI WadResMacHAL WadResWASAPI

List of all members.

Public Member Functions

virtual WadAPI GetAPI ()=0
 return API enum
virtual int Init ()=0
 initialize the OS API and discover all devices
virtual int GetNumDevices (int *pNumDev)=0
 Get the count of devices discovered.
virtual int GetDevInfo (int devId, WadDevInfo *pInfo)=0
 Get device information.
virtual int GetDefaultInDevId (int *pId)=0
 Get the default input device.
virtual int GetDefaultOutDevId (int *pId)=0
 Get the default output device.
void SetMeteringEnable (bool enable)
 Enable/disable metering.
bool GetInPeak (float *pPeakVal)
 Get input peak value.
bool GetOutPeak (float *pPeakVal)
 Get output peak value.
float GetLastInPeak ()
 Get peak value of last input buffer processed.
float GetLastOutPeak ()
 Get peak value of last output buffer processed.
void ResetMetering ()
 Reset peak metering values.
virtual int SetVol (int devId, bool isOutput, float vol)
 Set volume.
virtual int GetVol (int devId, bool isOutput, float *pVol)
 Get volume.
virtual int GetBufTime (bool isOutput, int *pBufTimeMsec)
 Get buffer time.
virtual int GetClosestFormat (bool isOutput, WadStreamFormat *pFormat)
 Get closest stream format after an unsupported format error.
WaAudioDevGetDevice ()
 Get the device.
virtual char * GetErrorText ()
 Get the error text after error status is returned.
bool IsInitialized ()
 Return T/F if Init() has been called and devices are discovered.
bool IsOpen ()
 Return T/F if device is open for streaming.
bool IsInOpen ()
 return T/F if device is open for input streaming
bool IsOutOpen ()
 return T/F if device is open for output streaming
virtual bool IsRunning ()=0
 Test if stream I/O thread is running.
void SetErrorText (char *text)
 Set the error text.

Static Public Member Functions

static float PeakToDb (float peak, float minDb, float maxDb)
 Convert peak sample value to dB.
static int CalcPeakInt16 (short *buf, unsigned int numSamps)
 Calculate maximum absolute value of short buffer.
static float CalcPeakFloat32 (float *buf, unsigned int numSamps)
 Calculate maximum absolute value of float buffer.
static WaAudioDevWadMake (int options)
 Make audio device.

Protected Member Functions

void ProcInPeakInt16 (short *buf, unsigned int numSamps)
 do input meter processing on 16-bit integer samples
void ProcInPeakFloat32 (float *buf, unsigned int numSamps)
 do input meter processing on 32-bit float samples
void ProcOutPeakInt16 (short *buf, unsigned int numSamps)
 do output meter processing on 16-bit integer samples
void ProcOutPeakFloat32 (float *buf, unsigned int numSamps)
 do output meter processing on 32-bit float samples
void SetIsInitialized (bool isInitialized)
 set initialized flag

Protected Attributes

float inPeak
 running input peak value
float lastInPeak
 last input buffer peak value
float outPeak
 running ouput peak value
float lastOutPeak
 last output buffer peak value
bool inPeakIsValid
 is inPeak valid, i.e. any samples processed?
bool outPeakIsValid
 is outPeak value, i.e any samples processed?
WadParam param
 parameters used to open the device
bool isInitialized
 Init() has completed, devices have been discovered.
bool isMeteringEnabled
 metering is enabled/disabled
bool isOpen
 successful Open sets this, Close resets
char errorText [WAD_MAX_ERROR_TEXT]
 error text used by device and connected ports

Detailed Description

Audio device.

Virtual base class for cross-platform audio devices. This can be implemented for each OS audio device API, e.g. Windows MME. This is intended for telecom use, not pro audio, hence there is no support for 24-bit or 32-bit integer sample formats or surround multichannel formats.

Creating the object doesn't do anything. Init() initializes the OS API and discovers audio devices. Use the WaAudioDevPort methods to open input and output devices for streaming. A single WaAudioDev object can have at most one input and one output stream. If you want more audio streams you need to create more instances of WaAudioDev.

If you want to rescan devices due to notification of a device change, you must create a new WaAudioDev object. You will probably want to remember any existing active device names, close open streams, and attempt to reopen using the saved device names to find the new device indices.

The audio device interface provides support for device volume control and signal level metering.


Member Function Documentation

float WaAudioDev::CalcPeakFloat32 ( float *  buf,
unsigned int  numSamps 
) [static]

Calculate maximum absolute value of float buffer.

Parameters:
[in]bufbuffer of float samples
[in]numSampsnumber of samples
int WaAudioDev::CalcPeakInt16 ( short *  buf,
unsigned int  numSamps 
) [static]

Calculate maximum absolute value of short buffer.

Parameters:
[in]bufbuffer of short samples
[in]numSampsnumber of samples
virtual WadAPI WaAudioDev::GetAPI ( ) [pure virtual]

return API enum

Return enum specifying the low level API in use.

Implemented in WadMme, WadWASAPI, WadFile, and WadMacHAL.

int WaAudioDev::GetBufTime ( bool  isOutput,
int *  pBufTimeMsec 
) [virtual]

Get buffer time.

Parameters:
[in]isOutputtrue if get output buffer time, else get input buffer time
[out]pBufTimeMsecpointer 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 in WadMme, WadWASAPI, WadFile, and WadMacHAL.

int WaAudioDev::GetClosestFormat ( bool  isOutput,
WadStreamFormat pFormat 
) [virtual]

Get closest stream format after an unsupported format error.

Parameters:
[in]isOutputtrue if get output format, else get input format
[out]pFormatpointer to closest format

After an unsupported format error, calling this will return the closest supported format. The caller can then set up appropriate sample rate and sample format and channel format conversions and try to reopen the device.

Reimplemented in WadWASAPI.

virtual int WaAudioDev::GetDefaultInDevId ( int *  pId) [pure virtual]

Get the default input device.

Parameters:
[out]pIdpointer to default input device ID

Implemented in WadMme, WadWASAPI, WadFile, and WadMacHAL.

virtual int WaAudioDev::GetDefaultOutDevId ( int *  pId) [pure virtual]

Get the default output device.

Parameters:
[out]pIdpointer to default output device ID

Implemented in WadMme, WadWASAPI, WadFile, and WadMacHAL.

WaAudioDev * WaAudioDev::GetDevice ( ) [virtual]

Get the device.

Returns pointer to the actual WaAudioDev at the end of the processing chain. Hence if you have a WaAudioDevPort pointer and you want to do an operation like get device name or change volume, you can first get the WaAudioDev pointer and call methods on that.

Implements WaAudioDevPort.

virtual int WaAudioDev::GetDevInfo ( int  devId,
WadDevInfo pInfo 
) [pure virtual]

Get device information.

Parameters:
[in]devIdthe device ID, 0 to numDev-1
[out]pInfopointer to device info

Implemented in WadMme, WadWASAPI, WadFile, and WadMacHAL.

char * WaAudioDev::GetErrorText ( ) [virtual]

Get the error text after error status is returned.

When an error occurs using a device or device port the code will often store a descriptive error message. Call this to retrieve the error text after an error. Note that device ports store their errors in the WaAudioDev at the end of the processing chain. You should use or copy the error text before calling additional methods, closing, or deleting port or device.

bool WaAudioDev::GetInPeak ( float *  pPeakVal)

Get input peak value.

Parameters:
[out]pPeakValpointer to peak value

Returns true if any samples processed since last poll. All peak values are represented as float samples where 1.0 is maximum.

float WaAudioDev::GetLastInPeak ( )

Get peak value of last input buffer processed.

This is for internal use (autogain).

float WaAudioDev::GetLastOutPeak ( )

Get peak value of last output buffer processed.

This is for internal use.

virtual int WaAudioDev::GetNumDevices ( int *  pNumDev) [pure virtual]

Get the count of devices discovered.

Parameters:
[out]pNumDevpointer to number of devices

Implemented in WadMme, WadWASAPI, WadFile, and WadMacHAL.

bool WaAudioDev::GetOutPeak ( float *  pPeakVal)

Get output peak value.

Parameters:
[out]pPeakValpointer to peak value

Returns true if any samples processed since last poll. All peak values are represented as float samples where 1.0 is maximum.

int WaAudioDev::GetVol ( int  devId,
bool  isOutput,
float *  pVol 
) [virtual]

Get volume.

Parameters:
[in]devIddevice ID
[in]isOutputtrue if get output volume, else get input volume
[out]volpointer 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 in WadMme, WadWASAPI, and WadMacHAL.

virtual int WaAudioDev::Init ( ) [pure 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.

Implemented in WadMme, WadWASAPI, WadFile, and WadMacHAL.

virtual bool WaAudioDev::IsRunning ( ) [pure 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.

Implemented in WadMme, WadWASAPI, WadFile, and WadMacHAL.

float WaAudioDev::PeakToDb ( float  peak,
float  minDb,
float  maxDb 
) [static]

Convert peak sample value to dB.

Parameters:
[in]peakpeak value, 1.0 is maximum
[in]minDbminimum dB value to return
[in]maxDbmaximum dB value to return

Helper function to convert peak values to dBFS (full scale) and restrict range. A peak of 1.0 maps to 0 dB.

void WaAudioDev::ResetMetering ( )

Reset peak metering values.

Implementations should reset metering in Close or Open.

void WaAudioDev::SetErrorText ( char *  text)

Set the error text.

Parameters:
[in]texterror text

Set the error text. This method is public so that ports can set error text. Ports report error text by storing text in device.

void WaAudioDev::SetMeteringEnable ( bool  enable)

Enable/disable metering.

Parameters:
[in]enableenable flag
int WaAudioDev::SetVol ( int  devId,
bool  isOutput,
float  vol 
) [virtual]

Set volume.

Parameters:
[in]devIddevice ID
[in]isOutputtrue if set output volume, else set input volume
[in]volvolume, 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 in WadMme, WadWASAPI, and WadMacHAL.

WaAudioDev * WaAudioDev::WadMake ( int  options) [static]

Make audio device.

Parameters:
[in]optionsoption flags

Make an audio device for the OS platform. The options argument allows some control. Note that this only creates the WaAudioDev object, the caller must call Init() after creating the object.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines