Normally for game coders a sound library is low level.
The primary functionality are loading and playing sounds.
It comes with some tools to make more complex tasks by the user of the library.
Tools are:
Left and right channel paning
Volume control
different playback speed
10 user defined EQ's
Sound callbacks.
...
With this tools you an create:
Realistic 3D sounds with doppler effect
Indore vs outdoor switchable setups.
Sound sources with cone or sphere characteristic.
Inside the callback's you can calculate any DSP effect
and many more ...
I would encapsulate my sound objects from the low level stuff
like this pseudo code:
Code: Select all
type hWave as integer
type hSound as integer
type tWavePool
declare function Load(Path as string) as hWave
as hWave Poll()
' ...
end type
type tSound
declare constructor(WaveID as hWave)
declare constructor(Path as string)
declare constructor(nSamples as integer, nChannesl as integer=2)
declare function Play(nLoops as integer=1) as boolean
declare function PlayFrom(timeStart as double, nLoops as integer=1) as boolean
declare function PlayTo(timeEnd as double, nLoops as integer=1) as boolean
declare function PlayRange(timeStart as double, timeEnd as double, nLoops as integer=1) as boolean
declare property Pan as single
declare property Pan(value as single)
declare property Speed as single
declare property Speed(value as single)
...
as hSound ID
end type
type tSound3D extends tSound2D
declare sub setPosition(x as single, x as single, z as single)
declare sub getPosition(byref x as single, byref x as single, byref z as single)
declare sub setVelocity(x as single, x as single, z as single)
declare sub getVelocity(byref x as single, byref x as single, byref z as single)
declare sub setCone(angle as single=60, umbra as single, penumbra as single)
declare sub getCone(byref angle as single,byref umbra as single,byref penumbra as single)
declare sub setSphere(radius as single)
declare sub getSphere(byref radius as single)
enum eMode
bothoff
cone
sphere
end enum
declare sub setMode(mode as eMode)
...
end type
type tEffect extends tSound
declare sub setEQ(index as integer, centerFrequency as single, db as single)
declare sub getEQ(index as integer, byref centerFrequency as single, byref db as single)
declare sub enableEQ(index as integer, onoff as boolean)
declare sub setEcho(roomSize as single, delaytime as single, intensity as single)
declare sub getEcho(byref roomSize as single, byref delayTime as single, byref intensity as single)
declare sub enableEcho(onoff as boolean)
...
end type
type tEffect3D extends tEffect
declare sub setDoppler(factor as single, minFrequency as single, db as single)
declare sub getDoppler(byref factor as single, byref minFrequency as single, byref db as single)
declare sub enableDoppler(onoff as boolean)
declare sub setEcho3D(roomWidth as single, roomHeight as single, roomDepth as single, intensity as single)
declare sub getEcho3D(byref roomWidth as single, byref roomHeight as single, byref roomDepth as single, byref intensity as single)
declare sub enableEcho3D(onoff as boolean)
...
end type