Beispiel #1
0
        override public void Dispose(bool disposing)
        {
            // If you need thread safety, use a lock around these
            // operations, as well as in your methods that use the resource.
            if (!m_disposed)
            {
                if (disposing)
                {
                    if (m_description3d != null)
                    {
                        m_description3d.Dispose();
                    }

                    if (m_secondaryBuffer != null)
                    {
                        m_secondaryBuffer.Dispose();
                    }

                    if (m_buffer3d != null)
                    {
                        m_buffer3d.Dispose();
                    }
                }

                m_description3d   = null;
                m_secondaryBuffer = null;
                m_buffer3d        = null;

                // Indicate that the instance has been disposed.
                m_disposed = true;
            }
        }
Beispiel #2
0
 protected override void SetDescriptionFlags(ref Microsoft.DirectX.DirectSound.BufferDescription desc)
 {
     desc.Control3D = true;
     desc.Mute3DAtMaximumDistance = true;
     desc.Guid3DAlgorithm         = DSoundHelper.Guid3DAlgorithmHrtfFull;
     base.SetDescriptionFlags(ref desc);
 }
        protected virtual void Dispose(bool disposing)
        {
            // If you need thread safety, use a lock around these
            // operations, as well as in your methods that use the resource.
            if (!m_disposed)
            {
                if (disposing)
                {
                    if (m_descriptionListener != null)
                    {
                        m_descriptionListener.Dispose();
                    }

                    if (m_primary3d != null)
                    {
                        m_primary3d.Dispose();
                    }

                    if (m_listener3d != null)
                    {
                        m_listener3d.Dispose();
                    }
                }

                m_descriptionListener = null;
                m_primary3d           = null;
                m_listener3d          = null;

                // Indicate that the instance has been disposed.
                m_disposed = true;
            }
        }
Beispiel #4
0
 private void init_dx()
 {
     try
     {
         sound_card = new Device();
         sound_card.SetCooperativeLevel(this, CooperativeLevel.Priority);
     }
     catch
     {
         MessageBox.Show("Failed to create a sound card, check your directX version\nTheSoftware will run in compatibility mode. It will NOT sound good as it can only play one sound at a time");
         return;
     }
     try
     {
         description = new BufferDescription();
         description.ControlVolume    = true;
         description.LocateInSoftware = true;
     }
     catch
     {
         MessageBox.Show("Failed to create a sound buffer, check your directX version\nTheSoftware will run in compatibility mode. It will NOT sound good as it can only play one sound at a time");
         sound_card.Dispose();
         sound_card = null;
         return;
     }
 }
        public Listener(System.Windows.Forms.Form form, Object3D object_listening)
        {
            m_listener = object_listening;
            Sound.BufferDescription description = new Sound.BufferDescription();
            Sound.WaveFormat        fmt         = new Sound.WaveFormat();
            description.PrimaryBuffer = true;
            description.Control3D     = true;
            Sound.Buffer buff = null;

            fmt.FormatTag             = Sound.WaveFormatTag.Pcm;
            fmt.Channels              = 2;
            fmt.SamplesPerSecond      = 22050;
            fmt.BitsPerSample         = 16;
            fmt.BlockAlign            = (short)(fmt.BitsPerSample / 8 * fmt.Channels);
            fmt.AverageBytesPerSecond = fmt.SamplesPerSecond * fmt.BlockAlign;

            applicationDevice.SetCooperativeLevel(form, Sound.CooperativeLevel.Priority);

            // Get the primary buffer and set the format.
            buff        = new Buffer(description, Device);
            buff.Format = fmt;

            applicationListener = new Listener3D(buff);
            listenerParameters  = applicationListener.AllParameters;
        }
Beispiel #6
0
        public Sound2d(string file, DirectSound.Device device)
        {
            // 2d setup
            m_description2d = new DirectSound.BufferDescription();
            m_description2d.ControlEffects        = false;
            m_description2d.ControlVolume         = true;
            m_description2d.GlobalFocus           = true;
            m_description2d.ControlPositionNotify = true;

            m_secondaryBuffer = new DirectSound.SecondaryBuffer(file, m_description2d, device);

            m_notify = new DirectSound.Notify(m_secondaryBuffer);
        }
Beispiel #7
0
 public void addSecondaryBufferAndPlay(string filePath, string name)
 {
     if (!dic.ContainsKey(name))
     {
         Microsoft.DirectX.DirectSound.BufferDescription buffDes =
             new Microsoft.DirectX.DirectSound.BufferDescription();
         buffDes.GlobalFocus   = true; //设置缓冲区全局获取焦点
         buffDes.ControlVolume = true; //指明缓冲区可以控制声音
         buffDes.ControlPan    = true; //指明缓冲区可以控制声道平衡
         SecondaryBuffer sb = new SecondaryBuffer(filePath, buffDes, device);
         dic.Add(name, sb);
         sb.Play(0, BufferPlayFlags.Looping);
     }
 }
Beispiel #8
0
        public Sound3d(string file, DirectSound.Device device)
        {
            m_description3d = new DirectSound.BufferDescription();
            m_description3d.ControlEffects        = false;
            m_description3d.GlobalFocus           = true;
            m_description3d.Control3D             = true;
            m_description3d.ControlVolume         = true;
            m_description3d.Guid3DAlgorithm       = DirectSound.DSoundHelper.Guid3DAlgorithmHrtfFull;
            m_description3d.ControlPositionNotify = true;

            m_secondaryBuffer = new DirectSound.SecondaryBuffer(file, m_description3d, device);

            m_buffer3d          = new DirectSound.Buffer3D(m_secondaryBuffer);
            m_buffer3d.Position = new SoundVector(0, 0, 1);
            m_buffer3d.Mode     = DirectSound.Mode3D.Normal;

            m_notify = new DirectSound.Notify(m_secondaryBuffer);
        }
        public SoundListener3d(DirectSound.Device device)
        {
            // 3d setup
            m_descriptionListener = new DirectSound.BufferDescription();

            m_descriptionListener.ControlEffects = false;
            m_descriptionListener.Control3D      = true;
            m_descriptionListener.ControlVolume  = true;
            m_descriptionListener.PrimaryBuffer  = true;

            m_primary3d  = new DirectSound.Buffer(m_descriptionListener, device);
            m_listener3d = new DirectSound.Listener3D(m_primary3d);

            // default orientation
            DirectSound.Listener3DOrientation o = new DirectSound.Listener3DOrientation();
            o.Front = new Microsoft.DirectX.Vector3(0, 0, 1);   // facing forward
            o.Top   = new Microsoft.DirectX.Vector3(0, 1, 0);   // standing upright

            m_listener3d.Orientation = o;
        }
Beispiel #10
0
        } // initGfx().fim

        // [---
        public void inicializarSom()
        {
            string som_arquivo = @"c:\gameprog\gdkmedia\som\shoot.wav";

            // Cria um dispositivo de som
            radio = new DirectSound.Device();

            // Estabelece o nível de cooperação
            radio.SetCooperativeLevel(this, DirectSound.CooperativeLevel.Normal);
            // <b>
            // Configura descrição do som
            DirectSound.BufferDescription desc = new DirectSound.BufferDescription();

            // Habilita controle de pan
            desc.ControlPan = true;

            // Habilita foco global. Efeito sonoro toca mesmo enquanto a aplicação
            // está em segundo plano
            desc.GlobalFocus = true;

            // Cria um objeto SecondaryBuffer que toca o som
            som = new DirectSound.SecondaryBuffer(som_arquivo, desc, radio);
            // </b>
        } // inicializarSom().fim
Beispiel #11
0
        /// <summary>
        /// Funkcja inicjujaca dzialanie silnika dzwiekowego (laczy sie z karta
        /// dzwiekowa, tworzy niezbedne obiekty (tablica dzwiekow, listener,
        /// glowny bufor dzwiekowy, obiekt szukajacy sciezek do plikow)
        /// </summary>
        /// <param name="owner">Obiekt (Forms), w ktorym ma byc umieszczony 
        /// silnik dzwiekowy</param>
        /// <param name="distanceFactor">Czynnik odleglosci</param>
        /// <param name="roloffFactor">Czynnik roloff</param>
        /// <param name="volume">Glosnosc</param>
        public static void InitializeEngine(Control owner, int volume,
            float distanceFactor, float roloffFactor)
        {
            //karta dzwiekowa
            soundCard = new DS.Device();
            soundCard.SetCooperativeLevel(owner, CooperativeLevel.Normal);

            //lista dzwiekow
            soundList = new ArrayList();

            //listener
            primaryBufferDescription = new BufferDescription();
            primaryBufferDescription.ControlEffects = false;
            primaryBufferDescription.Control3D = true;
            primaryBufferDescription.PrimaryBuffer = true;
            primaryBufferDescription.ControlVolume = true;
            primaryBuffer = new DS.Buffer(primaryBufferDescription, soundCard);
            primaryBuffer.Volume = volume;

            listener = new Listener3D(primaryBuffer);
            listener.DistanceFactor = distanceFactor;
            listener.RolloffFactor = roloffFactor;

            //muzyka w tle

            //SourceNameFinder
            nameFinder = new SourceNameFinder();
        }
Beispiel #12
0
 public bool PlaySoundStream()
 {
     bool functionReturnValue = false;
     //   Plays the .wav stream with the selected Playback device
     //   Returns True if no errors False otherwise...
     System.DateTime dttStartPlay = default(System.DateTime);
     int intTrace = 0;
     Status stcStatus = null;
     if (!blnCodecStarted)
         return false;
     if ((memWaveStream == null))
     {
         Logs.Exception("[PlaySoundFile] memWaveStream is nothing");
         return false;
     }
     else if (objPlayback != null && objPlayback.Status.Playing)
     {
         Logs.Exception("[PlaySoundFile] objPlayback is Playing, Call AbortWaveStream");
         AbortSoundStream();
     }
     intTrace = 1;
     try
     {
         intTrace = 2;
         devSelectedPlaybackDevice.SetCooperativeLevel(this.Handle, CooperativeLevel.Priority);
         //dttStartWaveStreamPlay = Now
         KeyPTT(true);
         // Activate PTT before starting sound play
         Microsoft.DirectX.DirectSound.BufferDescription bufPlaybackFlags = new Microsoft.DirectX.DirectSound.BufferDescription();
         // The following flags required to allow playing when not in focus and
         // to allow adjusting the volume...
         bufPlaybackFlags.Flags = (BufferDescriptionFlags)BufferDescriptionFlags.GlobalFocus + BufferDescriptionFlags.ControlVolume;
         intTrace = 3;
         memWaveStream.Seek(0, SeekOrigin.Begin);
         // reset the pointer to the origin
         intTrace = 4;
         objPlayback = new SecondaryBuffer(memWaveStream, bufPlaybackFlags, devSelectedPlaybackDevice);
         objPlayback.Volume = Math.Min(-5000 + 50 * MCB.DriveLevel, 0);
         // -5000=off, 0=full volume
         intTrace = 5;
         objPlayback.Play(0, BufferPlayFlags.Default);
         //objWMProtocol.SetCaptureState(CaptureState.Transmitting)
         dttTestStart = Now;
         dttStartPlay = Now;
         intTrace = 6;
         // wait up to 300 ms for start of playback.
         while (Now.Subtract(dttStartPlay).TotalMilliseconds < 300 & !objPlayback.Status.Playing)
         {
             Thread.Sleep(10);
         }
         intTrace = 7;
         if (objPlayback.Status.Playing)
         {
             intTrace = 8;
             if (MCB.DebugLog)
                 Logs.WriteDebug("[PlaySoundStream] Stream: " + strLastWavStream);
             stcStatus.ControlName = "lblXmtFrame";
             stcStatus.Text = strLastWavStream;
             stcStatus.BackColor = Color.LightSalmon;
             queTNCStatus.Enqueue(stcStatus);
             stcStatus.ControlName = "lblRcvFrame";
             stcStatus.BackColor = SystemColors.Control;
             stcStatus.Text = "";
             queTNCStatus.Enqueue(stcStatus);
             functionReturnValue = true;
         }
         else
         {
             intTrace = 9;
             KeyPTT(false);
             functionReturnValue = false;
             //objWMProtocol.SetCaptureState(CaptureState.SearchForLeader)
             Logs.WriteDebug("[PlaySoundStream] Failure to start objPlayback");
             Logs.Exception("[PlaySoundStream] Failure to start objPlayback");
         }
     }
     catch (Exception e)
     {
         Logs.Exception("[PlaySoundStream] Kill PTT on exception: " + e.ToString + "  intTrace=" + intTrace.ToString);
         KeyPTT(false);
         functionReturnValue = false;
         //objWMProtocol.SetCaptureState(CaptureState.SearchForLeader)
     }
     return functionReturnValue;
 }
Beispiel #13
0
 public SecondaryBuffer(string fileName, BufferDescription desc, Device parent) : base(fileName, desc, parent)
 {
     throw new NotImplementedException();
 }
Beispiel #14
0
 public SecondaryBuffer(Stream source, BufferDescription desc, Device parent) : base(source, desc, parent)
 {
     throw new NotImplementedException();
 }
Beispiel #15
0
 public SecondaryBuffer(BufferDescription desc, Device parent) : base(desc, parent)
 {
     throw new NotImplementedException();
 }