'' ----------------------------------------------------------------------------
'' IrrKlang Wrapper for Imperative Languages - Freebasic Examples
'' Frank Dodd (2009)
'' ----------------------------------------------------------------------------
'' Example 04: Controling Sounds
'' This simple example allows the user to control the sound with keys
'' ----------------------------------------------------------------------------

'' ////////////////////////////////////////////////////////////////////////////
'' Includes for extension libraries
#include "IrrKlangWrapper.bi"

'' ////////////////////////////////////////////////////////////////////////////
'' global variables
DIM LastTime as Double
DIM sound as irr_sound
DIM volume as single
DIM keyString as string
DIM pauseState as uinteger = IRR_KLANG_TRUE
DIM speed as single = 0.5

'' ////////////////////////////////////////////////////////////////////////////
'' GDB debugger main() function

' start the irrklang sound engine
IrrKlangStart

' Play a sound in 3D space
sound = IrrKlangPlay2D ( "./media/getout.ogg", _
        IRR_KLANG_FALSE, IRR_KLANG_FALSE, IRR_KLANG_TRUE )

' list some instructions
? "Press 'Q' to end"
? "Press 'P' to pause"
? "Press 'space' to display the play position in the track"
? "Press 'D' to switch between half speed and normal speed"
Do
    ' get any user input
    keyString = inkey

    ' pause the sound
    if keyString = "p" then
        IrrKlangSetIsPaused( sound, pauseState )
        
        ' toggle the pause flag
        if pauseState = IRR_KLANG_TRUE then pauseState = IRR_KLANG_FALSE else pauseState = IRR_KLANG_TRUE 
    end if

    if keyString = " " then
        ? "Play position is ";IrrKlangGetPlayPosition( sound );"ms"
    end if

    if keyString = "d" then
        IrrKlangSetPlaybackSpeed ( sound, speed )

        ' switch between normal and half speed
        if speed = 1.0 then speed = 0.5 else speed = 1.0
    end if

Loop Until keyString = "q"

' Stop the urrklang sound engine and release resources
IrrKlangStop
