Class WindowsAudioIo
This class uses the Windows Wave API to capture audio from a microphone and to send audio to the speakers or a headset. It is intended for use with Voice Over IP (VoIP) applications running under Windows.
Implements
Inherited Members
Namespace: SipLib.Audio.Windows
Assembly: SipLib.Audio.Windows.dll
Syntax
public class WindowsAudioIo : IMMNotificationClient, IAudioSampleSource
Constructors
WindowsAudioIo(int, string?)
Constructor
Declaration
public WindowsAudioIo(int SampleRate = 8000, string? DeviceName = null)
Parameters
| Type | Name | Description |
|---|---|---|
| int | SampleRate | Sample rate in samples per second. Must be either 8000 or 16000. The default is 8000. |
| string | DeviceName | Specifies the audio device name as known by the Windows Wave API subsystem. The default is null. If null, then this class will pick the first available audio device. |
Properties
SampleRate
Gets the configured sample rate in samples/second.
Declaration
public int SampleRate { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
AudioOutSamplesReady(short[])
Sends the received PCM samples to the output device (speakers or headset).
Declaration
public void AudioOutSamplesReady(short[] PcmSamples)
Parameters
| Type | Name | Description |
|---|---|---|
| short[] | PcmSamples | Received PCM samples (16-bit linear, 8000 or 16000 samples per second. |
GetAudioDeviceNames()
Gets a list of available Wave API audio devices.
Declaration
public static List<string> GetAudioDeviceNames()
Returns
| Type | Description |
|---|---|
| List<string> | Returns a list of device names. The list will be empty if there are no audio devices available. |
OnDefaultDeviceChanged(DataFlow, Role, string)
IMMNotificationClient interface method. Called by the Windows multi-media subsystem when the default audio device has changed. The user of this WindowsAudioIo object should never call this method.
Declaration
public void OnDefaultDeviceChanged(DataFlow flow, Role role, string defaultDeviceId)
Parameters
| Type | Name | Description |
|---|---|---|
| DataFlow | flow | |
| Role | role | |
| string | defaultDeviceId |
OnDeviceAdded(string)
IMMNotificationClient interface method. Called by the Windows multi-media subsystem when an audio device has been added to the system. The user of this WindowsAudioIo object should never call this method.
Declaration
public void OnDeviceAdded(string pwstrDeviceId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | pwstrDeviceId |
OnDeviceRemoved(string)
IMMNotificationClient interface method. Called by the Windows multi-media subsystem when an audio device has been removed from the system. The user of this WindowsAudioIo object should never call this method.
Declaration
public void OnDeviceRemoved(string deviceId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | deviceId |
OnDeviceStateChanged(string, DeviceState)
IMMNotificationClient interface method. Called by the Windows multi-media subsystem when the audio device state changes. The user of this WindowsAudioIo object should never call this method.
Declaration
public void OnDeviceStateChanged(string deviceId, DeviceState newState)
Parameters
| Type | Name | Description |
|---|---|---|
| string | deviceId | |
| DeviceState | newState |
OnPropertyValueChanged(string, PropertyKey)
IMMNotificationClient interface method. Called by the Windows multi-media subsystem when a property of an audio device has changed. The user of this WindowsAudioIo object should never call this method.
Declaration
public void OnPropertyValueChanged(string pwstrDeviceId, PropertyKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | pwstrDeviceId | |
| PropertyKey | key |
Start()
Tells the audio sample source to start sending audio samples by firing the SendAudioSamples event.
Declaration
public void Start()
StartAudio()
Sets up audio acquisition from the microphone and gets ready to start sending audio to the speakers or headset.
Declaration
public WaveAudioStatusEnum StartAudio()
Returns
| Type | Description |
|---|---|
| WaveAudioStatusEnum | Returns Success if no errors were detected or an error code. Audio is not started if an error code is returned. |
Stop()
Tells the audio sample source to stop sending audio samples.
Declaration
public void Stop()
StopAudio()
Call this method to stop the audio and gracefully shutdown.
Declaration
public void StopAudio()
Events
AudioDeviceStateChanged
This event is fired when the state of the Windows audio I/O device changes state.
Declaration
public event AudioDeviceStateChangedDelegate? AudioDeviceStateChanged
Event Type
| Type | Description |
|---|---|
| AudioDeviceStateChangedDelegate |
AudioSamplesReady
This event is fired when a full block of 20 milliseconds of audio data has been received from the microphone. Each sample point is a PCM sample (16-bit linear, 8000 or 16000 samples/second).
Declaration
public event AudioSamplesReadyDelegate? AudioSamplesReady
Event Type
| Type | Description |
|---|---|
| AudioSamplesReadyDelegate |