The simplest way to work with audio is to use object properties with the IMProps interface. You can change the order of audio channels, modify a number of channels and set the audio gain for each of them.
This property modifies a number of audio channels and channels order. For example, this code:
(myFile as IMProps).PropsSet("object::audio_channels", "0,1,2,3");
sets only 4 audio channels in strict order from 1st channel to 4th for your myFile object. If myFile has more than 4 audio channels other channels are cut. You can use any source object as myFile - MMixer, MFile, MPlaylist, MLive.
To change the order of audio channels you should vary channel indexes in the property value:
(myFile as IMProps).PropsSet("object::audio_channels", "3,1,2,0");
You can copy audio channels by using the same channel index several times:
(myFile as IMProps).PropsSet("object::audio_channels", "0,1,1,0");
To use just a single channel you should set its index as value for this property:
(myFile as IMProps).PropsSet("object::audio_channels", "2");
To make a channel muted you should set "-1" as the index of required channel. For example, to mute 3rd result channel you should call:
(myFile as IMProps).PropsSet("object::audio_channels", "0,1,-1,3");
The property is used right after the audio is decoded - before any conversion like it is in the "object:audio_channels" case.
For example, you have a file with 10 audio tracks and each track is of 2 audio channels. So, you have 20 audio channels in total. If you need to use only the last 2 channels, you should set the "audio_channels" property to "18,19". But if you use an audio conversion to 16 channels with the FormatAudioSet method, you can't access the channels with indexes higher than 15 using "object::audio_channels" - because after the conversion you have only 16 audio channels.
In this case, you should use "file::audio_channels" property.
Note please that the "file::" and "object::" prefixes are for MPlatform SDK only - in MFormats SDK you work with MFReader object directly as if you set the properties for the decoding process.
Audio channels mixing
You can mix several original audio channels into a single new channel. For example, to create a 2 channels audio from original 4 channels audio the way the 1st new channel contains audio from 1st, 2nd, and 4th original channels, and the 2nd new channel is a sum of 2nd, 3rd and 4th original channels you should call:
Audio track splitting
To split audio channels into separated tracks, use '|' symbol in "audio_channels" property value. For example, to split 4 channels audio track into 4 mono tracks:
This property modifies the audio gain of audio channels. You can modify audio gain for all audio channels at once or set the audio gain for each channel separately.
To set the audio gain for all the channels you should call
(myFile as IMProps).PropsSet("object::audio_gain", "-10.0");
This decrease the audio gain of all audio channels to 10.0 dB.
To specify audio gain for each channel you should call
(myFile as IMProps).PropsSet("object::audio_gain", "-10.0,5.2,-7.5,2.1");
In this case, 4 channels have a new audio gain. If there are more than 4 audio channels in the object all the other channels gain is unchanged.
The difference between working with audio through properties and IMAudio interface in MPlatform SDK
With IMAudio and IMAudioTrack interfaces you can work with audio in a more flexible way, but most common actions are much easier to do through properties. The main difference between these approaches is that when MPlatform calculates audio in your stream it firstly uses setting made through IMAudio and IMAudioTrack interfaces and in the last step it modifies audio according to properties:
For example, if you get audio VU meter value of an audio channel with TrackLoudnessGet method and compare its value with VU meter data that contains in the result frame, you get different values.
What about MFormats SDK?
You don't need to use "object::" or "file::"prefixes for properties MFormats SDK objects