I’ve decided to release this mostly because most of the code isn’t mine (credits for 90% of the code go to Damian666, I’ve really just fixed up a few things, cleaned it up, optimised it and added fading out) so I should really share it but also because I’ve mostly been bitching around here lately.
BASS is a sound library that allows you to play, from what I’ve noticed, most, if not all, formats. As a personal recommendation I suggest you use OGG simply because they are not tied under a license, the file size is still small and the quality is even better than MP3.
So let’s start with the modules. Add these two modules to your project (Put the modules in your /src/ folder, hit Ctrl-D, select Existing and point it to the location of the modules). The first module, modBass adds library functions and the second, modSound adds playback functionality.
Next you will also need the .DLL file required to run the BASS library, you can get that here.
Now what we have is essentially a working music engine. There is one final thing for people who like smooth fading out though.
At the start of the GameLoop add:
Dim TmrMusicFade as Long
And somewhere else in the GameLoop:
' Music fading If TmrMusicFade < Tick And ShouldMusicFade Then If MusicVolume - 0.1 > 0 Then MusicVolume = MusicVolume - 0.1 Call SetVolume(MusicIndex, MusicVolume) Else MusicFaded = True ShouldMusicFade = False PlayMusic NewSong End If TmrMusicFade = Tick + 100 End If
This will make sure that your music fades out before the new song is played. If you want the song to simply fade out without going onto the next one then call PlayMusic like so:
This will make it transition to an empty song which it simply won’t play.
If you do not want a song to fade out then call PlayMusic like so:
PlayMusic "songhere.ogg", True
The true tells PlayMusic to simply ignore the fading out code.
This is a bit advanced, I understand, but hopefully I’ve explained it in an easy to follow way. If not feel free to ask any questions. Once again, 90% of the credits for this code goes to Damian666 who creared the initial module.