# Audio sample grabber usage

Video Capture SDK .Net , Video Edit SDK .Net , Media Player SDK .Net

You can get audio frames from live sources or files using the OnAudioFrameBuffer event.

The OnAudioFrameBuffer event provides the unmanaged memory pointer for the decoded frame. Usually, it is PCM audio data, but it can also be IEEE audio data.

Frame event args contain the channel count, sample rate, audio format, timestamp, and other information.

# Sample code

Create event handler.

VideoCapture1.OnAudioFrameBuffer += VideoCapture1_OnAudioFrameBuffer;

Set the Audio_Sample_Grabber_Enabled property to true to enable the event (not required for VideoEditCore) and create the event handler.

VideoCapture1.Audio_Sample_Grabber_Enabled = true;

Create event handler.

VideoCapture1.OnAudioFrameBuffer += VideoCapture1_OnAudioFrameBuffer;

Process audio frames in the OnAudioFrameBuffer event.

using VisioForge.Types;

private void VideoCapture1_OnAudioFrameBuffer(object sender, AudioFrameBufferEventArgs e)
{
    // you can process audio here

    // write audio info
    Debug.WriteLine("Audio frame: " + e.Frame.DataSize + " bytes; Format: " + e.Frame.Info.ToString());

    // process data
    // e.Frame.Data (IntPtr) contains audio data in PCM format
}

Also, you can use the GetDataArray method of AudioFrame to get the copy of audio data as an array.


Visit our GitHub page to get more code samples.