Implement this user callback interface in order to receive audio buffers. Register the callback by setting the either the ILMACallback::CallbackObj or the ILMACallback::CallbackObj2 property. Each 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.
Use this interface with VB (6 or earlier) or other programming languages that cannot deal with pointers. This interface does not work well in .NET. For .NET programming, use the ILMAUserCallback2 (uses a pointer to the data, cast as a 32-bit long value) or ILMAUserCallback3 (uses a pointer to the data, cast as a 64-bit LONGLONG value.) interface instead.
typedef enum
{
AUDCALBK_ERR_OK,
AUDCALBK_ERR_DROP,
AUDCALBK_ERR_DELIVERLASTSAMPLE,
} AudCalBkErrConstants;
Lists the possible error code values that can be returned by the CallbackProc method.
AUDCALBK_ERR_OK | [0] Successful, pass this sample data array downstream. |
AUDCALBK_ERR_DROP | [1] Drop this sample; the sample will not be delivered downstream. |
AUDCALBK_ERR_DELIVERLASTSAMPLE | [2] Repeat the last successfully delivered sample. |
This function will be called each time an audio sample is received by the filter.
pData |
Pointer to the sample data. The sample data is an array of unsigned bytes (8-bit) or signed short (16-bit) values. |
lDataSize |
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. |
lBitsPerSample |
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. |
lChannels |
Number of channels (that is, 1=mono, 2=stereo...) |
lSamplesPerSec |
Sample rate, in samples per second. |
lAvgBytesPerSec |
Average bandwidth in bytes per second. It should be equal to lSamplesPerSec * lChannels * (lBitsPerSample / 8). |
AUDCALBK_ERR_OK |
Successful, pass this sample data array downstream. |
AUDCALBK_ERR_DROP |
Drop this sample; the sample will not be delivered downstream. |
AUDCALBK_ERR_DELIVERLASTSAMPLE |
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.
Here is some Visual Basic code that doubles the intensity of the sound for pData(i):
Dim val As Long ' use a signed data type
val = pData(i) - 128 ' convert pData(i) to long. val is now the audio value, in the 0..255 range
val = val * 2 - double the sound intensity
' convert the value to signed 8-bit
val = pData(i) - 128
' double the audio value
val = val * 2
' clip the output to -128..127
If val > 127 Then
val = 127
ElseIf val < -128 Then
val = -128
End If
' write the data out, adding back 128
pData(i) = val + 128
Note how the real audio value was clipped to the -128 ..127 range before adding 128. This is important, otherwise distortions are introduced.
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.
Here is some Visual Basic code that doubles the intensity of the sound for pData(i):
' use a signed data type. Use long (32-bit in VB) instead of Integer (16-bit in VB) to avoid overflows when multiplying by 2
Dim val As Long
val = pData(i)
val = val * 2
' clip the output to --32768..32767
If val > 32767 Then
val = 32767
ElseIf (val < -32768) Then
val = -32768
End If
pData(i) = val