Applogies if I step on someones toes or upset someone but I gota say the example included for VB users is very poor.
I would like to see a much better example released and would be willing to hand over source code for my player to Brett if he is interested, here is a snapshot of it in action.
Yes the skin is a rip off of a winamp skin. The label1 to which you see is the scroller for the song name, to which I havn’t quite finished. However the code is heavly documented, uses a class module to handle fmod intergration, and uses some apis calls for blitting and timer handling. Supports playlists, ect.. Overall its a much better sample and would help most VB users.
Again applogies if I upset anyone with this post, but everyone I have talked to said the VB example is crap.
<font size=-1>[ This Message was edited by: Cire on 2002-02-27 12:39 ]</font>
Hey, your code seems extremely clean and documented
And thats a good thing for an example!
Maybe you could try something like the following code for the spectrum. I’ve tried it in my BPM detection program and it looks much better.
It is made using some suggestions in this forum on the same way winamp calculates the frequency bands.
You will need to get the first 300 values or so from the spectrum in order for this to work.
vline is just a function I wrote to quickly draw a rectangle with a lot of options.
Public Sub DrawSpectrum()
Dim interval As Double
Dim height As Long
Dim hdc As Long
Dim a As Long, b As Long, c As Long, d As Long
Dim tmpVal As Single
Static total(31) As Single
interval = picSpectrum.ScaleWidth / 200
height = picSpectrum.ScaleHeight
hdc = picSpectrum.hdc
vLine hdc, 0, 0, picSpectrum.ScaleWidth, height, vbBlack
interval = picSpectrum.ScaleWidth / 16
b = 0
Dim cnt As Single
For a = 0 To 15
If a = 0 Then d = 2 If a = 1 Then d = 2 If a = 2 Then d = 3 If a = 3 Then d = 4 If a = 4 Then d = 5 If a = 5 Then d = 7 If a = 6 Then d = 9 If a = 7 Then d = 11 If a = 8 Then d = 14 If a = 9 Then d = 17 If a = 10 Then d = 21 If a = 11 Then d = 26 If a = 12 Then d = 32 If a = 13 Then d = 38 If a = 14 Then d = 45 If a = 15 Then d = 52 cnt = 0 For c = 1 To d cnt = cnt + dsp_Spectrum2(b) b = b + 1 Next If cnt <> 0 Then total(a) = (total(a) * 1 + Log(cnt)) / 2 Else total(a) = (total(a) * 9) / 10 End If tmpVal = (total(a) + 1) / 2 vLine hdc, interval * a + 1, height, interval * (a + 1) - 1, height - tmpVal * height, vbGreen
Could You post the vline function? Currently what I do is draw the spectrum on a seperate picturebox, 1 frame behind, then blit images, so the specturm is really 1 frame behind this helps greatly with speed.
More or less loop blt’s image to spectrum, clears old picture in hiden picturebox, and draws a new one.
Would u mind posting your vline sub?
If you send me your e-mail adress (to firstname.lastname@example.org) I will send it to you (it’s too long to post here).
You will also need win32.tlb or manually look up the windows functions using the windows api viewer.
What you should do when drawing a picture is make sure the picturebox is autoredraw=true.
Then you clear the picture using a rectangle from left-top to right-bottom with the back-color. This is a lot faster then using the .cls method of the picturebox.
Then you draw all the other stuff, preferably with the windows api equivalents of the visual basic functions (FillRect, SetPixelV, LineTo, …)
All can be added using the windows api viewer, and documentation can be found on msdn.microsoft.com
You can also put the hdc of the picturebox (pic.hdc) in a variable before drawing. This also saves a lot of time.
When the picture is drawn, you just call pic.Refresh to update the screen and voila, you’re finished.
I started to clone the Brett’s FMOD player in VB but, because of lack of time, i stop it temporarly. I restarted 2 days ago, hope i ll finish it soon but don’t expect to much from this example, it will show the same things Brett show plus some tricks for VB users.
In another registre, i also started my lamer brain project based on FMOD : a winamp ‘clone’ in VB. For now, it works fine, exepts for plugins (work in progress, thanx to BlackShard), have an advanced playlist manager, load winamp skins (without bugs !), recquire low cpu/ram, use a lot of API, is multithreaded, protected (mutex), have a basic winamp EQ ‘clone’ (load/save EQF) … The pb is that the code in unreadable (+ 20 000 lines of code) !!!
Hey Cire, you’re concurrent of me!
http://web.tiscali.it/sababros/Download … 1beta2.exe
or else (if above don’t work/too slow):
http://www.sababros.bbk.org/Download/fP … 1beta2.exe
Sorry for the size (1.64Mb) but I think it worths
I am assuming you are using my source code. I’am not quite sure what version of source you have but shoud lbe able to adapt it for all versions. Simply remove the create timer api and kill timer apis for the specturm then call the drawspectrum function passing any appropriate data.
Theres been another topic on this, I’ve made a pretty nice example in VB showing how to do spectrum analysis, VU, calculating bitrate, volume change, etc… Take a look at it…
- Paranoid_Android answered 16 years ago
I have written the current example and I must agree that it is not a good example.
I always wanted to write a better one, but I just didn’t have the time yet to do it.
Your player looks great. If the code is indeed clear and documented then I think this should replace the current example.
Thanks Aidon I did not mean to insult your code and I’am glad you guys are open to public code submiting. Here is a brief snip of my main form declaration and first function. I will clean it up before I submit the code if Brett gives the go ahead.
‘ Author: Mark St. Louis (Contact email@example.com) aka Cire
‘Created: November 29, 2001
‘ Notes: Requires Fmod to power the player.
‘ Note to Newbies:
‘ You should really get in the habbit of using Option Explicit.
‘ It really does help in debugging code when u have to define all your
‘ variables correctly, amongst other things.
‘ Option base 0 instructs the compilter that we want to have a 0 element in
‘ our arrays, I belive this is the default but I set it outa habit anyhow.
Option Base 0
‘ The below 3 variables are handles to timers. We know that VB timers
‘ are not very accurate, slow and overall just plainly suck. Thus we
‘ use the Windows API to setup some timers for us, These variables are
‘ more or less a handle to that timer, we need them so when we shut down
‘ we can remove the timer calls, so that VB does not crash.
Private lngTimerID As Long ‘ This Timer that updates EQ.
Private lngTimerIDVU As Long ‘ This Timer updates the VU meter.
Private lngTimerIDOther As Long ‘ This timer updates everything else.
‘ The Spec variable is a an array to which we can aquire the current
‘ specturm from FMOD, we really only use 0->72 but I init for 144, and
‘ add anything over 72 to the other bands. Anything less then 144 is
‘ pretty much sleepy anyhow. See code below in ‘DrawEQ’ for more details.
Private Spec(144) As Single
‘ LastVu is a modied variable indicating our last reading of FMOD’s VU reading
‘ We keep track of it so that we can do a sliding scale for the volume.
‘ What I mean for that is, in one reading VU might be 89, next it might
‘ be 12, we don’t wana jump around like that so i use a slide of -5 if
‘ its lower then the last reading, this gives a ‘smoothing’ effect. Again
‘ See code below in ‘DrawVU’ for more details
Private LastVu As Long
‘ H,W are simple variables that indicate the eq’s Height and Width. Since
‘ we use these frequently I set a reference to them. Really I should
‘ change these to const but I’am not positive I want them this size yet.
Private H As Long
Private W As Long
‘ SongFileName is the ‘full path and filename’ of the song we are currently
Dim SongFileName As String
‘ The below 2 variables ScrollX and ScrollString are used to handle the
‘ scroll window, ie the song name.
Private ScrollX As Long
Private ScrollString As String
‘ DrawEQ is true if we should draw the EQ, this is toggleable via the EQ button
‘ on the player.
Private DrawEQ As Boolean
‘ RepeatMode indicates if we should repeat the song or playlist, again it
‘ is toggable via the player.
Private RepeatMode As Boolean
‘ Mp3Player is a class object. It is the heart of the player. Pretty much
‘ handles all the player to FMOD intergration. There are many useful
‘ functions contained within it that will make your life easier. See
‘ the code within Mp3Class for more details.
Public Mp3Player As Mp3Class
‘ The below class object enables us to support playlists. It works on the same
‘ princple as winamp m3u files, thus can read and write m3u files that work
‘ jointly with winamp. See the code within it for more details.
Public PlayList As PlayListClass
‘ Begin Code
‘ Sub: StartTimer
‘ Created: 11/31/01
‘ Notes: Starts API timers, sets correct playstate image, and
‘ shows and sets the inital data for the song.
Private Sub StartTimer()
Dim i As Long
' Loop through the labels that display data on the song, such as ' KBPS, Output Frequency, channels, ect and set them to visible. For i = 0 To lblStatus.UBound lblStatus(i).Visible = True Next i imgPlayStatus(0).Visible = True ' Show the play image imgPlayStatus(1).Visible = False ' Hide Pause Image imgPlayStatus(2).Visible = False ' Hide Stop Image ' For more information on what below statements are see ' the functions within the classes. lblStatus(2).Caption = Mp3Player.GetKBPS ' Show our KBPS lblStatus(3).Caption = Mp3Player.OutPutRate(True) ' Show Output rate ' The 3 ifs will kill the timers just in case they are running. If lngTimerID > 0 Then lngTimerID = KillTimer(0, lngTimerID) If lngTimerIDVU > 0 Then lngTimerIDVU = KillTimer(0, lngTimerIDVU) If lngTimerIDOther > 0 Then lngTimerIDOther = KillTimer(0, lngTimerIDOther) ' Note: Subs called are in DLLDeclares ' Note to newbies: When messing with API Timers never use the stop button ' to stop a program running in debug mode, or else VB will crash, ' use the forums close button or something else that will trigger ' the forums 'unload' event. Or add a function that will remove ' the timers first. ' Set a windows API timer every 10ms, calling TimerProcEQ sub. 10ms is a ' bit extreme however ideally I will expand this to be configureable by ' the user. For now I like things FAST! :smile: lngTimerID = SetTimer(0, 0, 10, AddressOf TimerProcEQ) 'Set a Windows API timer every 25ms calling TimerProcVU sub, no need ' in calling this any faster then 25ms, since FMOD updates it every 25 ms. lngTimerIDVU = SetTimer(0, 0, 25, AddressOf TimerProcVU) ' Finally we need a timer that ticks about 1 second, that we can use to ' update the scrolling, play time, progress, ect.. lngTimerIDOther = SetTimer(0, 0, 1000, AddressOf TimerProcOther)
<font size=-1>[ This Message was edited by: Cire on 2002-02-27 13:53 ]</font>
Please login first to submit.