Esempio n. 1
0
 private void Stop()
 {
     if (buffer != null)
     {
         buffer.Stop();
     }
 }
Esempio n. 2
0
 public void SetBuffer(byte[] buffer)
 {
     if (_parent == null)
     {
         return;
     }
     if (_memoryStream != null)
     {
         _memoryStream.Dispose();
     }
     if (_sound != null && !_sound.Status.Terminated)
     {
         _sound.Stop();
     }
     if (buffer != null)
     {
         _memoryStream = new MemoryStream(buffer);
         _sound        = new Microsoft.DirectX.DirectSound.SecondaryBuffer(_memoryStream, _bufferDesc, _dev);
         //EffectDescription effs = new EffectDescription();
         //effs.GuidEffectClass = DSoundHelper.StandardInteractive3DLevel2ReverbGuid;
         //_sound.SetEffects(new EffectDescription[]{effs});
         _sound.Volume    = _conf.Volumee.Value;
         _sound.Frequency = _conf.Freqq.Value;
         updateSoundEffects(true);
         //setEffects();
     }
     else
     {
         _sound = null;
     }
 }
Esempio n. 3
0
        private NextNotificationTask HandleNewBytesInControlThread(int nextPlaceForBytes, int byteWindowSize, BufferNotificationEventArgs ea)
        {
            LockFlag lockFlag      = LockFlag.None;
            int      bytesObtained = ea.NewSoundByte.Length;

            if (bytesObtained > byteWindowSize)
            {
                SB.Stop();
                throw new ApplicationException("An event handler provided the streaming buffer with " + bytesObtained + " bytes of sound, but it only requested " + byteWindowSize + " bytes.");
            }
            else if (bytesObtained == byteWindowSize)
            {
                SB.Write(nextPlaceForBytes, ea.NewSoundByte, lockFlag);
            }
            else
            {
                // Fill the remainder of the segment with silence.
                if (ea.NewSoundByte.Length > 0)
                {
                    SB.Write(nextPlaceForBytes, ea.NewSoundByte, lockFlag);
                }
                SB.Write(nextPlaceForBytes + ea.NewSoundByte.Length, new byte[byteWindowSize - ea.NewSoundByte.Length], lockFlag);

                if (ea.SoundFinished)
                {
                    return(NextNotificationTask.FillSectionWithSilence);
                }
            }
            return(NextNotificationTask.FillSectionWithNewSound);
        }
Esempio n. 4
0
 // --------------------------------------------------------------------
 // Handle windows events
 // --------------------------------------------------------------------
 protected override void OnLostFocus(EventArgs e)
 {
     base.OnLostFocus(e);
     Paused = true;
     Text   = Gametitle + " - Paused";
     _wave.Stop();
 }
Esempio n. 5
0
 public void StartPlaying()
 {
     if (_enum10 == AudioStatus.ShouldStartAudio)
     {
         _secondaryBuffer0.Stop();
         _enum10 = AudioStatus.IsCurrentlyPlayingAudio;
     }
 }
Esempio n. 6
0
 public override void Code()
 {
     if (secondaryBuffer == null || secondaryBuffer.Disposed || mp3Stream == null)
     {
     }
     else
     {
         if (Playing)
         {
             if (secondaryBuffer.PlayPosition < halfSize)
             {
                 pos = true;
             }
             else
             {
                 pos = false;
             }
             if (pos != posb)
             {
                 if (pos)
                 {
                     backFilled = false;
                 }
                 else
                 {
                     foreFilled = false;
                 }
             }
             posb = pos;
             if (mp3Stream.Position < mp3Stream.Length)
             {
                 if (pos && !backFilled)
                 {
                     fillBack();
                     backFilled = true;
                 }
                 else if (!pos && !foreFilled)
                 {
                     fillFore();
                     foreFilled = true;
                 }
             }
             else
             {
                 //mp3Stream.Position = 0;
                 secondaryBuffer.Stop();
                 if (Loop)
                 {
                     playMP3();
                 }
                 else
                 {
                     Playing = false;
                 }
             }
         }
     }
 }
Esempio n. 7
0
 public void Pause()
 {
     if (sound == null)
     {
         return;
     }
     sound.Stop();
     Parent.PlayerUpdate = 2;
 }
Esempio n. 8
0
        void Form1_Disposed(object sender, EventArgs e)
        {
            Disconnect();

            if (null != ApplicationBuffer)
            {
                ApplicationBuffer.Stop();
            }
        }
        public void Play(string filename)
        {
            if (_buffer != null)
            {
                _buffer.Stop();
            }

            _buffer = new SecondaryBuffer(filename, _bufferDescription, _device);
            _buffer.Play(0, BufferPlayFlags.Default);
        }
Esempio n. 10
0
 public void Play(bool stopExisting, bool loop)
 {
     if (secbuf != null)
     {
         if (stopExisting)
         {
             secbuf.Stop();
         }
         secbuf.Play(0, loop ? BufferPlayFlags.Looping : BufferPlayFlags.Default);
     }
 }
Esempio n. 11
0
        private void btn_stop_Click(object sender, EventArgs e)
        {
            bufferSound.Stop();

            isSync.Enabled = true;  //enable sync checkbox;
            timer1.Enabled = false; //stop timer1
            sweepCnt       = 0;

            if (!bufferSound.Status.Playing)
            {
                btn_play.Enabled = true; Sweep.Enabled = true;
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Refresh the playback buffer with data from the stream.
        /// </summary>
        private void RefreshBuffer()
        {
            // variable to prevent least count errors in clip end time
            long safeMargin = CalculationFunctions.ConvertTimeToByte(1, SampleRate, FrameSize);

            while ((mPlayed < mPlayUntil - safeMargin) && !mAtLastRefresh)
            {
                if (mSoundBuffer.Status.BufferLost)
                {
                    mSoundBuffer.Restore();
                }
                Thread.Sleep(SLEEP_INCREMENT);
                // refresh the part of the buffer which the play cursor is not currently in (odd = front part)
                if ((mBufferCheck % 2 == 1) && mSoundBuffer.PlayPosition > mRefreshSize)
                {
                    mSoundBuffer.Write(0, mAudioStream, mRefreshSize, 0);
                    mPlayed += mRefreshSize;
                    mBufferCheck++;
                }
                else if ((mBufferCheck % 2 == 0) && mSoundBuffer.PlayPosition < mRefreshSize)
                {
                    mSoundBuffer.Write(mRefreshSize, mAudioStream, mRefreshSize, 0);
                    mPlayed += mRefreshSize;
                    mBufferCheck++;
                }
            }
            mAtEndOfAsset       = false;
            mBufferStopPosition = (mBufferCheck % 2 == 0 ? mRefreshSize : mBufferSize) - ((int)mPlayed - (int)mPlayUntil);
            int StopMargin = (int)CalculationFunctions.ConvertTimeToByte(70, SampleRate, FrameSize);

            if (mBufferStopPosition < StopMargin)
            {
                mBufferStopPosition = StopMargin;
            }
            int currentPos = mSoundBuffer.PlayPosition;

            while (currentPos < (mBufferStopPosition - StopMargin) || currentPos > mBufferStopPosition)
            {
                Thread.Sleep(SLEEP_INCREMENT);
                currentPos = mSoundBuffer.PlayPosition;
            }
            mBufferStopPosition = -1;
            mPausePosition      = 0;
            mSoundBuffer.Stop();
            mAudioStream.Close();
            ChangeState(PlayerState.Stopped);
            mIsEventEnabledDelayedTillTimer = mEnableEvents;
            mAtEndOfAsset = true;
        }
Esempio n. 13
0
        public void Dispose()
        {
            if (_wavePlayThread == null)
            {
                return;
            }
            try
            {
                _isFinished = true;
                Thread.MemoryBarrier();
                _fillEvent.Set();
                _cancelEvent.Set();
                _wavePlayThread.Join();

                if (_soundBuffer != null)
                {
                    if (_soundBuffer.Status.Playing)
                    {
                        _soundBuffer.Stop();
                    }
                    _soundBuffer.Dispose();
                }
                if (_notify != null)
                {
                    _notify.Dispose();
                }
                if (_device != null)
                {
                    _device.Dispose();
                }
                if (_fillEvent != null)
                {
                    _fillEvent.Dispose();
                }
                if (_frameEvent != null)
                {
                    _frameEvent.Dispose();
                }
                if (_cancelEvent != null)
                {
                    _cancelEvent.Dispose();
                }
            }
            finally
            {
                _wavePlayThread = null;
            }
        }
Esempio n. 14
0
        private void setBufferAndWave(double lengthFactor)
        {
            var waveFormat = new WaveFormat();

            waveFormat.SamplesPerSecond      = samplesPerSecond;
            waveFormat.Channels              = 2;
            waveFormat.FormatTag             = WaveFormatTag.Pcm;
            waveFormat.BitsPerSample         = 16;
            waveFormat.BlockAlign            = (short)(waveFormat.Channels * waveFormat.BitsPerSample / 8);
            waveFormat.AverageBytesPerSecond = waveFormat.BlockAlign * waveFormat.SamplesPerSecond;

            var bufferDesc = new BufferDescription(waveFormat);

            bufferDesc.DeferLocation    = true;
            bufferDesc.Control3D        = false;
            bufferDesc.ControlEffects   = false;
            bufferDesc.ControlFrequency = true;
            bufferDesc.ControlPan       = true;
            bufferDesc.ControlVolume    = true;
            bufferDesc.GlobalFocus      = true;
            bufferDesc.BufferBytes      = Convert.ToInt32(lengthFactor * DitLengthSecond *
                                                          waveFormat.AverageBytesPerSecond);

            if (buffer != null)
            {
                buffer.Stop();
                buffer.Dispose();
                buffer = null;
            }

            buffer = new SecondaryBuffer(bufferDesc, device);
            bufferDesc.Dispose();
            bufferDesc = null;
        }
Esempio n. 15
0
        private void playOrStopButton__Click(object sender, EventArgs e)
        {
            if (secondaryBuffer_ == null)
            {
                device_.SetCooperativeLevel(this, CooperativeLevel.Normal);

                bufferDescription_ = new BufferDescription()
                {
                    GlobalFocus           = true,
                    ControlVolume         = true,
                    ControlPositionNotify = true,
                };

                secondaryBuffer_ = new SecondaryBuffer(filePathTextBox_.Text, device_);
                secondaryBuffer_.Play(0, BufferPlayFlags.Default);

                playOrStopButton_.Text = "Stop";
                stopButton_.Enabled    = true;
            }
            else if (secondaryBuffer_.Status.Playing)
            {
                secondaryBuffer_.Stop();
                playOrStopButton_.Text = "Play";
            }
        }
Esempio n. 16
0
        /// <summary>
        /// 语音播放
        /// </summary>
        public override void ReadSound(string file)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(m_strDeviceDescription) ||
                    string.IsNullOrWhiteSpace(file) ||
                    !m_hashDevices.ContainsKey(m_strDeviceDescription))
                {
                    return;
                }

                if (File.Exists(file) == false)
                {
                    return;
                }

                if (null != m_buf)
                {
                    m_buf.Stop();
                    m_buf.Dispose();
                    m_buf = null;
                }
                using (BufferDescription temp = new BufferDescription())
                {
                    temp.Flags = BufferDescriptionFlags.GlobalFocus;
                    m_buf      = new SecondaryBuffer(file, temp, (Device)m_hashDevices[m_strDeviceDescription]);
                    m_buf.Play(0, BufferPlayFlags.Default);
                }
            }
            catch (Exception ex)
            {
                CLOGException.Trace("SoundManagementLib.CSoundDirectX.ReadSound 异常", CBaseMethods.MyBase.GetExceptionInfo(ex));
            }
        }
Esempio n. 17
0
File: main.cs Progetto: sjk7/DX90SDK
 private void btnStop_Click(object sender, System.EventArgs e)
 {
     if (null != ApplicationBuffer)
     {
         ApplicationBuffer.Stop();
     }
 }
Esempio n. 18
0
        byte[] addbuffer;                 // contains 30 waveforms


        private void btnGo_Click(object sender, EventArgs e)
        {
            // Button is either "stop" or "go"
            if (!timer.Enabled)
            {
                timer_Tick(null, null); //fill buffer initially
                bufferstream.Play(0, BufferPlayFlags.Looping);
                timer.Enabled              = true;
                timerDisplay.Enabled       = true;
                this.MainMenuStrip.Enabled = false;

                if (this.deviceInput != null)
                {
                    timerPoll.Enabled = true; // if game pad connected, poll the input device !
                }
                btnGo.Text = "Stop";
            }
            else
            {
                bufferstream.Stop();
                timer.Enabled              = false;
                timerDisplay.Enabled       = false;
                timerPoll.Enabled          = false;
                this.MainMenuStrip.Enabled = true;
                btnGo.Text = "Start";
            }
        }
Esempio n. 19
0
 public void Stop()
 {
     isRunning = false;
     if (m_Buffer != null)
     {
         m_Buffer.Stop();
     }
 }
 public void Stop()
 {
     if (!disposed)
     {
         lock (buffer)
             buffer.Stop();
     }
 }
Esempio n. 21
0
 private void buttonStop_Click(object sender, System.EventArgs e)
 {
     if (null != applicationBuffer)
     {
         textStatus.Text = "Sound stopped.";
         EnablePlayUI(true);
         applicationBuffer.Stop();
         applicationBuffer.SetCurrentPosition(0);
     }
 }
Esempio n. 22
0
 public void stopWav()
 {
     wavPlayer.Stop();
     if (sound != null)
     {
         sound.Stop();
         sound = null;
     }
     wplayer.controls.stop();
 }
Esempio n. 23
0
 private void play(SecondaryBuffer input, int volume)
 {
     if (input != null)
     {
         input.Stop();
         input.SetCurrentPosition(0);
         input.Volume = volume;
         input.Play(0, BufferPlayFlags.Default);
     }
 }
Esempio n. 24
0
 public void StopPlaying()
 {
     if (mSecondaryBuffer == null)
     {
         return;
     }
     if (mSecondaryBuffer.Status.Playing)
     {
         mSecondaryBuffer.Stop();
     }
 }
Esempio n. 25
0
        public void SoundDeathEnd()
        {
            if (soundDeath == null)
            {
                return;
            }

            if (soundDeath.Status.Playing)
            {
                soundDeath.Stop();
            }
        }
Esempio n. 26
0
        public void Pause()
        {
            if (_halted)
            {
                return;
            }

            _halted = true;
            _soundBuffer.Stop();

            Monitor.Enter(_thread);
        }
Esempio n. 27
0
        public void SoundtrackEnd()
        {
            if (soundtrack == null)
            {
                return;
            }

            if (soundtrack.Status.Playing)
            {
                soundtrack.Stop();
            }
        }
Esempio n. 28
0
        public void PlayLoop(string soundpath)
        {
            if (havedevice == false)
            {
                return;
            }

            if (soundbuffer != null)
            {
                soundbuffer.Stop();
                soundbuffer.Dispose();
                soundbuffer = null;
            }

            if (LoadSoundFile(soundpath))
            {
                soundbuffer.Play(0, BufferPlayFlags.Default);
            }

            soundbuffer.Play(0, BufferPlayFlags.Default);
        }
Esempio n. 29
0
            public void Update()
            {
                var pitch  = Math.Max(Pitch, 0.0f);
                var volume = Math.Max(Math.Min(Volume, 1.0f), 0.0f);

                SecondaryBuffer.Frequency = Math.Min(Math.Max((int)(DefaultFrequency * pitch), MinimumFrequency), MaximumFrequency);

                var gain = MinimumVolume;


                if (volume > 0.001f)
                {
                    var attenuation = volume;


                    if (attenuation >= 1.0f)
                    {
                        attenuation = 1.0f;
                    }


                    gain = (int)(Math.Log10(1.0 / 1024.0 + attenuation / 1.0 * 1023.0 / 1024.0) * 2000.0);
                }


                SecondaryBuffer.Volume = gain;


                if (volume > 0.0f)
                {
                    if ((SecondaryBuffer.Status & BufferStatus.Playing) != 0)
                    {
                        return;
                    }


                    SecondaryBuffer.CurrentPlayPosition = 0;
                    SecondaryBuffer.Play(0, PlayFlags.Looping);


                    return;
                }


                if (SecondaryBuffer.Status == BufferStatus.None)
                {
                    return;
                }


                SecondaryBuffer.Stop();
            }
        private void LoadSoundFile()
        {
            BufferDescription description = new BufferDescription();

            description.Guid3DAlgorithm  = DSoundHelper.Guid3DAlgorithmHrtfLight;
            description.Control3D        = true;
            description.ControlFrequency = true;
            description.ControlVolume    = true;

            if (null != soundBuffer)
            {
                soundBuffer.Stop();
                soundBuffer.SetCurrentPosition(0);
            }

            // Load the wave file into a DirectSound buffer
            try
            {
                soundBuffer   = new SecondaryBuffer(m_FileName, description, Listener.Device);
                soundBuffer3D = new Buffer3D(soundBuffer);
            }
            catch (Exception e)
            {
                GameEngine.Console.AddLine("Exception on loading " + m_FileName + ". Ensure file is Mono");
                GameEngine.Console.AddLine(e.Message);
            }

            if (WaveFormatTag.Pcm != (WaveFormatTag.Pcm & description.Format.FormatTag))
            {
                GameEngine.Console.AddLine("Wave file must be PCM for 3D control.");
                if (null != soundBuffer)
                {
                    soundBuffer.Dispose();
                }
                soundBuffer = null;
            }
        }
Esempio n. 31
0
 public static void Play(string name)
 {
     if (!PlaySound) return;
     /*BUFFER[name].Stop();
     BUFFER[name].SetCurrentPosition(0);
     BUFFER[name].Play(0, BufferPlayFlags.Default);*/
     STREAM[name].Position = 0;
     SecondaryBuffer buffer = new SecondaryBuffer(STREAM[name], DEVICE);
     buffer.Stop();
     buffer.SetCurrentPosition(0);
     buffer.Play(0, BufferPlayFlags.Default);
     BUFFER_POOL.Add(new MyBuffer(buffer));
 }