Qbasicnews.com

Full Version: Playing sound in FB.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Remember PLAY in QB? Well, that doesn't seem to work in FB - only BEEP. So is there some intrinsic command that allows WAV or MP3 loading (and playing) in FB? If so, what is it, and if not, someone point me to a lib or just a set of subroutines for sound.
Danke.
[edit]I downloaded a lib called BASS. Any ideas how to use it?
rtfm
FB should come with Bass headers and import libraries prebuilt. I haven't looked too deeply into 0.15 yet, but I've used Bass in 0.14, so I'll throw ya a bone here as for some basics of how to use it.

Code:
BASS_GetVersion ' returns the version...I ignore it, heh
If BASS_Init(1, 44100, 0, 0, 0) = BASSFALSE Then
  ' if this happens, you got no sound
Else
  If BASS_Start = BASSFALSE Then
    ' if this happens, you got no sound again
  End If
End If
That should be enough to get the lib started.

When you're done with it, do this:

Code:
BASS_Stop
BASS_Free
which stops all playback and unloads the library. You're advised to remove any resources manually though using the "Free" functions, such as BASS_MusicFree. Anyways, there's two kinds of music that Bass supports: mods and streams. Loading mods is easy:

Code:
ModHandle = BASS_MusicLoad(BASSFALSE, FileToLoad, 0, 0, BASS_MUSIC_RAMP + BASS_MUSIC_LOOP, 0)
BASS_MusicPlay ModHandle
That's the basics...there's more to it but that should get you started for those. For streams, it's similar:

Code:
StreamHandle = BASS_StreamCreateFile(BASSFALSE, FileToLoad, 0, 0, 0)
BASS_StreamPlay StreamHandle, BASSFALSE, BASS_SAMPLE_LOOP

To load samples, you do something similar to this:

Code:
SampleHandle = BASS_SampleLoad(BASSFALSE, FileToLoad, 0, 0, 3, BASS_SAMPLE_OVER_POS)
and to play it back:
Code:
BASS_SamplePlayEx SampleHandle, 0, -1, -1, 0, BASSFALSE

Look up all the details for this in the Bass help file. What I've posted here should get you started though.
Ah, that's the type of answer I need. Thanks Nek.

But, there are problems.
Code:
#include "c:\fbasic\freebasic\lib\win32\def\bassmod.dll.def"
#include "c:\fbasic\freebasic\lib\win32\def\bass.dll.def"
BASS_GetVersion ' returns the version...I ignore it, heh
If BASS_Init(1, 44100, 0, 0, 0) = BASSFALSE Then
  ' if this happens, you got no sound
Else
  If BASS_Start = BASSFALSE Then
    ' if this happens, you got no sound again
  End If
End If
ModHandle=BASS_musicLoad(BASSFALSE,"c:\mmp3.mp3",0,0,3,BASS_SAMPLE_OVER_POS)
BASS_SamplePlayEx SampleHandle, 0, -1, -1, 0, BASSFALSE
sleep
BASS_Stop
BASS_Free
The two #include's are the .def files with the names bass included with the FB package.
On mmp3.mp3 is a random song.
On compile it generates an error in the includes, first line...do they need to be modified before use or something?
First of all, you either use bass or bassmod but never both.

Second of all, you use the bi file, not the def file.
OK, thanks.
Now it's coming up with this error:
C:\FBASIC\FreeBASIC\lib\win32/bass.dll: file not recognized: File format not recognized

I copied bass.dll (which came with the bass distro that I downloaded) pretty much everywhere: the folder of the .bi, the folder of the FB program itself, the lib folder, the lib\win32 folder, etc.
What are you trying to do with the DLL? You won't need it until runtime.
Yes - and runtime is now.
Code:
#include "bass.bi"
BASS_GetVersion ' returns the version...I ignore it, heh
If BASS_Init(1, 44100, 0, 0, 0) = BASSFALSE Then
  ' if this happens, you got no sound
Else
  If BASS_Start = BASSFALSE Then
    ' if this happens, you got no sound again
  End If
End If
ModHandle=BASS_musicLoad(BASSFALSE,"c:\mmp3.mp3",0,0,3,BASS_SAMPLE_OVER_POS)
BASS_SamplePlayEx SampleHandle, 0, -1, -1, 0, BASSFALSE
sleep
BASS_Stop
BASS_Free
The aforementioned error occurs.
Use the bass.dll that comes with FB instead, the import table is likely different enough to cause problems. I don't think FB's included bass.dll has been updated since FB was released...I think it's time for a new def.
Okie Dokie...
Now ld.exe says it cannot find -lbass.
Pages: 1 2 3