Getting the audio data for VU meter level display with MFormats

A frame-based MFormats SDK architecture provides access to the data of each frame you process. 

Each frame contains the VU meter level data ready to be used. Which makes the VU meter displaying a pretty easy task: all you need is pick the VU meter data from the frame you process and display it. 

Here is a sequence of actions:

1. Get the frame from the source. It can be MFReader, MFLive, or any custom frames source.
MFFrame myFrame;
mySource.SourceFrameGet(-1, out myFrame, "");

2. Get the frame's audio and video props structure using  MFAVPropsGet method:
M_AV_PROPS myAV_Props;
int audioSamples; 
myFrame.MFAVPropsGet(out myProps, out audioSamples);

3. Get the VU meter level data array out of M_AV_PROPS structure and display it. 
There are 3 types of audio volume information representation available now: the RMS (actual volume information), the VU meter (the dynamic volume information with attack and release ramps) and VU meter peaks

NOTE: The M_AV_PROPS structure provides you with 2 arrays of audio volume information: the original one (that was provided by the source) and the output one (after applying the audio gain with MFAudioGain method).
// The array of original VU meter values.  
float[] originalChannelsVUmeterArr = myAV_Props.ancData.audOriginal.arrVUMeter;
// The array of output VU meter values.
float[] outputChannelsVUmeterArr = myAV_Props.ancData.audOutput.arrVUMeter;
   
4. Enumerate the array to get the VU meter level for each audio channel.
NOTE: the array of VU meter values contains 12 items by default. This value does not match the real number of audio channels of the frame, so you should refer to nChannels field of M_AUD_PROPS structure to get the real number of channels.
// Get the real number of audio channels
int numberOfChannels = avProps.audProps.nChannels;
// Enumerate the VU level values for audio channels
for (int i = 0; i < numberOfChannels; i++)
{
    // Get the VU level value for current audio channel
    float channelVUmeterValue = outputChannelsVUmeterArr[i];
}
Depending on the required VU meter display accuracy you can process not every single frame audio data, but each 10-th, 20-th etc. to reduce the resources consummation. 

Check the VU meter display logic on our Sample File Playback application:



Except VU meter display logic, the VU meter control can also set the gain for each audio channel.