ILMADetUserCallback

Implement the ILMADetUserCallback2 user callback to receive notifications of sound and silence detection. Register the callback by setting the ILMADet::CallbackObj property. The interface has one method, which reports sound and silence events. It is called by the filter.

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.

Use the ILMADetUserCallback2 Interface with C++, .NET or other programming languages that can cast a LONGLONG (__int64) value to a pointer.

Methods

HRESULT CallbackProc (long nEvent, VARIANT *pData, long lDataCount, long lBitsPerSample, long lChannels, long lSamplesPerSec, long lAvgBytesPerSec);

Description

The filter calls this method whenever sound or silence is detected.

Parameters

nEvent

Event notification type that indicates whether sound or silence is being detected. Possible values for are:

Value Meaning
AUDIO_LEVEL_STARTSOUND The filter has detected sound. The previous buffer contained silence.
AUDIO_LEVEL_SOUND The filter has detected sound. The previous buffer contained sound also.
AUDIO_LEVEL_STARTSILENCE The filter has detected silence. The previous buffer contained sound.
AUDIO_LEVEL_SILENCE The filter has detected silence. The previous buffer contained silence also.

pData

Pointer to the audio data. The audio data is an array of unsigned bytes (8-bit) or signed short (16-bit) values. For more information on the audio data, refer to the Comments section below.

lDataCount

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 lDataCount * 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 (i.e. 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).

Comments

Each time the callback is received, you are also given the audio data buffer.

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 such cases, each 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 the left channel and the other for the 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 is obtained by subtracting 128 from the array value and should have a value between -128 and 127. When changing the value, remember to add 128 before putting the data back.

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 values. It is not necessary to perform conversions like those 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 

Returns

Return Description
S_OK Successful
< 0 An error occurred.
Help Version 22.0.2023.2.15
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Filters C API Help

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.