DQBplaySound
SUB

Prototype

DECLARE SUB DQBplaySound (BYVAL Slot, BYVAL Voice, BYVAL Freq, BYVAL LoopFlag)

Parameters

Slot - Slot holding the sound data

Voice - Sound channel to use

Freq - Playing frequency

LoopFlag - Specifies to play the sound once or repeatedly

Returns

none

Description

Plays a sound effect previously stored into EMS by the DQBloadSound function into a specified slot. The voice parameter can range from 1 to the maximum number of voices specified when calling DQBinstallSB, and tells which sound channel to use. If LoopFlag is 0, the sound is played once, while if the LoopFlag is 1 the sound is looped. There are two constants defined into DIRECTQB.BI that helps you using the LoopFlag parameter: they are the ONCE and the LOOPED constants. The DQB sound engine supports sound resampling: you specify the output frequency for each sound you play, and the sound will be resampled and played in realtime.

Notes:

If you play a sound while another one is still playing on the same voice, the old one is stopped and the new starts. To stop any sound playing on a voice, call DQBstopVoice.

Example

*****************************************************************************

' All integers for speed
DEFINT A-Z

'$INCLUDE:'DIRECTQB.BI'

' Let's initialize the library with no extra layer nor EMS, and one sound
IF DQBinit(0, 1, 0) THEN DQBclose: PRINT DQBerror$: END

' Frees 16K of base memory for the sound engine volume table
dummy& = SETMEM(-17000)

' Initializes the sound engine, by passing 220h as the base address and by
' autodetecting the IRQ and DMA settings. 2 voices are initialized, sampling
' rate is set to 22 KHz, and the volume table is built.
IF DQBinstallSB(TRUE, 2, 22050, &H220, AUTO, AUTO) THEN
    ' Bad initialization
    DQBclose
    PRINT DQBerror$
    END
END IF

' Asks the user for the location of a WAV file to load
INPUT "Insert the WAV file name to load:", File$

' Loads the sound in memory
IF DQBloadSound(1, File$) THEN DQBclose: PRINT DQBerror$: END

PRINT "Press a key to exit..."

' Plays sound 1 at 22 Khz on voice 2 once
DQBplaySound 1, 2, 22050, ONCE

' Waits a key
WHILE INKEY$ = "": WEND

' Turns off the sound engine (that's not really needed, as it's automatically
' done for you by the DQBclose function)
DQBremoveSB

' Ends program
DQBclose
dummy& = SETMEM(17000)

*****************************************************************************