Exemplo n.º 1
0
        public static void PlaySound3d(SecondarySoundBuffer Sound, bool bCloseFirst, bool bLoopSound, double x, double y, double z)
        {
            lock (playLock)
            {
                SoundBuffer3D DS3DBuffer = new SoundBuffer3D(Sound);
                //stop currently playing waves?
                if (bCloseFirst)
                {
                    Sound.Stop();
                    Sound.CurrentPosition = 0;
                }
                //set the position
                DS3DBuffer.Position = Get3DVector(x, y, z);

                //loop the sound?
                if (bLoopSound)
                {
                    Sound.Play(0, SharpDX.DirectSound.PlayFlags.Looping);
                }
                else
                {
                    Sound.Play(0, SharpDX.DirectSound.PlayFlags.None);
                }
                DS3DBuffer.Dispose();
            }             //lock
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets up a new Sound based on an <see cref="XSound"/> asset.
        /// </summary>
        /// <param name="sound">The <see cref="XSound"/> asset to get the audio data from.</param>
        public Sound3D(XSound sound) : base(sound)
        {
            #region Sanity checks
            if (sound == null)
            {
                throw new ArgumentNullException(nameof(sound));
            }
            #endregion

            _buffer3D = new SoundBuffer3D(SoundBuffer);
        }
Exemplo n.º 3
0
        public static SecondarySoundBuffer LoadSound3d(string FileName, double MDistance, double MaxDistance, bool useFull3DEmulation)
        {
            if (isFromResource)
            {
                FileName = FileName.Split('.')[0];
            }
            SoundBufferDescription BufferDesc = new SoundBufferDescription();

            if (!File.Exists(FileName))
            {
                throw new ArgumentException("The sound " + FileName + " could not be found.");
            }


            BufferDesc.Flags = SharpDX.DirectSound.BufferFlags.Control3D
                               | SharpDX.DirectSound.BufferFlags.ControlVolume
                               | SharpDX.DirectSound.BufferFlags.ControlFrequency
                               //| SharpDX.DirectSound.BufferFlags.StickyFocus
                               | SharpDX.DirectSound.BufferFlags.Mute3DAtMaxDistance;
            // if (useFull3DEmulation)
            //BufferDesc.AlgorithmFor3D = DirectSound3DAlgorithmGuid.FullHrt3DAlgorithm;
            SecondarySoundBuffer theBuffer = null;

            if (!isFromResource)
            {
                AudioFile wFile = new AudioFile(new FileStream(FileName, FileMode.Open));
                byte[]    final = wFile.getRawWaveData();
                BufferDesc.Format      = wFile.format();
                BufferDesc.BufferBytes = final.Length;
                theBuffer = new SecondarySoundBuffer(objDS, BufferDesc);
                theBuffer.Write(final, 0, LockFlags.EntireBuffer);
                wFile.close();
            }
            else
            {
                byte[]    data  = Encrypter.getData(FileName, pass);
                AudioFile wFile = new AudioFile(data);
                byte[]    final = wFile.getRawWaveData();
                BufferDesc.Format      = wFile.format();
                BufferDesc.BufferBytes = final.Length;
                theBuffer = new SecondarySoundBuffer(objDS, BufferDesc);
                theBuffer.Write(final, 0, LockFlags.EntireBuffer);
                wFile.close();
            }

            SoundBuffer3D DS3DBuffer = new SoundBuffer3D(theBuffer);

            DS3DBuffer.MinDistance = (float)MDistance;
            DS3DBuffer.MaxDistance = (float)MaxDistance;
            DS3DBuffer.Dispose();
            return(theBuffer);
        }
 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;
 }