Пример #1
0
 private void FormMain_Load(object sender, EventArgs e)
 {
     timer1.Start();
     if (WaveNative.waveInGetNumDevs() == 0)
     {
         textBoxConsole.AppendText(DateTime.Now.ToString() + " : No audio input devices detected\r\n");
     }
     else
     {
         textBoxConsole.AppendText(DateTime.Now.ToString() + " : Audio input device detected\r\n");
         if (_isPlayer == true)
         {
             _streamOut = new FifoStream();
         }
         _audioFrame = new AudioFrame(_isTest);
         _audioFrame.IsDetectingEvents  = SoundAlert.Properties.Settings.Default.SettingIsDetectingEvents;
         _audioFrame.AmplitudeThreshold = SoundAlert.Properties.Settings.Default.SettingAmplitudeThreshold;
         _streamMemory = new MemoryStream();
         Start();
     }
 }
Пример #2
0
 private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     Stop();
     if (_isSaving == true)
     {
         byte[] waveBuffer = new byte[SoundAlert.Properties.Settings.Default.SettingBitsPerSample];
         _streamWave = WaveStream.CreateStream(_streamMemory, _waveFormat);
         waveBuffer  = new byte[_streamWave.Length - _streamWave.Position];
         _streamWave.Read(waveBuffer, 0, waveBuffer.Length);
         if (SoundAlert.Properties.Settings.Default.SettingOutputPath != "")
         {
             _streamFile = new FileStream(SoundAlert.Properties.Settings.Default.SettingOutputPath + "\\" + _sampleFilename, FileMode.Create);
         }
         else
         {
             _streamFile = new FileStream(_sampleFilename, FileMode.Create);
         }
         _streamFile.Write(waveBuffer, 0, waveBuffer.Length);
         _isSaving = false;
     }
     if (_streamOut != null)
     {
         try
         {
             _streamOut.Close();
         }
         finally
         {
             _streamOut = null;
         }
     }
     if (_streamWave != null)
     {
         try
         {
             _streamWave.Close();
         }
         finally
         {
             _streamWave = null;
         }
     }
     if (_streamFile != null)
     {
         try
         {
             _streamFile.Close();
         }
         finally
         {
             _streamFile = null;
         }
     }
     if (_streamMemory != null)
     {
         try
         {
             _streamMemory.Close();
         }
         finally
         {
             _streamMemory = null;
         }
     }
 }