I am trying to sample the level of mp3 files to find the beginning and end of the music and also testing for the audio levels at 100 ms points throught the song to get an average volume and a peak volume to do some rough automatic volume processing. But I cannot seem to get this code segment to return samples reliably. Some mp3s work pretty good, some not at all. I have stripped out all but the bare minimum of code to simplify my question. If you feed this thing an mp3 file I think it should fill the LevelLst with 25ms sample levels taken every 100ms. Different mp3s return different results. Usually returns a few samples then just 0's. However a specific mp3 will always return the same results. What am I doing wrong?
Public Sub ScanTest2(ByVal SongPath As String, LevelLst As List(Of Integer))
Dim DecodeStreamId As Int32 = Bass.BASS_StreamCreateFile(SongPath, 0, 0, BASSFlag.BASS_STREAM_DECODE) 'open the decode_stream
Dim StreamLength As Integer = Bass.BASS_ChannelGetLength(DecodeStreamId)
If DecodeStreamId <> 0 Then
Dim Result As Boolean = True
Dim Level As Integer
Dim LeftLevel As Integer
Dim RightLevel As Integer
Dim AudioLevel As Integer
Dim SamplePosition As Int64
Dim SampleInterval As Integer = 7056 * 3
Do While Result = True
Level = Bass.BASS_ChannelGetLevel(DecodeStreamId)
LeftLevel = Utils.LowWord32(Level)
RightLevel = Utils.HighWord32(Level)
AudioLevel = (LeftLevel + RightLevel) / 2
LevelLst.Add(AudioLevel)
SamplePosition = Bass.BASS_ChannelGetPosition(DecodeStreamId)
Result = Bass.BASS_ChannelSetPosition(DecodeStreamId, SamplePosition + SampleInterval, 0) 'move to next sample
Loop
Bass.BASS_StreamFree(DecodeStreamId)
End If
End Sub
