FMOD DSound - FX

Share your advanced PureBasic knowledge/code with the community.
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

FMOD DSound - FX

Post by Froggerprogger »

The following code checks the soundhardware for a hardware-channel-DSound-driver and initializes two FX and plays a bit with their parameters.

It uses fmod.dll for all of this.

Code: Select all

; FMOD - FX-example 
; 
; this small example shows how to use the DirectX - FX 
; 
; this program is written for FMOD 3.71 and needs the FMOD-Wrapper for PureBasic to compile 
; 
; by Froggerprogger, 25.02.04 

soundfile.s = OpenFileRequester("Choose a cool PCM-music soundfile (wav, mp3, etc.)...","","",0) 
If soundfile = "" : End : EndIf 

FSOUND_SetOutput(#FSOUND_OUTPUT_DSOUND) ; Dsound only for the use of FX 

Init_OK = #False 
For i=0 To FSOUND_GetNumDrivers() - 1 
  FSOUND_GetDriverCaps(i, @caps) 
  If caps & #FSOUND_CAPS_HARDWARE 
    Init_OK = #True 
    FSOUND_SetDriver(i) 
    Break 
  EndIf 
Next 
If Init_OK = #False 
  MessageRequester("","No DSound driver with hardwarechannels found. Cannot continue.", #MB_ICONERROR) 
  End 
EndIf 

numSoftChannels = 2 
HardCh_1 = numSoftChannels + 1 ; the hardwarechannel-IDs begin directly after the softwarechannels 

FSOUND_Init(44100, numSoftChannels,0) 

*sample = FSOUND_Sample_Load(#FSOUND_FREE, soundfile, #FSOUND_LOOP_NORMAL | #FSOUND_HW2D | #FSOUND_ENABLEFX, 0, 0) ; you might use #FSOUND_HW3D instead 

*channel = FSOUND_PlaySoundEx(HardCh_1, *sample, 0, #True) 
  ; First enable all the FX's (up to 16 per channel) before setting their parameters ! 
  *fx = FSOUND_FX_Enable(HardCh_1, #FSOUND_FX_PARAMEQ) 
  *fx2 = FSOUND_FX_Enable(HardCh_1, #FSOUND_FX_ECHO) 
  
  ; setting some parameters for the FX 
  FSOUND_FX_SetParamEQ(*fx, 8000, 12, -15) 
  FSOUND_FX_SetEcho(*fx2, 20, 12, 200, 600, #True) 

; start playing (you might use FSOUND_PlaySoundEx(HardCh_1, *sample, 0, #False) instead 
FSOUND_SetPaused(*channel, #False) 

;make some silly realtime-changes 
For i=0 To 30 
  FSOUND_FX_SetParamEQ(*fx, 8000, 12, -15+i) 
  FSOUND_FX_SetEcho(*fx2, 3*i, 12, 310-10*i, 620-20*i, #True) ; this could create clipping, because it's not the 'fine way' 
  Delay(400) 
Next 
Delay(500) 

For i=0 To 7800 Step 4 
  FSOUND_FX_SetParamEQ(*fx, 8000 - i, 4, 15) 
  Delay(1) 
Next 
Delay(1000) 

For i=255 To 0 Step -1 
  FSOUND_SetVolume(*channel, i) 
  Delay(1) 
Next 

FSOUND_StopSound(*channel) 
FSOUND_Close() 
MessageRequester("","End",#MB_ICONINFORMATION) 
%1>>1+1*1/1-1!1|1&1<<$1=1