By default, when you configure a live video source, it uses embedded audio source which is named <From Video>. And you can mix this embedded audio source with an external live audio, or disable the original audio and use only an external one. You can use any available DirectShow audio sources as external audio.
You can set external audio sources for MLive and MFLive objects as a specific device type.
MPlatform SDK
int nCount = 0; //Get device count m_objMLive.DeviceGetCount(0, "ext_audio", out nCount); string[] deviceArray; if (nCount > 0) { deviceArray = new string[nCount]; for (int i = 0; i < nCount; i++) { string strName; string strDesc; m_objMLive.DeviceGetByIndex(0, "ext_audio", i, out strName, out strDesc); deviceArray[deviceIndex] = strName; } } m_objMLive.DeviceSet("video", deviceArray[targetIndex], "");
myLive.DeviceSet("ext_audio", "PC Sounds (Loopback)", "");
MFormats SDK
To get a list of the available external audio source that you can use with a video device should call this code:
// get number of devices available for usage int deviceCount; myLiveSource.DeviceGetCount(eMFDeviceType.eMFDT_ExtAudio , out deviceCount); // initialize an array to collect device names string[] deviceArray; if (deviceCount > 0) { deviceArray = new string[vCount]; for (int deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++) { // get device by its index string deviceName; int isBusy; // indicates is it possible to use this device or is it busy in another application myLiveSource.DeviceGetByIndex(eMFDeviceType.eMFDT_ExtAudio , deviceIndex, out deviceName, out isBusy); deviceArray[deviceIndex] = deviceName; } }
To set a device you should call DeviceSet method:
myLiveSource.DeviceSet(eMFDeviceType.eMFDT_ExtAudio, deviceIndex, "");
Common features
Once the external audio source is specified, you get embedded audio mixed with external one as result. By default, external audio channels are added to original one as a new audio track. When you work with MLive/MFLive object only, all the tracks are merged together. So if your video source contains embedded audio with 2 channels and the external audio source also has 2 channels, as a result, you will get 4-channels audio.
To set where the external audio should be inserted you should set "ext_audio.insert_to_channels" property with the PropsSet method for you MFLive or MLive object. For example:
(myLiveSource as IMProps).PropsSet("ext_audio.insert_to_channels", "0,1"); // MForamts SDK
(myLiveSource as IMProps).PropsSet("object::ext_audio.insert_to_channels", "0,1"); // MPlatform SDK
In this case, external audio will be at 1st and 2nd channels, while the original audio will be shifted to 3rd and other channels.
You can use up to 16 different external audio sources within a single object (MLive or MFLive).
In MPlatform SDK you can specify a new external audio source with "ext_audio.2", "ext_audio.3" etc. device types like:
myLive.DeviceSet("ext_audio.2", "DirectShow Microphone", "");
And in MFormats SDK you can use eMFDT_ExtAudio_2, eMFDT_ExtAudio_3 as device types:
myLiveSource.DeviceSet(eMFDeviceType.eMFDT_ExtAudio_2, deviceIndex2, "");
For these audio sources, the channels are added next to the original ones.
Disable original audio
You should specify "audio" (eMFDeviceType.eMFDT_Audio) device to "<No Audio>" (for professional capture cards) or to "<None>" (for DirectShow devices like web cameras) with the DeviceSet method:
myLive.DeviceSet("audio", @"<No Audio>", ""); // MPlatform SDK
m_objLive.DeviceSet(eMFDeviceType.eMFDT_Audio, targetIndex , ""); //MFormats SDK
where targetIndex is the index of "No Audio" source.