''
'' A Freebasic IrrKlang Interface Test
'' F.Dodd (2006)
''
'' This is a pure test of creating a wrapper DLL for IrrKlang simplifying its
'' C++ architecture and providing a basic but functional Audio SDK for languages
'' that are not object oriented. At the moment this provides very few calls and
'' is merely a test for implementing such an interface.
''
'' This source uses Irrlicht definitions created by the Irrlicht authors
''

'' ////////////////////////////////////////////////////////////////////////////
'' Instructions to link the required DLL's
#inclib "IrrKlangWrapper"
#inclib "IrrKlang"

'' ////////////////////////////////////////////////////////////////////////////
'' Enumerated Type Definitions

ENUM E_STREAM_MODE
    ESM_AUTO_DETECT = 0,
    ESM_STREAMING,
    ESM_NO_STREAMING,
    ESM_FORCE_32_BIT = &h7fffffff
END ENUM


'' ////////////////////////////////////////////////////////////////////////////
'' Constant Definitions
#define IRR_KLANG_FALSE 0
#define IRR_KLANG_TRUE 1

'' ////////////////////////////////////////////////////////////////////////////
'' Type Definitions

TYPE irr_sound as UINTEGER PTR


'' ////////////////////////////////////////////////////////////////////////////
'' System Functions

' only one irrklang device object is supported by this wrapper. this call creates
' the device object that is exposed to FreeBasic
declare sub IrrKlangStart CDECL alias "IrrKlangStart" (  )

' Set the global sound volume
declare sub IrrKlangSetSoundVolume CDECL alias "IrrKlangSetSoundVolume" ( _
    byval volume as single )

' Play a 2D sound
declare function IrrKlangPlay2D CDECL alias "IrrKlangPlay2D" ( _
    byval file as zstring ptr, _
    byval playLooped as uinteger = IRR_KLANG_FALSE, _
    byval startPaused as uinteger = IRR_KLANG_FALSE, _
    byval track as uinteger = IRR_KLANG_FALSE, _
    byval streamMode as E_STREAM_MODE = ESM_AUTO_DETECT, _
    byval enableSoundEffects as uinteger = IRR_KLANG_FALSE ) as irr_sound

' Play a 3D sound
declare function IrrKlangPlay3D CDECL alias "IrrKlangPlay3D" ( _
    byval file as zstring ptr, _
    byval posX as single, _
    byval posY as single, _
    byval posZ as single, _
    byval playLooped as uinteger = IRR_KLANG_FALSE, _
    byval startPaused as uinteger = IRR_KLANG_FALSE, _
    byval track as uinteger = IRR_KLANG_FALSE, _
    byval streamMode as E_STREAM_MODE = ESM_AUTO_DETECT, _
    byval enableSoundEffects as uinteger = IRR_KLANG_FALSE ) as irr_sound


' Pause all sounds
declare sub IrrKlangSetAllSoundsPaused CDECL alias "IrrKlangSetAllSoundsPaused" ( _
    byval volume as integer )

' Stop all sounds
declare sub IrrKlangStopAllSounds CDECL alias "IrrKlangStopAllSounds" ( )

' Remove a specific sound file from memory
declare sub IrrRemoveSoundSource CDECL alias "IrrRemoveSoundSource" ( _
    byval file as zstring ptr )

' Stop all sounds and remove all sound files from memory
declare sub IrrKlangRemoveAllSoundSources CDECL alias "IrrKlangRemoveAllSoundSources" ( )

' Set the position of the listener for 3D sounds
declare sub IrrKlangSetListenerPosition CDECL alias "IrrKlangSetListenerPosition" ( _
    byval posX as single, _
    byval posY as single, _
    byval posZ as single, _
    byval lookX as single, _
    byval lookY as single, _
    byval lookZ as single, _
    byval velocityX as single = 0, _
    byval velocityY as single = 0, _
    byval velocityZ as single = 0, _
    byval upX as single = 0, _
    byval upY as single = 1, _
    byval upZ as single = 0 )

' Stop the sound engine
declare sub IrrKlangStop CDECL alias "IrrKlangStop" ( )


'' ////////////////////////////////////////////////////////////////////////////
'' Sound Functions

' Release the sound
declare sub IrrReleaseSound CDECL alias "IrrReleaseSound" ( byval sound as irr_sound )

' Get the length of the sound in milliseconds
declare function IrrKlangGetPlayLength CDECL alias "IrrKlangGetPlayLength" ( byval sound as irr_sound ) as uinteger

' Get the position of play in the sound in milliseconds
declare function IrrKlangGetPlayPosition CDECL alias "IrrKlangGetPlayPosition" ( byval sound as irr_sound  ) as uinteger

' Determine if a sound has finished playing
declare function IrrKlangIsFinished CDECL alias "IrrKlangIsFinished" ( byval sound as irr_sound  ) as uinteger

' Pause and unpause the sound
declare sub IrrKlangSetIsPaused CDECL alias "IrrKlangSetIsPaused" ( byval sound as irr_sound, byval pause as uinteger  )

' Set the playback speed of the sound
declare sub IrrKlangSetPlaybackSpeed CDECL alias "IrrKlangSetPlaybackSpeed" ( byval sound as irr_sound, byval speed as single  )

' Set the playback position of the sound
declare sub IrrKlangSetPlayPosition CDECL alias "IrrKlangSetPlayPosition" ( byval sound as irr_sound, byval position as uinteger )

' Set the position of the sound in 3D space
declare sub IrrKlangSetPosition CDECL alias "IrrKlangSetPosition" ( _
    byval sound as irr_sound, _
    byval posX as single, _ )
    byval posY as single, _ )
    byval posZ as single )

' Set the volume of the sound
declare sub IrrKlangSetVolume CDECL alias "IrrKlangSetVolume" ( byval sound as irr_sound, byval volume as single  )

' Set the minimum distance at which the sound can be heard
declare sub IrrKlangSetMinDistance CDECL alias "IrrKlangSetMinDistance" ( byval sound as irr_sound, byval distance as single  )

' Stop the sound playing
declare sub IrrKlangStopSound CDECL alias "IrrKlangStopSound" ( byval sound as irr_sound  )

'returns if the sound is paused
declare function IrrKlangGetIsPaused CDECL alias "IrrKlangGetIsPaused" ( byval sound as irr_sound  ) as uinteger

'returns volume of the sound
Declare Function IrrKlangGetVolume CDECL alias "IrrKlangGetVolume" ( byval sound as irr_sound) as single

'sets the pan of the sound
declare sub IrrKlangSetPan CDECL alias "IrrKlangSetPan" (byval sound as irr_sound,byval pan as single)

'returns the pan of the sound
declare function IrrKlangGetPan CDECL alias "IrrKlangGetPan" (byval sound as irr_sound) as single

'returns if the sound has been started to play looped
declare function IrrKlangIsLooped CDECL alias "IrrKlangIsLooped" ( byval sound as irr_sound  ) as uinteger

'changes the loop mode of the sound
declare sub IrrKlangSetIsLooped CDECL alias "IrrKlangSetIsLooped" ( byval sound as irr_sound, byval looped as uinteger  )

'Returns the minimal distance if this is a 3D sound
Declare Function IrrKlangGetMinDistance CDECL alias "IrrKlangGetMinDistance" ( byval sound as irr_sound  ) as single

'Sets the maximal distance if this is a 3D sound
declare sub IrrKlangSetMaxDistance CDECL alias "IrrKlangSetMaxDistance" ( byval sound as irr_sound, byval distance as single  )

'Returns the maximal distance if this is a 3D sound
Declare Function IrrKlangGetMaxDistance CDECL alias "IrrKlangGetMaxDistance" ( byval sound as irr_sound  ) as single

'Returns the playback speed set by setPlaybackSpeed()
Declare Function IrrKlangGetPlaybackSpeed CDECL alias "IrrKlangGetPlaybackSpeed" ( byval sound as irr_sound  ) as single

'Returns amount of loaded sound source
declare function IrrKlangGetSoundSourceCount CDECL alias "IrrKlangGetSoundSourceCount" () as integer

'Returns master sound volume
declare function IrrKlangGetSoundVolume CDECL alias "IrrKlangGetSoundVolume" () as single


'Returns if a sound with the specified name is currently playing
declare function IrrIsCurrentlyPlaying CDECL alias "IrrIsCurrentlyPlaying" ( _
    byval file as zstring ptr) as irr_sound

'Returns if irrKlang is running in the same thread as the application or is using multithreading
declare sub IrrKlangIsMultiThreaded CDECL alias "IrrKlangIsMultiThreaded" ( )

'Sets the default minimal distance for 3D sounds
declare sub IrrKlangSetDefault3DSoundMinDistance CDECL alias "IrrKlangSetDefault3DSoundMinDistance" ( byval sound as irr_sound, byval distance as single  )

'Returns the default minimal distance for 3D sounds
Declare Function IrrKlangGetDefault3DSoundMinDistance CDECL alias "IrrKlangGetDefault3DSoundMinDistance" ( byval sound as irr_sound  ) as single

'Sets the default maximal distance for 3D sounds
declare sub IrrKlangSetDefault3DSoundMaxDistance CDECL alias "IrrKlangSetDefault3DSoundMaxDistance" ( byval sound as irr_sound, byval distance as single  )

'Returns the default maximal distance for 3D sounds
Declare Function IrrKlangGetDefault3DSoundMaxDistance CDECL alias "IrrKlangGetDefault3DSoundMaxDistance" ( byval sound as irr_sound  ) as single

'Sets a rolloff factor which influences the amount of attenuation that is applied to 3D sounds
declare sub IrrKlangSetRolloffFactor CDECL alias "IrrKlangSetRolloffFactor" ( byval sound as irr_sound, byval rolloff as single  )

'Sets parameters affecting the doppler effect
'Declare Function IrrKlangSetRolloffFactor CDECL alias "IrrKlangSetRolloffFactor" ( byval sound as irr_sound, byval dopplerFactor as single , byval distanceFactor as single  )
