Implement this user callback interface in order to receive audio buffers. Register the callback by setting the ILMACallback::CallbackObj2 property. This interface has one method, which is called by the LEAD Audio Callback Filter whenever the filter receives an audio buffer.

DirectShow determines the duration of the audio buffer. However, if you use the LEADTOOLS Multimedia toolkit, you can change the size of the audio buffers using the get_AudioBufferSize property.

This interface should be used for C++, .NET or other programming languages that can cast a 32-bit long to a pointer. See below for .NET examples (C# and VB.NET) of a class implementing this interface.

Interface Methods:

HRESULT CallbackProc (long pData, long lDataSize, long lBitsPerSample, long lChannels, long lSamplesPerSec, long lAvgBytesPerSec);

This function will be called each time an audio sample is received by the filter.



Pointer to the sample data cast as a 32-bit long. The sample data is an array of unsigned bytes (8-bit) or signed short (16-bit) values. This value should be cast to a pointer to unsigned byte or signed short, depending on the value of lBitsPerSample.


The number of elements in pData. If lBitsPerSample is 8, then this also represents the size (in bytes) of the buffer pointed to by pData. If lBitsPerSample is 16, then the size of the pData buffer is lDataSize * 2.


Number of bits per sample of mono data. This can be 8 or 16. This determines the format of the data pointed to by pData.


Number of channels (i.e. 1=mono, 2=stereo...)


Sample rate, in samples per second.


Average bandwidth in bytes per second. It should be equal to lSamplesPerSec * lChannels * (lBitsPerSample / 8).



Successful, pass this sample data array downstream.


Drop this sample; the sample will not be delivered downstream.


Repeat the last successfully delivered sample.

Other error codes

Any other error code will be returned by the filter as is and the data will not be passed downstream.


Format of audio data:

The general format of the audio data (lChannels) is as follows:

Sample 0

Channel 0

Channel 1


Channel lChannels - 1

In this case,

pData(0) is Sample 0, Channel 0   
pData(1) is Sample 0, Channel 1 
pData(lChannels - 1) is Sample 0, Channel lChannels -1   
pData(lChannels) is Sample 1, Channel 0   
pData(lChannels + 1) is Sample 1, Channel 1 

The format for mono data is simple, because there is only one channel. In this case, every value in the array is one sample:

pData(0) is Sample 0   
pData(1) is Sample 1 

The format for stereo data is still simple: there are two values per sample (one for left channel and the other for right channel):

pData(0) is Sample 0, Left channel   
pData(1) is Sample 0, Right channel   
pData(2) is Sample 1, Left channel   
pData(3) is Sample 1, Right channel 
The format of the value is different depending on whether lBitsPerChannel is 8 or 16.

Format of 8-bit audio data:

The values in the array are unsigned and between 0 and 255. The real audio value will be obtained by subtracting 128 from the array value and should have a value between -128 and 127. If you want to change the value, you must remember to add 128 before putting back the data.

Format of 16-bit data:

The values in the array are signed and between -32768 and 32767. They contain the real audio value and it is not necessary to do the conversions like for the 8-bit data.


Example 1: Fast C# code (using unsafe code)

This C# code silences the sound track by setting all the sound values to 0. Note that this sample uses pointers, which means your application must be compiled as using unsafe code. For slower, safe code, look at the second example, which is written in VB.NET.

Example 2: VB.NET code (slower, but using safe code)

This VB.NET code silences the sound track by setting all the sound values to 0. Note that this sample is safe, does not use pointers, but is slower than the unsafe code above.

Public Class VBAudioCallback : Implements LMACallbackLib.ILMAUserCallback2 
   Public Sub New() 
   End Sub 
   Sub CallbackProc(ByVal pData As Integer, ByVal lDataSize As Integer, ByVal lBitsPerSample As Integer, ByVal lChannels As Integer, ByVal lSamplesPerSec As Integer, ByVal lAvgBytesPerSec As Integer) Implements LMACallbackLib.ILMAUserCallback2.CallbackProc 
      Dim ptrData As IntPtr = New IntPtr(pData) 
      Dim i As Integer 
      ' copy the data to a managed array, since VB does not support pointers. 
      If lBitsPerSample = 16 Then 
         Dim ptrData16(lDataSize) As Short 
         ' Copy data from pData into ptrData16 
         System.Runtime.InteropServices.Marshal.Copy(ptrData, ptrData16, 0, lDataSize) 
         ' set the data to 0 
         For i = 0 To lDataSize - 1 
            ptrData16(i) = 0 
         ' copy the data back into ptrData 
         System.Runtime.InteropServices.Marshal.Copy(ptrData16, 0, ptrData, lDataSize) 
         Dim ptrData8(lDataSize) As Byte 
         ' Copy data from pData into ptrData8 
         System.Runtime.InteropServices.Marshal.Copy(ptrData, ptrData8, 0, lDataSize) 
         ' set the data to 0 
         For i = 0 To lDataSize - 1 
            ptrData8(i) = 0 
         ' copy the data back into ptrData 
         System.Runtime.InteropServices.Marshal.Copy(ptrData8, 0, ptrData, lDataSize) 
      End If 
   End Sub   
End Class   

Help Version 20.0.2020.3.31
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.