LVC audio input
The LVCAudioInput
class is used to add audio sources to the LVC pipeline. The class allows you to set the audio parameters and the volume of the audio source.
You can use any block that has an audio output pad. For example, you can use the VirtualAudioSourceBlock
to create a virtual audio source or SystemAudioSourceBlock
to capture audio from the microphone.
Usage
When creating an LVCAudioInput
object, you must specify the MediaBlock to be used as the audio data source.
Sample code
Virtual audio source
The sample code below shows how to create an LVCAudioInput
object with a VirtualAudioSourceBlock
as the audio source.
var name = "Audio source [Virtual]";
var settings = new VirtualAudioSourceSettings();
var info = new AudioInfoX(settings.Format, settings.SampleRate, settings.Channels);
var src = new LVCAudioInput(name, _compositor, new VirtualAudioSourceBlock(settings), info, true);
if (await _compositor.Input_AddAsync(src))
{
// added successfully
}
else
{
src.Dispose();
}
System audio source (DirectSound in Windows)
The sample code below shows how to create an LVCAudioInput
object with a SystemAudioSourceBlock
as the audio source.
We use the DeviceEnumerator
class to get the audio devices. The first audio device is used as the audio source. The first audio format of the device is used as the audio format.
DSAudioCaptureDeviceSourceSettings settings = null;
AudioCaptureDeviceFormat deviceFormat = null;
var device = (await DeviceEnumerator.Shared.AudioSourcesAsync(AudioCaptureDeviceAPI.DirectSound))[0]];
if (device != null)
{
var formatItem = device.Formats[0];
if (formatItem != null)
{
deviceFormat = formatItem.ToFormat();
settings = new DSAudioCaptureDeviceSourceSettings(device, deviceFormat);
}
}
if (settings == null)
{
MessageBox.Show(this, "Unable to configure audio capture device.");
return;
}
var name = $"Audio source [{device.Name}]";
var info = new AudioInfoX(deviceFormat.Format, deviceFormat.SampleRate, deviceFormat.Channels);
var src = new LVCAudioInput(name, _compositor, new SystemAudioSourceBlock(settings), info, true);
if (await _compositor.Input_AddAsync(src))
{
// added successfully
}
else
{
src.Dispose();
}