Ejemplo n.º 1
0
 private void sbtSave_Click(object sender, EventArgs e)
 {
     if (sourceStream1 != null)
     {
         sourceStream1.StopRecording();
         sourceStream1.Dispose();
         sourceStream1   = null;
         sbtSave.Enabled = false;
         sbtOpen.Focus();
         txtTenFile.Text = "";
     }
     if (this.waveWriter != null)
     {
         this.waveWriter.Dispose();
         this.waveWriter = null;
     }
     steam.Dispose();
     steam2.Dispose();
     output.Dispose();
     output2.Dispose();
     if (cdDelete.Checked)
     {
         File.Delete(currentrecord);
         File.Delete(currentrecord.Replace(".wav", "mic.wav"));
     }
     setdefaul();
 }
Ejemplo n.º 2
0
 private void MusicDispose()
 {
     if (_reader != null)
     {
         _fileStream.Dispose();
         _waveOut.Dispose();
         _reader.Dispose();
         _blockAlignStream.Dispose();
     }
 }
Ejemplo n.º 3
0
 public void Dispose()
 {
     if (BlockAlignReductionStream != null)
     {
         BlockAlignReductionStream.Dispose();
     }
 }
Ejemplo n.º 4
0
        public void DisposeAudioOutput()
        {
            if (mainDirectSoundOut != null)
            {
                if (mainDirectSoundOut.PlaybackState != PlaybackState.Stopped)
                {
                    mainDirectSoundOut.Stop();
                }
                mainDirectSoundOut.Dispose();
                mainDirectSoundOut = null;
            }
            if (mainBARStream != null)
            {
                mainBARStream.Dispose();
                mainBARStream = null;
            }
            if (mainWaveIn != null)
            {
                mainWaveIn.StopRecording();
                mainWaveIn.Dispose();
                mainWaveIn = null;
            }

            SetTemp();
            label1.Text       = "";
            errormessage.Text = "The audio was disposed";
        }
Ejemplo n.º 5
0
        public void Stop()
        {
            if (waveOut != null)
            {
                waveOut.Stop();
                waveOut.Dispose();
                waveOut = null;
            }
            if (baStream != null)
            {
                baStream.Dispose();
                baStream = null;
            }
            if (wavStream != null)
            {
                wavStream.Dispose();
                wavStream = null;
            }

            if (mf != null)
            {
                mf.Close();
                mf.Dispose();
                mf = null;
            }
        }
Ejemplo n.º 6
0
 public void DisposeWave()
 {
     if (ts.IsCancellationRequested && !MainWindow.instance.bottomTimeSlider.IsMouseOver)
     {
         try
         {
             if (output != null)
             {
                 if (output.PlaybackState == PlaybackState.Playing)
                 {
                     output.Stop();
                 }
                 output.Dispose();
                 output = null;
             }
             if (stream != null)
             {
                 stream.Dispose();
                 stream = null;
             }
         }
         catch (NAudio.MmException mmex) {
             Console.Error.WriteLine(mmex.Message);
         }
     }
 }
Ejemplo n.º 7
0
        public void PlaySound(string name, Action done = null)
        {
            FileStream ms        = File.OpenRead(_soundLibrary[name]);
            var        rdr       = new Mp3FileReader(ms);
            WaveStream wavStream = WaveFormatConversionStream.CreatePcmStream(rdr);
            var        baStream  = new BlockAlignReductionStream(wavStream);
            var        waveOut   = new WaveOut(WaveCallbackInfo.FunctionCallback());

            waveOut.Init(baStream);
            waveOut.Play();
            var bw = new BackgroundWorker();

            bw.DoWork += (s, o) =>
            {
                while (waveOut.PlaybackState == PlaybackState.Playing)
                {
                    Thread.Sleep(100);
                }
                waveOut.Dispose();
                baStream.Dispose();
                wavStream.Dispose();
                rdr.Dispose();
                ms.Dispose();
                if (done != null)
                {
                    done();
                }
            };
            bw.RunWorkerAsync();
        }
Ejemplo n.º 8
0
 public void DisposWave()
 {
     if (output != null)
     {
         if (output.PlaybackState == PlaybackState.Playing)
         {
             output.Stop();
         }
         output.Dispose();
         output = null;
     }
     if (steam != null)
     {
         steam.Dispose();
         steam = null;
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// フォームのクロージング処理
        /// Wave関連オブジェクトのDispose処理を担当
        /// </summary>
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            output?.Dispose();
            output = null;

            stream?.Dispose();
            stream = null;
        }
Ejemplo n.º 10
0
 public void Dispose()
 {
     fileStream.Dispose();
     fileStream.Dispose();
     mp3FileReader.Dispose();
     wavStream.Dispose();
     baStream.Dispose();
     wave.Dispose();
 }
Ejemplo n.º 11
0
 private void DJDemo_FormClosing(object sender, FormClosingEventArgs e)
 {
     sensors.Disconnect();
     music.Volume = 1;
     music.Stop();
     music.Dispose();
     baStream.Dispose();
     wavStream.Close();
     song.Close();
 }
Ejemplo n.º 12
0
 internal void Dispose()
 {
     _playThread.Abort();
     soundTouch.Dispose();
     blockAlignReductionStream.Dispose();
     reader.Dispose();
     waveChannel.Dispose();
     player.Dispose();
     //waveFileWriter.Dispose();
 }
Ejemplo n.º 13
0
 public void Dispose()
 {
     _cts.Cancel();
     _playThread?.Abort();
     _soundTouch?.Dispose();
     _blockAlignReductionStream?.Dispose();
     _device?.Dispose();
     _device = null;
     _reader?.Dispose();
     _reader = null;
     _cts?.Dispose();
 }
Ejemplo n.º 14
0
 private void Dispose()
 {
     if (output != null)
     {
         //arreter la musique
         output.Stop();
         output.Dispose();
         song.Dispose();
         song   = null;
         output = null;
     }
 }
Ejemplo n.º 15
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            _rdr?.Dispose();
            _wavStream?.Dispose();
            _baStream?.Dispose();
            _waveOut?.Dispose();
        }
Ejemplo n.º 16
0
 public void Dispose()
 {
     if (waveOut != null)
     {
         waveOut.Dispose();
     }
     if (reader != null)
     {
         reader.Dispose();
     }
     if (baStream != null)
     {
         baStream.Dispose();
     }
 }
Ejemplo n.º 17
0
 private void DisposeWave()
 {
     if (output != null)
     {
         if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing)
         {
             output.Stop();
         }
         output.Dispose();
         output = null;
     }
     if (stream != null)
     {
         stream.Dispose();
         stream = null;
     }
 }
Ejemplo n.º 18
0
 private void DisposeWave()
 {
     if (SoundOut != null)
     {
         if (SoundOut.PlaybackState == NAudio.Wave.PlaybackState.Playing)
         {
             SoundOut.Stop();
         }
         SoundOut.Dispose();
         SoundOut = null;
     }
     if (BlockStream != null)
     {
         BlockStream.Dispose();
         BlockStream = null;
     }
 }
Ejemplo n.º 19
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (output != null)
     {
         output.Dispose();
         output = null;
     }
     if (stream != null)
     {
         stream.Dispose();
         stream = null;
     }
     if (tone != null)
     {
         tone.Dispose();
     }
 }
Ejemplo n.º 20
0
 private void DisponeWal()
 {
     if (soundOut != null)
     {
         if (soundOut.PlaybackState == PlaybackState.Playing)
         {
             soundOut.Stop();
         }
         soundOut.Dispose();
         soundOut = null;
     }
     if (stream != null)
     {
         stream.Dispose();
         stream = null;
     }
 }
Ejemplo n.º 21
0
        /*
         * Plays the sound found at @path to the @audioDevice with @audioVolume.
         * The default AudioDevice (system standard) is -1.
         * The audio ranges from 0.00 to 1.00, values above 1 will be used as 1.
         * The file under path must be a .mp3 file.
         *
         * This method starts a background worker to play the sound.
         * Playing multiple sounds at once is possible.
         */
        private void PlaySound(string path, int audioDevice = 0, double audioVolume = 50.0, Action done = null)
        {
            FileStream ms  = File.OpenRead(path);
            var        rdr = new Mp3FileReader(ms);
            // TODO: Can I use MemoryStream here?
            WaveStream wavStream = WaveFormatConversionStream.CreatePcmStream(rdr);
            var        baStream  = new BlockAlignReductionStream(wavStream);

            var waveOut = new WaveOut();

            waveOut.DeviceNumber = audioDevice;
            waveOut.Volume       = (float)audioVolume / 100;

            waveOut.Init(baStream);
            waveOut.Play();

            var bw = new BackgroundWorker();

            // Do Work is the regular handler, checked every few ms
            bw.DoWork += (s, o) =>
            {
                while (waveOut.PlaybackState == PlaybackState.Playing || waveOut.PlaybackState == PlaybackState.Stopped)
                {
                    Thread.Sleep(150);
                }
                // Dispose of all used resources
                waveOut.Dispose();
                baStream.Dispose();
                wavStream.Dispose();
                rdr.Dispose();
                ms.Dispose();
                // Set the inherited bw state to done (from running)
                if (done != null)
                {
                    done();
                }
            };

            bw.RunWorkerAsync();
            // Add to currently running WaveOuts
            _runningWaveOuts.Add(waveOut);
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Releases unmanaged and - optionally - managed resources.
 /// </summary>
 /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             if (output != null)
             {
                 output.Stop();
                 output.Dispose();
                 output = null;
             }
             if (reduce != null)
             {
                 reduce.Dispose();
                 reduce = null;
             }
         }
         _disposed = true;
     }
 }
 private void DisposeWave()
 {
     try
     {
         if (soundOut != null)
         {
             if (soundOut.PlaybackState == PlaybackState.Playing)
             {
                 soundOut.Stop();
             }
             soundOut.Dispose();
             soundOut = null;
         }
         if (blockStream != null)
         {
             blockStream.Dispose();
             blockStream = null;
         }
     }
     catch { }
 }