Medialooks Knowledge Base Support Center

Contact Us

Working with audio through properties

The simplest way to work with audio is to use object properties with IMProps interface. You can change the order of audio channels, modify a number of channels and set the audio gain for each of them.

"object::audio_channels" property

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, MComposer.

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");

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:

myLive.PropsSet("object::audio_channels", "0+1+2,2+3+4");

"object::audio_gain" property

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 audio gain for all the channels you should call

(myFile as IMProps).PropsSet("object::audio_gain", "-10");

This decrease audio gain of all audio channels to 10 dB.

To specify audio gain for each channel you should call

(myFile as IMProps).PropsSet("object::audio_gain", "-10,5,-7,2");

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::" prefix for properties MFormats SDK objects