|
-
Sep 6th, 2002, 05:14 PM
#1
Thread Starter
Lively Member
DirectSound3D - Muting the sound at max distance
Hi. This ones for the sound guys. I am using DSBCAPS_MUTE3DATMAXDISTANCE to mute the sound (save processing power) when the sound goes beyond the max distance from the listener. However, attenuation stops at max distance but the sound does not mute. Any ideas please. I have included the relevant code (I think this is all u need). Cheers.
------ CODE START ----------------------------
Private Sub cmdInit_Click()
On Error GoTo ErrHandler
If cmdInit.Caption = "INITIALISE" Then
cmdInit.Caption = "REINITIALISE"
sbAngle.Enabled = True
sbDistance.Enabled = True
sbVolume.Enabled = True
sbVelX.Enabled = True
sbVelY.Enabled = True
sbVelZ.Enabled = True
sbDoppler.Enabled = True
sbRollOff.Enabled = True
End If
cmdPlay.Enabled = True
cmdStop.Enabled = False
If ObjPtr(DSListen) Then Set DSListen = Nothing
If ObjPtr(DSPrimBuffer) Then Set DSPrimBuffer = Nothing
If ObjPtr(DSBuffer3D) Then Set DSBuffer3D = Nothing
If ObjPtr(DSBuffer) Then
DSBuffer.Stop
Set DSBuffer = Nothing
End If
BufferDesc.lFlags = DSBCAPS_CTRL3D Or DSBCAPS_CTRLVOLUME Or DSBCAPS_GETCURRENTPOSITION2 Or DSBCAPS_MUTE3DATMAXDISTANCE
Set DSBuffer = DS.CreateSoundBufferFromFile(App.Path & "\blip.wav", BufferDesc)
If Option1.Value Then BufferDesc.guid3DAlgorithm = GUID_DS3DALG_NO_VIRTUALIZATION
If Option2.Value Then BufferDesc.guid3DAlgorithm = GUID_DS3DALG_HRTF_LIGHT
If Option3.Value Then BufferDesc.guid3DAlgorithm = GUID_DS3DALG_HRTF_FULL
Set DSBuffer = DS.CreateSoundBufferFromFile(App.Path & "\blip.wav", BufferDesc)
Set DSBuffer3D = DSBuffer.GetDirectSound3DBuffer
' Setup DSBuffer
DSBuffer.SetVolume sbVolume.Value
' End setup
' Setup DSBuffer3D
DSBuffer3D.SetPosition Sin(sbAngle.Value * RAD) * sbDistance.Value, 0, Cos(sbAngle.Value * RAD) * sbDistance.Value, DS3D_DEFERRED
DSBuffer3D.SetMinDistance 10, DS3D_DEFERRED
DSBuffer3D.SetMaxDistance 90, DS3D_DEFERRED
DSBuffer3D.SetVelocity sbVelX.Value, sbVelY.Value, sbVelZ.Value, DS3D_DEFERRED
DSBuffer3D.SetConeAngles 90, 180, DS3D_DEFERRED
DSBuffer3D.SetConeOrientation 0, 0, -1, DS3D_DEFERRED
DSBuffer3D.SetConeOutsideVolume -2500, DS3D_DEFERRED
' End setup
PrimBufferDesc.lFlags = DSBCAPS_CTRL3D Or DSBCAPS_PRIMARYBUFFER Or DSBCAPS_MUTE3DATMAXDISTANCE
Set DSPrimBuffer = DS.CreatePrimarySoundBuffer(PrimBufferDesc)
Set DSListen = DSPrimBuffer.GetDirectSound3DListener
Set DSPrimBuffer = Nothing
' Setup DSListen
DSListen.SetPosition 0, 0, 0, DS3D_DEFERRED
DSListen.SetOrientation 0, 0, 1, 0, 1, 0, DS3D_DEFERRED
DSListen.SetDopplerFactor sbDoppler.Value / 10, DS3D_DEFERRED
DSListen.SetRolloffFactor sbRollOff.Value / 10, DS3D_DEFERRED
' End setup
DSListen.CommitDeferredSettings
Exit Sub
ErrHandler:
cmdExit_Click
Debug.Print "cmdInit_Click" & " - Error : " & Err.Description
End Sub
Private Sub cmdPlay_Click()
DSBuffer.Play DSBPLAY_LOOPING
cmdPlay.Enabled = False
cmdStop.Enabled = True
End Sub
------------------ END CODE ----------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|