private void ShutdownDirectSound() { // Release the listener interface. _Listener?.Dispose(); _Listener = null; // Release the 3D Secondary Sound Buffer. _3DSecondarySoundBuffer?.Dispose(); _3DSecondarySoundBuffer = null; // Release the primary sound buffer pointer. _PrimaryBuffer?.Dispose(); _PrimaryBuffer = null; // Release the direct sound interface pointer. _DirectSound?.Dispose(); _DirectSound = null; }
public static void setOrientation(SoundListener3D l, double x1, double y1, double z1, double x2, double y2, double z2) { Vector3 front = new Vector3((float)x1, (float)y1, (float)z1); Vector3 top = new Vector3((float)x2, (float)y2, (float)z2); if (l == null) { DSBListener.FrontOrientation = front; DSBListener.TopOrientation = top; } else { l.FrontOrientation = front; l.TopOrientation = top; } }
public static void setListener(double X1, double Y1, double Z1, double X2, double Y2, double Z2) { //if this is the first time calling this method, //instantiate the listener, //else just reset its position if (DSBListener == null) { SoundBufferDescription BufferDesc = new SoundBufferDescription(); BufferDesc.Flags = SharpDX.DirectSound.BufferFlags.PrimaryBuffer | SharpDX.DirectSound.BufferFlags.Control3D; primaryBuffer = new PrimarySoundBuffer(objDS, BufferDesc); //Finally, instantiate the listener using the PrimaryBuffer object DSBListener = new SoundListener3D(primaryBuffer); DSBListener.RolloffFactor = 1.0f; //Apply rolloff //according to realism. DSBListener.DistanceFactor = 0.3048f; } //To set orientation, a listener3DOrientation object must be passed which contains values for front.x,y,z, Etc. DSBListener.Position = Get3DVector(0.0, 0.0, 0.0); setOrientation(DSBListener, X1, Y1, Z1, X2, Y2, Z2); }
// Private Methods. private bool InitializeDirectSound(IntPtr windowHandler) { try { // Initialize the direct sound interface pointer for the default sound device. _DirectSound = new DirectSound(); try { _DirectSound.SetCooperativeLevel(windowHandler, CooperativeLevel.Priority); } catch { return(false); } // Setup the primary buffer description. SoundBufferDescription primaryBufferDesc = new SoundBufferDescription() { Flags = BufferFlags.PrimaryBuffer | BufferFlags.ControlVolume | BufferFlags.Control3D, AlgorithmFor3D = Guid.Empty }; // Get control of the primary sound buffer on the default sound device. _PrimaryBuffer = new PrimarySoundBuffer(_DirectSound, primaryBufferDesc); _Listener = new SoundListener3D(_PrimaryBuffer); _Listener.Deferred = false; _Listener.Position = new Vector3(0.0f, 0.0f, 0.0f); } catch (Exception) { return(false); } return(true); }