' DS4QB++ v1.0 Test 1 : This program demonstrates some of the coolest
' features DS4QB++ has to offer.

DEFINT A-Z

'$INCLUDE: 'DEXTERN.BI'

CLS

PRINT "Initializing DS4QB++...";
' Initialize DS4QB++ using the sound quality specified by SETUP.EXE,
' and default initialization flags
R = DS4QB.Init(CURRENT, DEFAULT)

IF R = -1 THEN
  PRINT "Error! Essential file missing!": END
 ELSEIF R = -3 THEN
  PRINT "Error! Please run SETUP.EXE!": END
 ELSEIF R = -2 THEN
  PRINT "Error! Could not connect to slave!": END
END IF

PRINT "Done.": PRINT

' Print out what OS group was select by the user in the setup
IF DS4QB.GetOS = WIN9X THEN
  PRINT "DS4QB++ is running under Windows 95/98/ME configuration."
 ELSE
  PRINT "DS4QB++ is running under Windows NT/2000/XP configuration."
END IF

PRINT

PRINT "Loading soundfx... (Mp3 compressed!)"

' Load sounds from Sounds.raw
FOR I = 1 TO 6
 PRINT "Loading sound #"; LTRIM$(STR$(I)); "...";
 RawExtract "Sounds.raw", I, "Temp.Mp3"
 DS4QB.LoadSound I, "Temp.Mp3", DEFAULT
 PRINT "Done."
NEXT

PRINT
PRINT "Loading music... (Also Mp3 compressed!)"

' Load music from Music.raw
FOR I = 1 TO 2
 PRINT "Loading music #"; LTRIM$(STR$(I)); "...";
 RawExtract "Music.raw", I, "Temp.Mo3"
 DS4QB.LoadMusic I, "Temp.Mo3", DEFAULT
 PRINT "Done."
NEXT

KILL "Temp.mp3"
KILL "Temp.mo3"

PRINT
PRINT "All done, press keys [1] - [6] to test a sound, [S] to switch musics"

CurMusic = 1

' Set the global music volume to 100, and leave the sound volume alone.
DS4QB.SetGlobalVolumes CURRENT, 100

' Start the fade in process
DS4QB.MusicFadeIn DEFAULT, CurMusic + 1, DEFAULT, StartTemp

DO
 Key$ = UCASE$(INKEY$)

 SELECT CASE Key$
  CASE "1" TO "6"
   ' Play the sound slot the user selected, use a random frequency between
   ' 11Khz and 44Khz, a random volume between 25 and 50, and a random pan
   ' setting between full left and full right.
   DS4QB.PlaySoundEx VAL(Key$), INT(RND * 33038) + 11012, INT(RND * 25) + 25, INT(RND * 200) - 100, CURRENT
  CASE "S"
   ' Start the switch fade process
   IF SwitchTemp = 0 AND EndTemp = 0 AND StartTemp = 0 THEN
    CurMusic = (CurMusic + 1) AND 1
    DS4QB.MusicFadeSwitch DEFAULT, ((CurMusic + 1) AND 1) + 1, DEFAULT, CurMusic + 1, SwitchTemp
   END IF
  CASE CHR$(27)
   ' Start the fade out process
   IF EndTemp = 0 AND SwitchTemp = 0 AND StartTemp = 0 THEN DS4QB.MusicFadeOut DEFAULT, CurMusic + 1, DEFAULT, EndTemp
 END SELECT

 ' Continue the fade in/out/switch processes if necessary
 IF StartTemp THEN DS4QB.MusicFadeIn DEFAULT, CurMusic + 1, DEFAULT, StartTemp
 IF SwitchTemp THEN DS4QB.MusicFadeSwitch DEFAULT, ((CurMusic + 1) AND 1) + 1, DEFAULT, CurMusic + 1, SwitchTemp
 IF EndTemp THEN
  DS4QB.MusicFadeOut DEFAULT, CurMusic + 1, DEFAULT, EndTemp
  IF EndTemp = 0 THEN EXIT DO
 END IF
LOOP

PRINT

PRINT "Shutting down DS4QB++...";
' Close down DS4QB++
DS4QB.Close
PRINT "Done."

' We're done!

