JOBnik's Forum
BASS => VB Examples => Topic started by: ritmod on December 25, 2006, 06:32:32 PM
-
sorry, my english is very bad...
hi. i referencee bass - spectrum code written by JOBnik
I have a problem with modifying the size of spectrum by this code
actually i also posted this problem to - Un4seen
the code is...
----------------------------------------------------------------------------------------------------------
Public Const SPECWIDTH As Long = 656 ' display width
Public Const SPECHEIGHT As Long = 500 ' height (changing requires palette adjustments too)
' MATH Functions
Public Function Sqrt(ByVal num As Double) As Double
Sqrt = num ^ 0.5
End Function
Function Log10(ByVal X As Double) As Double
Log10 = Log(X) / Log(10#)
End Function
' update the spectrum display - the interesting bit
Public Sub UpdateSpectrum(ByVal uTimerID As Long, ByVal uMsg As Long, ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long)
Dim X As Long, Y As Long, y1 As Long
Dim fft(1024) As Single ' get the FFT data
Call BASS_ChannelGetData(chan, fft(0), BASS_DATA_FFT2048)
#If 1 Then
Y = Sqrt(fft(X + 1)) * 3 * SPECHEIGHT - 4 ' scale it (sqrt to make low values more visible)
#Else
' Y = fft(X + 1) * 10 * SPECHEIGHT ' scale it (linearly)
#End If
If (specmode = 1) Then ' logarithmic, acumulate & average bins
ReDim specbuf(SPECWIDTH * (SPECHEIGHT + 1)) As Byte ' clear display
Dim b0 As Long
b0 = 0
BANDS = SPECWIDTH / 13
frmSpectrum.Caption = BANDS
Dim sc As Long, b1 As Long
Dim sum As Single
For X = 0 To BANDS - 1
sum = 0
b1 = 2 ^ (X * 10# / (BANDS - 1))
If (b1 > 1023) Then b1 = 1023
If (b1 <= b0) Then b1 = b0 + 1 ' make sure it uses at least 1 FFT bin
sc = 10 + b1 - b0
Do
sum = sum + fft(1 + b0)
b0 = b0 + 1
Loop While b0 < b1
Y = Sqrt(sum / Log10(sc)) * 3 * SPECHEIGHT - 4 ' scale it
If (Y > SPECHEIGHT) Then Y = SPECHEIGHT ' cap it
Y = Y - 1
While (Y >= 0)
Call FillMemory(specbuf(Y * SPECWIDTH + X * 13), 13 - 2, Y + 1)
Y = Y - 1
Wend
Next X
End If
' update the display
' to display in a PictureBox, simply change the .hDC to Picture1.hDC
Call SetDIBitsToDevice(frmSpectrum.hDC, 0, 0, SPECWIDTH, SPECHEIGHT, 0, 0, 0, SPECHEIGHT, specbuf(0), bh, 0)
--------------------------------------------------------------------------------------
code of frmspectrum
.
.
.
With bh.bmiHeader
.biBitCount = 8
.biPlanes = 1
.biSize = Len(bh.bmiHeader)
.biWidth = specwidth
.biHeight = SPECHEIGHT ' upside down (line 0=bottom)
.biClrUsed = 256
.biClrImportant = 256
End With
.
.
.
------------------------------------------------------------------------
i modified the SPECWIDTH to 656 and SPECHEIGHT to 500
but the spectrum was inclined (maybe ,if the value of specwidth was a multiple of 4 . it seems to be OK).
and overflow error was occured
how can i controll this problem ?
please let me know.
thanks.
-
Hi ;D
I'll check it out today a bit later :)
edit
Still didn't have time to check it... sorry.
-
Hi ;D
Sorry, I didn't have time to check it, but I see Ian has already posted a reply in BASS forum:
here's a link: http://www.un4seen.com/forum/?topic=6568.msg44103#msg44103
I didin't test it.
-
very thank you !! JOBnick!! ;)