This document describes the FBSound API V0.16.
All commands with parameters are listed. If you need clarification on any details, please take a look in the "/test" folder too. Every available command is used in the examples "testXYZ.bas"
FBSound is a free soundlib primarily for games and demos. The API interface is written for the open source FreeBASIC compiler. It supports dynamically loadable plugin/outs.
Linux x86 (alsa, oss, dsp, arts)
Windows 95, 98, 98SE, Me, NT, 2000, XP, 2000, (mm2)
Extract your FBSound download included with the folder tree.
*x.xx = current version (0.16) ...
fbsoundx.xx/
fbsoundx.xx/data
fbsoundx.xx/doc
fbsoundx.xx/lib
fbsoundx.xx/inc
fbsoundx.xx/src
fbsoundx.xx/tests
fbsoundx.xx/rebuildlib.bat
fbsoundx.xx/buildalltests.bat
fbsoundx.xx/rebuildlib.sh
fbsoundx.xx/buildalltests.sh
!!! optional for advanced users !!!
rebuild FBSound lib:
fbc must be in the PATH
cd fbsoundx.xx
Linux: sh ./rebuillib.sh
Windows: rebuildlib.bat
create all tests:
fbc must be in the PATH
Linux: sh ./buildalltests.sh
Windows: buildalltests.bat
Explanation about the type of parameters in this document.
|
nParam means a number (integer)
sParam means a floating point number (single)
blnParam means FBSBOOLEAN True or False (defined as 1 and 0)
strParam means chars (string)
@nParam means a ptr on number (integer)
@sParam means a ptr on floating point number (single)
@lpParam means a ptr on short ptr (16 bit samples)
@blnParam means a ptr on FBSBOOLEAN True or False (defined as 1 and 0)
[Param] means this param are optional
Function Summary: init/start/stop/exit FBSound.
|
fbs_Init([nRate],[nChannels],[nBuffers],[nFrames],[nIndex]) as FBSBOOLEAN
Setup any available playback devices. (internal: fbs_Start() will be called too)
|
fbs_Start() as FBSBOOLEAN
(optional) Start the sound threads.
|
fbs_Stop() as FBSBOOLEAN
(optional) Stop all running threads.
|
fbs_Exit() as FBSBOOLEAN
(optional) Remove FBSound (internal: fbs_Stop()
will be called if any threads are running)
|
Function Summary: load/create/remove wave objects in memory.
|
fbs_Load_WAVFile(strFilename,@hWave) as FBSBOOLEAN
Load any *.wav file in memory.
|
fbs_Load_MP3File(strFilename,@hWave [,strTmpFile as string]) as FBSBOOLEAN
Load any *.mp3 *.mp2 *.mp file in memory
|
fbs_Load_OGGFile(strFilename,@hWave [,strTmpFile as string]) as FBSBOOLEAN
Load any *.ogg file in memory
|
fbs_Create_Wave(nSamples,@hWave,@lpSamples) as FBSBOOLEAN
Create a new wave with nSamples samples in memory.
|
fbs_Create_Sound(hWave,@hSound) as FBSBOOLEAN
Create a playable sound hSound from the loaded wave hWave.
|
fbs_Destroy_Sound(@hSound) as FBSBOOLEAN
Remove any sound from memory.
|
fbs_Destroy_Wave(@hWave) as FBSBOOLEAN
Remove any wave from memory.
|
Function Summary: create/remove a stream object.
|
fbs_Create_MP3Stream(strFilename) as FBSBOOLEAN
Prepare a Stream for real-time decoding.
|
fbs_End_MP3Stream() as FBSBOOLEAN
Stop and remove an MP3Stream and its real-time decoder
|
Function Summary: play waves/sounds/streams.
|
fbs_Play_Wave(hWave,[nLoops],[sSpeed],[sVolume],[sPan],[@hSound]) as FBSBOOLEAN
Play a loaded hWave object and create an optional hSound object from it.
|
fbs_Play_Sound(hSound,[nLoops]) as FBSBOOLEAN
Play a created hSound object.
|
fbs_Play_MP3Stream() as FBSBOOLEAN
Play a prepared stream object.
|
Function Summary: get properties of an wave object.
|
fbs_Get_WavePointers(hWave,[@lpStart],[@lpEnd],[@nChannels]) as FBSBOOLEAN
Get current pointers, channels, and samples from playing sound.
|
Function Summary: get/set properties of an sound object.
|
fbs_Get_SoundLoops(hSound,@nLoops) as FBSBOOLEAN
Get the current number of sound loops.
|
fbs_Set_SoundLoops(hSound,nLoops) as FBSBOOLEAN
Set the new number of sound loops.
|
fbs_Get_SoundSpeed(hSound,@sSpeed) as FBSBOOLEAN
Get the passed sound's playback speed.
|
fbs_Set_SoundSpeed(hSound,sSpeed) as FBSBOOLEAN
Set the passed sound's playback speed.
|
fbs_Get_SoundVolume(hSound,@sVolume) as FBSBOOLEAN
Get the passed sound's volume.
|
fbs_Set_SoundVolume(hSound,sVolume) as FBSBOOLEAN
Set the passed sound's volume.
|
fbs_Get_SoundPan(hSound,@sPan) as FBSBOOLEAN
Get the passed sound's panning position.
|
fbs_Set_SoundPan(hSound,sPan) as FBSBOOLEAN
Set the passed sound's panning position.
|
fbs_Get_SoundMuted(hSound,@blnMuted) as FBSBOOLEAN
Get the passed sound's muted state.
|
fbs_Set_SoundMuted(hSound,blnMuted) as FBSBOOLEAN
Set the passed sound's muted state.
|
fbs_Get_SoundPaused(hSound,@blnPaused) as FBSBOOLEAN
Get the passed sound's pause state.
|
fbs_Set_SoundPaused(hSound,blnPaused) as FBSBOOLEAN
Set the passed sound's pause state.
|
fbs_Get_SoundPointers(hSound,[@lpStart],[@lpPlay],[@lpEnd]) as FBSBOOLEAN
Get pointers from sound object.
|
fbs_Set_SoundPointers(hSound,[lpStart],[lpPlay],[lpEnd]) as FBSBOOLEAN
Set pointers from sound object.
|
fbs_Get_SoundPosition(hSound,@sPosition) as FBSBOOLEAN
Get current playback position (0.0-1.0) from sound object.
|
Function Summary: get/set properties of a stream.
|
fbs_Get_StreamVolume(@sVolume) as FBSBOOLEAN
Get the passed stream's volume.
|
fbs_Set_StreamVolume(sVolume) as FBSBOOLEAN
Set the passed stream's volume.
|
fbs_Get_StreamPan(@sPan) as FBSBOOLEAN
Get the passed stream's panning position.
|
fbs_Set_StreamPan(sPan) as FBSBOOLEAN
Set the passed stream's panning position.
|
fbs_Get_StreamBuffer(@lpBuffer,@nChannels,@nSamples) as FBSBOOLEAN
Get the current stream's sample buffer.
|
The FBSound API in more details:
|
fbs_Init([nRate],[nChannesl],[nBuffers],[nFrames],[nIndex]) as FBSBOOLEAN
Setup a playback device. This function is the key to use FBSound and must be the first call. (test01.bas)
#include "../inc/fbsound.bi"
const data_path = "../data/"
' only if not same as exe path
' fbs_Set_PlugPath("./")
fbs_Init()
Parameters:
|
nRate as integer (Playback rate in Hz.)
Range: (6000-11025, 22050, 32000, 44100, 48000, 96000)
Default: 44100
|
nChannels as integer (Number of playback channels.)
Range: 1 = mono, 2 = stereo
Default: 2 (stereo)
|
nBuffers as integer (Number of playback buffers.)
Default: 3
|
nFrames as integer (Number of frames per buffer.)
Default: 2048
|
nIndex as integer (Specify which device should be used by default.)
Range: 0 = first, 1 = second, ...
Default: 0 (first device)
|
Returns:
|
False if an error occurred
True otherwise
|
functions: fbs_Start(), fbs_Stop(), fbs_Exit().
|
There is normally no need to use these functions manually.
fbs_Start() will be called internally from fbs_Init(). If any FreeBASIC program ends, fbs_Stop() and fbs_Exit() will be called internally too.
There is one reason to use these functions manually:
If you want to change the FBSound setup via fbs_Init() first call fbs_Stop() then fbs_Exit() . all playing waves/sounds/streams are stopped and removed from memory. Now use fbs_Init() with any new setup and reload/create waves/sounds/streams. (The old will be invalid)
Returns:
|
False if an error occurred
True otherwise
|
fbs_Set_PlugPath(strNewPath)
Normally fbs_Init() searches in the exepath for available dynamically loadable plugins/outs. If the exepath is not the folder with the dynamic libs you must call fbs_Set_PlugPath("newpath/") before you can use fbs_Init().
fbs_Set_PlugPath("../lib/")
fbs_Init()
Parameter:
|
NewPath as string
|
functions: fbs_Load_WAVFile(), fbs_Load_MP3File(), fbs_Load_OGGFile().
|
fbs_Load_WAVFile(strFileName,@hWave)
fbs_Load_MP3File(strFileName,@hWave)
fbs_Load_OGGFile(strFileName,@hWave)
Both functions load media files into the pool of memory waves.
The returned hWave is the ID of the new created wave and can be used with fbs_Play_Wave().
dim as integer hWave1,hWave2,hWave2
fbs_Init()
fbs_Load_WAVFile("anyfile.wav",@hWave1)
fbs_Load_MP3File("anyfile.mp3",@hWave2)
fbs_Load_OGGFile("anyfile.ogg",@hWave3)
fbs_Play_Wave(hWave1)
fbs_Play_Wave(hWave2)
fbs_Play_Wave(hWave3)
sleep
Parameters:
|
FileName as string (The file's name.)
@hWave as integer (The hWave to create.)
|
Returns:
|
False if an error occurred
True otherwise
|
function: fbs_Play_Wave().
|
fbs_Play_Wave(hWave, [nLoops], [sSpeed], [sVolume], [sPan],[@hSound])
Start playback of an hWave object. The wave can be loaded from either fbs_Load_WAVFile() or fbs_Load_MP3File() or created by fbs_Create_Wave(). Optional you can create an hSound object too. See get / set sound properties.
dim as integer hWave
fbs_Load_WAVFile("anywave.wav",@hWave)
fbs_Play_Wave(hWave)
Play an hWave object.
fbs_Play_Wave(hWave,3)
Loop hWave 3 times
fbs_Play_Wave(hWave,2,,,-1.0)
Loop hWave 2 times on the left channel
fbs_Play_Wave(hWave,,1.5)
Play hWave with 150% of the normal speed
Parameters:
|
hWave as integer (The ID of the wave in memory.)
nLoops as integer (Number of times to loop the sample.)
Range: 1 to 231
Default: 1
sSpeed as single (The sample's playback speed.)
Range: -4.0 (400% speed backwards) to +4.0 (400% speed forwards)
Default: 1.0 (100% speed forwards)
sPan as single (The sample's stereo location.)
Range: -1.0 (full left) to +1.0 (full right)
Default: 0.0 (center)
@hSound (optional: the new created hSound object.)
|
Returns:
|
False if an error occurred
True otherwise
|
functions: fbs_Create_Sound() and fbs_Play_Sound().
|
fbs_Create_Sound(hWave,@hSound) as FBSBOOLEAN
fbs_Play_Sound(hSound, [nLoops]) as FBSBOOLEAN
Create an hSound object hWave object with fbs_Create_Sound() . Start the hSound playback with fbs_Play_Sound()
The main difference between playing an hWave handle with fbs_Play_Wave() and playing an hSound handle with fbs_Play_Sound() is that you can change all properties of a playing hSound while it is playing/created/stopped or paused.
See get/set sound properties.
dim as integer hWave,hSound
fbs_Load_WAVFile("anywave.wav",@hWave)
fbs_Create_Sound(hWave,@hSound)
fbs_Play_Sound(hSound)
sleep
Create and play an hSound object:
fbs_Play_Sound(hSound,3)
Loop hSound 3 times
Parameters:
hWave as integer (The hWave to use.)
@hSound as integer (The hSound to create.)
Returns:
False if an error occurred
True otherwise
function: fbs_Get_WavePointes().
|
fbs_Get_WavePointers (hWave,@lpStart,@lpEnd,@nChannels) as FBSBOOLEAN
Parameters:
hWave as integer (The hWave whose properties to get.)
@lpStart as short ptr (The address of first sample in memory.)
Default: NULL
@lpEnd as short ptr (The address of last sample in memory.)
Default: NULL
@nChannesl integer ptr (The number of channels.)
Default: NULL
Returns:
False if an error occurred
True otherwise
functions: get/set sound properties.
|
fbs_Get_SoundLoops (hSound,@nLoops ) as FBSBOOLEAN
fbs_Set_SoundLoops (hSound, nLoops ) as FBSBOOLEAN
fbs_Get_SoundSpeed (hSound,@sSpeed ) as FBSBOOLEAN
fbs_Set_SoundSpeed (hSound, sSpeed ) as FBSBOOLEAN
fbs_Get_SoundVolume (hSound,@sVolume ) as FBSBOOLEAN
fbs_Set_SoundVolume (hSound, sVolume ) as FBSBOOLEAN
fbs_Get_SoundPan(hSound,@sPan ) as FBSBOOLEAN
fbs_Set_SoundPan(hSound, sPan ) as FBSBOOLEAN
fbs_Get_SoundMuted (hSound,@blnMuted ) as FBSBOOLEAN
fbs_Set_SoundMuted (hSound, blnMuted ) as FBSBOOLEAN
fbs_Get_SoundPaused (hSound,@blnPaused) as FBSBOOLEAN
fbs_Set_SoundPaused (hSound, blnPaused) as FBSBOOLEAN
fbs_Get_SoundPointers (hSound,@lpStart,@lpPlay,@lpEnd) as FBSBOOLEAN
fbs_Set_SoundPointers (hSound,lpStart,lpPlay,lpEnd) as FBSBOOLEAN
fbs_Get_SoundPosition (hSound,@sPosition) as FBSBOOLEAN
After you have created an hSound object with fbs_Create_Sound(), you can set any and all of its properties. It does not matter if the hSound is playing / freshly created / paused or muted, you can change the properties at any time.
The advantage: for an hWave object some of these properties can only be set once with fbs_Play_Wave()
Parameters:
hSound as integer (The hSound whose properties to set.)
nLoops as integer (The number of times to loop the hSound.)
Range: 1 to 231
Default: 1
sSpeed as single (The playback speed of the hSound.)
Range: -4.0 (400% speed backwards) to +4.0 (400% speed forwards)
Default: 1.0 (100% speed forwards)
sVolume as single (The hSound's playback volume.)
Range: 0.0 to 2.0
Default: 1.0
sPan as single (The hSound's stereo location.)
Range: -1.0 (full left) to +1.0 (full right)
Default: 0.0 (center)
blnMuted as FBSBOOLEAN (The muted state of the hSound.)
Range: True (no sound while playing default) or False (sound on)
Default: False
blnPaused as FBSBOOLEAN (The paused state of the hSound.)
Range: True (paused) or False (normal play)
Default: False
lpStart as short ptr (The first playable sample of the hSound.)
Default: NULL
lpPlay as short ptr (The play position of the hSound.)
Default: NULL
lpEnd as short ptr (The last playable sample of the hSound.)
Default: NULL
Returns:
False if an error occurred
True otherwise
functions: create/play/end an MP3Stream.
|
fbs_Create_MP3Stream(strFilename) as FBSBOOLEAN
fbs_Play_MP3Stream() as FBSBOOLEAN
fbs_Get_PlayingStreams() as integer
fbs_End_MP3Stream() as FBSBOOLEAN
Prepare an MP3Stream and it's real time decoder with fbs_Create_MP3Stream("filename") and begin stream playback with
fbs_Play_MP3Stream()
' prepare the real time decoder
fbs_Create_MP3Stream("../data/legends.mp3)
' start stream playback
fbs_Play_MP3Stream()
sleep
' prepare the real time decoder
fbs_Create_MP3Stream("../data/legends.mp3)
' start stream playback
fbs_Play_MP3Stream()
' wait of first decoded sound buffer
while fbs_Get_PlayingStreams()=0:sleep 10:wend
print "wait on end of stream or hit any key to quit."
while inkey="" and fbs_Get_PlayingStreams()>0
sleep 1000
wend
Parameters:
strFilename as string (The *.mp3 *.mp2 or *.mp FileName.)
Returns:
False if an error occurred
True otherwise
functions: get/set stream properties.
|
fbs_Get_StreamVolume(@sVolume) as FBSBOOLEAN
fbs_Set_StreamVolume( sVolume) as FBSBOOLEAN
fbs_Get_StreamPan(@sPan) as FBSBOOLEAN
fbs_Set_StreamPan( sPan) as FBSBOOLEAN
Parameters:
sVolume as single (The hSound's playback volume.)
Range: 0.0 to 2.0
Default: 1.0
sPan as single (The hSound's stereo location.)
Range: -1.0 (full left) to +1.0 (full right)
Default: 0.0 (center)
Returns:
False if an error occurred
True otherwise
functions: set/enable/disable user defined buffer callbacks.
|
type BUFFERCALLBACK as sub (
byval lpSamples as short ptr, _
byval nChannels as integer , _
byval nSamples as integer )
fbs_Set_MasterCallback(@YourCallback as BUFFERCALLBACK) as FBSBOOLEAN
fbs_Enable_MasterCallback() as FBSBOOLEAN
fbs_Disable_MasterCallback() as FBSBOOLEAN
fbs_Set_SoundCallback(hSound,@YourCallback as BUFFERCALLBACK) as FBSBOOLEAN
fbs_Enable_SoundCallback(hSound) as FBSBOOLEAN
fbs_Disable_SoundCallback(hSound) as FBSBOOLEAN
fbs_Set_StreamCallback(@YourCallback as BUFFERCALLBACK) as FBSBOOLEAN
fbs_Enable_StreamCallback() as FBSBOOLEAN
fbs_Disable_StreamCallback() as FBSBOOLEAN
After you have set and enabled a buffer callback it will be called for every new sound buffer.
The master buffer callback is called with all ready to use samples and is processed after the dsp and mixer pipeline. After this callback the buffer is sent to the current playback device.
The sound buffer callback is called for any sound object passed as an hSound and is processed before the dsp and mixer pipeline.
The stream buffer callback is called after a new buffer is decoded and is processed before the dsp and mixer pipeline.
You can read and write any sample of a new buffer from inside the callback. But be sure your sub will need not too much time because
the dsp and mixer thread will wait until your callback sub finishes.
Please take a look in the /test folder too.
"test15.bas" for mastercallback
"test16.bas" for soundcallbacks
"test17.bas" for streamcallback
Parameters:
hSound as integer (The sound ID.)
@YourCallback as BUFFERCALLBACK (Defined in fbstypes.bi)
Returns:
False if an error occurred
True otherwise
functions: set/enable/disable user defined load callback.
|
type LOADCALLBACK as sub (byval Percent as integer)
fbs_Set_LoadCallback(@YourLoadCallback as LOADCALLBACK) as FBSBOOLEAN
fbs_Enable_LoadCallback() as FBSBOOLEAN
fbs_Disable_LoadCallback() as FBSBOOLEAN
After you have set and enabled a load callback it will be called for every active file loading.
Please take a look in the /test folder.
"test29_a.bas"
"test29_b.bas"
functions: set/enable/disable one of 10 posible master band EQ's.
|
fbs_Set_MasterFilter(nFilter,sHz,sdB,[sOctave=1.0],[blnEnable=False]) as FBSBOOLEAN
fbs_Enable_MasterFilter(nFilter) as FBSBOOLEAN
fbs_Disable_MasterFilter(nFilter) as FBSBOOLEAN
You can set/enable/disable 10 posible master band EQ's.
The filters processed after the mixer pipeline. After this dsp section the buffer is sent to the current playback device.
Please take a look in the /test folder too.
"test18.bas" for fbs_Set_MasterFilter()
Parameters:
nFilter as integer (The filter ID 0-9.)
sHz as single (The center frequenc in Hz.)
sdB as single (The band volume in dB.)
sOctave as single (The optional band width in octaves default=1.0.)
blnOnOff as FBSBOOLEAN (The optional en/disable switch default=False)
Returns:
False if an error occurred
True otherwise
functions: simple translatition between volume and dB
|
fbs_Volume_2_dB(byval Volume) as single
fbs_dB_2_Volume(byval dB as single) as single
Please take a look in the /test folder too.
"test18.bas" for fbs_Volume_2_dB()
Parameters:
dB as single (dB to volume)
volume as single (volume to dB.)
Returns:
as single the translated value.
|