Esempio n. 1
1
        public Recorder()
        {
            int waveInDevices = WaveIn.DeviceCount;

            //for (int waveInDevice = 0; waveInDevice < waveInDevices; waveInDevice++)
            //{
            //    WaveInCapabilities deviceInfo = WaveIn.GetCapabilities(waveInDevice);
            //    comboBox1.Items.Add(string.Format("Device {0}: {1}, {2} channels", waveInDevice, deviceInfo.ProductName, deviceInfo.Channels));
            //}

            waveIn = new WaveIn();
            waveIn.DeviceNumber = 0;
            waveIn.DataAvailable += waveIn_DataAvailable;
            waveIn.RecordingStopped += waveIn_RecordingStopped;

            int sampleRate = 16000; // 16 kHz
            int channels = 1; // mono
            int bits = 16;

            recordingFormat = new WaveFormat(sampleRate, bits, channels);
            waveIn.WaveFormat = recordingFormat;

            string path = "C:\\temp";
            if( !Directory.Exists(path) )
            {
                Directory.CreateDirectory(path);
            }

            TempWavFileName = String.Format("{0}\\{1}.wav", path, Guid.NewGuid().ToString());

            writer = new WaveFileWriter(TempWavFileName, recordingFormat);
        }
Esempio n. 2
1
 //Кнопка "Запись"
 private void button_rec_Click(object sender, EventArgs e)
 {
     button_stop.Enabled = true;
     timer.Start();
     ind = 1;
     try
     {
         waveIn = new WaveIn();
         waveIn.DeviceNumber = 0;//Дефолтное устройство для записи (если оно имеется)
         waveIn.DataAvailable += waveIn_DataAvailable;//Прикрепляем к событию DataAvailable обработчик, возникающий при наличии записываемых данных
         waveIn.RecordingStopped += waveIn_RecordingStopped;//Прикрепляем обработчик завершения записи
         waveIn.WaveFormat = new WaveFormat(8000, 1);//Формат wav-файла - принимает параметры - частоту дискретизации и количество каналов(здесь mono)
         writer = new WaveFileWriter(outputFilename, waveIn.WaveFormat);//Инициализируем объект WaveFileWriter
         waveIn.StartRecording();//Начало записи
         button_play.Enabled = false;
         button_rec.Enabled = false;
         numeric.Enabled = false;
     }
     catch (Exception ex)
     {
         button_play.Enabled = true;
         button_rec.Enabled = true;
         numeric.Enabled = true;
         MessageBox.Show(ex.Message);
     }
 }
        private void startRecordSound()
        {
            int deviceNumber = devices_cbx.SelectedIndex;
            int sampleRate   = devices_cbx.SelectedIndex;

            if (sampleRate >= 0 && deviceNumber >= 0 && sampleRate < Constant.TextSampleRate.Count <string>())
            {
                sourceStream = new NAudio.Wave.WaveIn();
                sourceStream.DeviceNumber = deviceNumber;
                sourceStream.WaveFormat   = new NAudio.Wave.WaveFormat(Constant.SampleRate[sampleRate], NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);
                //NAudio.Wave.WaveInProvider waveIn = null;
                //waveIn = new NAudio.Wave.WaveInProvider(sourceStream);

                pathFile = VCDir.Instance.PathWaveFile;
                sourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable);
                waveWriter = new NAudio.Wave.WaveFileWriter(pathFile, sourceStream.WaveFormat);

                sourceStream.StartRecording();
                // waveOut.Play();
            }
            else
            {
                MessageBox.Show("");
                return;
            }
        }
Esempio n. 4
0
		public async Task Transcode(CancellationToken ct, IWaveStreamProvider stream, Stream targetStream)
		{
			using (var fileWriter = new NAudio.Wave.WaveFileWriter(targetStream, stream.WaveFormat))
			{
				await stream.Stream.CopyToAsync(fileWriter);
			}
		}
Esempio n. 5
0
        /// <summary>
        /// Merge multiple .wav files together and save the output.
        /// </summary>
        /// <param name="outputFile">The path to save the output to.</param>
        /// <param name="sourceFiles">An IEnumerable list of files to merge.</param>
        private static void ConcatenateWav(string outputFile, IEnumerable<string> sourceFiles) {
            byte[] buffer = new byte[1024];
            WaveFileWriter waveFileWriter = null;
            
            try {
                foreach (string sourceFile in sourceFiles) {
                    using (WaveFileReader reader = new WaveFileReader(sourceFile)) {
                        if (waveFileWriter == null) {
                            // first time in create new Writer
                            waveFileWriter = new WaveFileWriter(outputFile, reader.WaveFormat);
                        }
                        else {
                            if (!reader.WaveFormat.Equals(waveFileWriter.WaveFormat)) {
                                throw new InvalidOperationException("Can't concatenate WAV Files that don't share the same format");
                            }
                        }

                        int read;
                        while ((read = reader.Read(buffer, 0, buffer.Length)) > 0) {
                            waveFileWriter.WriteData(buffer, 0, read);
                        }
                    }
                }
            }
            finally {
                if (waveFileWriter != null) {
                    waveFileWriter.Dispose();
                }
            }

        }
Esempio n. 6
0
        // Method needed to cleanup outputStream and waveOut file
        private void DisposeWave()
        {
            if (sourceStream != null)
            {
                sourceStream.StopRecording();
                sourceStream.Dispose();
                sourceStream = null;
            }
            if (waveWriter != null)
            {
                waveWriter.Dispose();
                waveWriter = null;
            }

            if (waveOut != null)
            {
                if (waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing)
                {
                    waveOut.Stop();
                }
                waveOut.Dispose();
                waveOut.Stop();
                waveOut = null;
            }

            if (waveReader != null)
            {
                waveReader.Dispose();
                waveReader.Close();
                waveReader = null;
            }
        }
Esempio n. 7
0
		/// ------------------------------------------------------------------------------------
		private void ProcessData()
		{
			try
			{
				while (true)
				{
					byte[] buffer = null;
					lock (_data)
					{
						if (_data.Count > 0)
							buffer = _data.Dequeue();
					}
					if (buffer != null)
					{
						// write it to the file
						_writer.Write(buffer, 0, buffer.Length);
					}
					else
					{
						if (_finished)
							break;
						Thread.Sleep(20);
					}
				}
				_recordedTimeInSeconds = TimeSpan.FromSeconds((double)_writer.Length / _writer.WaveFormat.AverageBytesPerSecond);
			}
			finally
			{
				_writer.Dispose();
				_writer = null;
			}
		}
Esempio n. 8
0
 private void Source_RecordingStopped(object sender, StoppedEventArgs e)
 {
     if (this.InvokeRequired)
     {
         this.BeginInvoke(new EventHandler <StoppedEventArgs>(Source_RecordingStopped), sender, e);
     }
     else
     {
         if (source != null) // 关闭录音对象
         {
             this.source.Dispose();
             this.source = null;
         }
         if (encoder != null)//关闭文件流
         {
             encoder.Close();
             encoder.Dispose();
             encoder = null;
         }
         if (e.Exception != null)
         {
             MessageBox.Show(String.Format("出现问题 {0}", e.Exception.Message));
         }
     }
 }
 private void ConvertWavTo10SecondWavs(FileInfo inputFile)
 {
     var samplesOutWav = @"..\..\..\samples\wav10seconds\";
     using (var inAudio = new WaveFileReader(inputFile.FullName))
     {
         //Calculate required byte[] buffer.
         var buffer = new byte[10*inAudio.WaveFormat.AverageBytesPerSecond];//Assume average will be constant for WAV format.
         int index = 0;
         do
         {
             var outFile = string.Format("{0}{1}.{2:0000}.wav",
             samplesOutWav, inputFile.Name.Replace(inputFile.Extension, string.Empty), index);
             int bytesRead = 0;
             do
             {
                 bytesRead = inAudio.Read(buffer, 0, buffer.Length - bytesRead);
             } while (bytesRead > 0 && bytesRead < buffer.Length);
             //Write new file
             using (var waveWriter = new WaveFileWriter(outFile, inAudio.WaveFormat))
             {
                 waveWriter.Write(buffer, 0, buffer.Length);
             }
             index++;
         } while (inAudio.Position < inAudio.Length);
     }
 }
Esempio n. 10
0
        static void Main(string[] args)
        {
            // for recording
            waveFileWriter = new WaveFileWriter(@"C:\rec\out.wav", new WaveFormat(44100, 2));

            var sound = new MySound();
            sound.SetWaveFormat(44100, 2);
            sound.init();
            waveOut = new WaveOut();
            waveOut.Init(sound);
            waveOut.Play();

            ConsoleKeyInfo keyInfo;
            bool loop = true;
            while (loop)
            {
                keyInfo = Console.ReadKey();
                if (keyInfo.Key == ConsoleKey.Q)
                {
                    waveOut.Stop();
                    waveOut.Dispose();
                    waveFileWriter.Close();
                    waveFileWriter.Dispose();
                    loop = false;
                }
            }
        }
Esempio n. 11
0
        private void buttonStartRecording_Click(object sender, EventArgs e)
        {
            if (waveIn == null)
            {
                if(outputFilename == null)
                {
                    buttonSelectOutputFile_Click(sender, e);
                }
                if(outputFilename == null)
                {
                    return;
                }
                if (radioButtonWaveIn.Checked)
                {
                    waveIn = new WaveIn();
                    waveIn.WaveFormat = new WaveFormat(8000, 1);
                }
                else
                {
                    waveIn = new WasapiCapture((MMDevice)comboDevices.SelectedItem);
                    // go with the default format as WASAPI doesn't support SRC
                }

                writer = new WaveFileWriter(outputFilename, waveIn.WaveFormat);

                waveIn.DataAvailable += new EventHandler<WaveInEventArgs>(waveIn_DataAvailable);
                waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);
                waveIn.StartRecording();
                buttonStartRecording.Enabled = false;
            }
        }
 public void CanDownsampleAnMp3File()
 {
     string testFile = @"D:\Audio\Music\Coldplay\Mylo Xyloto\03 - Paradise.mp3";
     if (!File.Exists(testFile)) Assert.Ignore(testFile);
     string outFile = @"d:\test22.wav";
     using (var reader = new AudioFileReader(testFile))
     {
         // downsample to 22kHz
         var resampler = new WdlResamplingSampleProvider(reader, 22050);
         var wp = new SampleToWaveProvider(resampler);
         using (var writer = new WaveFileWriter(outFile, wp.WaveFormat))
         {
             byte[] b = new byte[wp.WaveFormat.AverageBytesPerSecond];
             while (true)
             {
                 int read = wp.Read(b, 0, b.Length);
                 if (read > 0)
                     writer.Write(b, 0, read);
                 else
                     break;
             }
         }
         //WaveFileWriter.CreateWaveFile(outFile, );
     }
 }
Esempio n. 13
0
        public Form1()
        {
            if (save)
                writer = new WaveFileWriter("test.wav", new WaveFormat(44100, 1));
            Control.CheckForIllegalCrossThreadCalls = false;
            //35
            //40-60
            //60-100
            //100-300
            //600-900
            //900-1800
            //1800-3500
            //3500-7500
            //7500-12000
            //12000-18000
            //18000
            var filters = new EqualizerFilters();
            table = new float[filters.Filters.Count];
            for (int i = 0; i < table.Length; i++)
                table[i] = 1;
            solver = new FIRSolver2(OpenCLNet.OpenCL.GetPlatform(0), filters.Filters, 2048);
            solver.SetMulTable(table);

            InitializeComponent();

            asio = new Asio.Asio(Asio.Asio.InstalledDrivers.ElementAt(0));
            asio.ProcessAudio = ProcessAudio;
            var asioThread = new Thread(new ThreadStart(asio.Start));
            asioThread.IsBackground = true;
            asioThread.Priority = ThreadPriority.Highest;
            asioThread.Start();
        }
Esempio n. 14
0
        private void sourceStreamDataAvailable(object sender, WaveInEventArgs e)
        {
            string path = outputPath + "wavsam" + nFiles + ".wav";
            writer = new WaveFileWriter(path, waveFormat);
            writer.Write(e.Buffer, 0, e.Buffer.Length);
            writer.Flush();
            writer.Close();
            nFiles++;

            Process process = new Process();
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.FileName = "praatcon.exe";
            String male;
            if (isMale) male = "yes"; else male = "no";
            process.StartInfo.Arguments = "extract_measures.praat " + path + " " + male;
               // process.StartInfo.RedirectStandardOutput = true;

            process.Start();

            process.WaitForExit();

            ResultEventArgs args = new ResultEventArgs();
              //      args.text = output;
            OnResults(args);
               // args.nWords = err.Length;
        }
Esempio n. 15
0
        private void waveBtn_Click(object sender, EventArgs e)
        {
            if (sourceList.SelectedItems.Count == 0)
            {
                return;
            }

            SaveFileDialog save = new SaveFileDialog();

            save.Filter = "Wave File (*.wav)|*.wav;";
            // jesli cos sie nie zgadza sie w oknie dialogowym - return
            if (save.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            int deviceNumber = sourceList.SelectedItems[0].Index;

            sourceStream = new NAudio.Wave.WaveIn();  // przechowuje to co wchodzi
            sourceStream.DeviceNumber = deviceNumber; // z danego urzadzenia
            // format strumienia
            sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);
            // kiedy jest mozliwe pobranie nowych danych - pobierz ze strumienia
            sourceStream.DataAvailable += new EventHandler <WaveInEventArgs>(sourceStream_DataAvailable);
            // zapisz plik o takiej nazwie w formacie wav
            waveWriter = new NAudio.Wave.WaveFileWriter(save.FileName, sourceStream.WaveFormat);

            sourceStream.StartRecording();
        }
Esempio n. 16
0
        private void btnRecord_Click(object sender, EventArgs e)
        {
            if (_signal == null)
            {
                return;
            }

            if (File.Exists(_tempFileName))
            {
                File.Delete(_tempFileName);
            }

            using (FileStream fs = new FileStream(_tempFileName, FileMode.Create))
            {
                float[] convertedDoubles = new float[_signal.Values.Count];
                for (int i = 0; i < convertedDoubles.Length; i++)
                {
                    convertedDoubles[i] = (float)_signal.Values[i];
                }

                using (WaveFileWriter waveFileWriter = new WaveFileWriter(fs, new WaveFormat(SAMPLE_RATE, 16, 1)))
                {
                    waveFileWriter.WriteSamples(convertedDoubles, 0, _signal.Values.Count);
                }
                fs.Close();
            }
            MessageBox.Show("Recorded!");
        }
Esempio n. 17
0
        // Method that stops recording
        private void stop_Click(object sender, EventArgs e)
        {
            Recognition_Form form = new Recognition_Form(null, null, null);

            form.Show();

            this.microResultLabel = form.ms_result;
            this.mfcc_result      = form.mfcc_result;
            this.lpc_result       = form.lpc_result;


            if (sourceStream != null)
            {
                sourceStream.StopRecording();
                sourceStream.Dispose();
                sourceStream = null;
            }
            if (waveWriter != null)
            {
                waveWriter.Dispose();
                waveWriter = null;
            }
            openWav(wavSaveName);
            recording_timer.Stop();
            wavSaveName = null;
            System.Threading.Tasks.Task.Run(() =>
            {
                processWavFile(algo);
            });
            // processWavFile(algo);
        }
Esempio n. 18
0
        //Starts recording
        private void startRecording()
        {
            ReadAudioForm3.backButton.Enabled   = false;
            ReadAudioForm3.submitButton.Enabled = false;
            wavSource = new WaveIn();
            wavSource.DataAvailable    += new EventHandler <WaveInEventArgs>(wavSource_DataAvailable);
            wavSource.RecordingStopped += new EventHandler <StoppedEventArgs>(wavSource_RecordingStopped);
            //wavSource.WaveFormat = new WaveFormat(44100, 1);
            wavSource.WaveFormat = new WaveFormat(8000, 16, 1);

            String filename = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\RecordWAV\" + lvlStr + ".wav";

            wavFile      = new WaveFileWriter(filename, wavSource.WaveFormat);
            canvasHeight = waveCanvas.Height;
            canvasWidth  = waveCanvas.Width;

            polyLine                 = new Polyline();
            polyLine.Stroke          = Brushes.Black;
            polyLine.StrokeThickness = 1;
            polyLine.Name            = "waveform";
            polyLine.MaxHeight       = canvasHeight - 4;
            polyLine.MaxWidth        = canvasWidth - 4;

            polyHeight = polyLine.MaxHeight;
            polyWidth  = polyLine.MaxWidth;

            counter = 0;

            dispPoints = new Queue <Point>();
            totalBytes = new List <byte>();
            dispShots  = new Queue <Int32>();

            wavSource.StartRecording();
        }
Esempio n. 19
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (SourceList.SelectedItems.Count == 0)
            {
                return;
            }
            SaveFileDialog save = new SaveFileDialog();

            save.Filter = "Wave File (*.wav|*.wav;";
            if (save.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            int deviceNumber = SourceList.SelectedItems[0].Index;

            sourceStream = new NAudio.Wave.WaveIn();
            sourceStream.DeviceNumber = deviceNumber;
            sourceStream.WaveFormat   = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);

            sourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable);
            waveWriter = new NAudio.Wave.WaveFileWriter(save.FileName, sourceStream.WaveFormat);

            sourceStream.StartRecording();
        }
Esempio n. 20
0
 public void FlushUpdatesHeaderEvenIfDisposeNotCalled()
 {
     var ms = new MemoryStream();
     var testSequence = new byte[] { 0x1, 0x2, 0xFF, 0xFE };
     var testSequence2 = new byte[] { 0x3, 0x4, 0x5 };
     var writer = new WaveFileWriter(new IgnoreDisposeStream(ms), new WaveFormat(16000, 24, 1));
     writer.Write(testSequence, 0, testSequence.Length);
     writer.Flush();
     // BUT NOT DISPOSED
     // another write that was not flushed
     writer.Write(testSequence2, 0, testSequence2.Length);
     
     // check the Reader can read it
     ms.Position = 0;
     using (var reader = new WaveFileReader(ms))
     {
         Assert.AreEqual(16000, reader.WaveFormat.SampleRate, "Sample Rate");
         Assert.AreEqual(24, reader.WaveFormat.BitsPerSample, "Bits Per Sample");
         Assert.AreEqual(1, reader.WaveFormat.Channels, "Channels");
         Assert.AreEqual(testSequence.Length, reader.Length, "File Length");
         var buffer = new byte[600]; // 24 bit audio, block align is 3
         int read = reader.Read(buffer, 0, buffer.Length);
         Assert.AreEqual(testSequence.Length, read, "Data Length");
         
         for (int n = 0; n < read; n++)
         {
             Assert.AreEqual(testSequence[n], buffer[n], "Byte " + n);
         }
     }
     writer.Dispose(); // to stop the finalizer from moaning
 }
Esempio n. 21
0
        /// <summary>
        /// 录音开始的Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void recordStart_Click(object sender, EventArgs e)
        {
            //this.source = new AudioCaptureDevice()
            //{
            //    DesiredFrameSize = 4096,
            //    SampleRate = 22050,

            //    Format = SampleFormat.Format16Bit
            //this.source.NewFrame += Source_NewFrame;
            //this.source.AudioSourceError += Source_AudioSourceError;
            //this.source.RecordingStopped += Source_RecordingStopped;

            this.source                   = new WaveIn();
            this.source.WaveFormat        = new WaveFormat(8000, 1);
            this.source.DataAvailable    += this.Source_NewFrame;
            this.source.RecordingStopped += Source_RecordingStopped;

            //MemoryStream s = new MemoryStream();
            //this.encoder = new WaveEncoder(s);

            this.encoder = new WaveFileWriter(Path.Combine(Application.StartupPath, "sounds", string.Format("{0}.wav", System.IO.Path.GetRandomFileName())), this.source.WaveFormat);

            this.source.StartRecording();

            //this.soundStream = s;
        }
Esempio n. 22
0
 public void ReaderShouldReadBackSameDataWrittenWithWrite()
 {
     var ms = new MemoryStream();
     var testSequence = new byte[] { 0x1, 0x2, 0xFF, 0xFE };
     using (var writer = new WaveFileWriter(new IgnoreDisposeStream(ms), new WaveFormat(16000, 24, 1)))
     {
         writer.Write(testSequence, 0, testSequence.Length);
     }
     // check the Reader can read it
     ms.Position = 0;
     using (var reader = new WaveFileReader(ms))
     {
         Assert.AreEqual(16000, reader.WaveFormat.SampleRate, "Sample Rate");
         Assert.AreEqual(24, reader.WaveFormat.BitsPerSample, "Bits Per Sample");
         Assert.AreEqual(1, reader.WaveFormat.Channels, "Channels");
         Assert.AreEqual(testSequence.Length, reader.Length, "File Length");
         var buffer = new byte[600]; // 24 bit audio, block align is 3
         int read = reader.Read(buffer, 0, buffer.Length);
         Assert.AreEqual(testSequence.Length, read, "Data Length");
         for (int n = 0; n < read; n++)
         {
             Assert.AreEqual(testSequence[n], buffer[n], "Byte " + n);
         }
     }
 }
Esempio n. 23
0
        public static void RecordSound(string name)
        {
            int waveDeviceCount = WaveIn.DeviceCount;
            //detect presence of recording hardware
            if (waveDeviceCount > 0)
            {
                inputDevice = 0;
            }
            else
            {
                MessageBox.Show("No recording hardware detected", "iMasomoAdmin", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            wordName = name;
            try
            {
                
                waveIn = new WaveIn();
                waveIn.DeviceNumber = inputDevice;
                waveIn.WaveFormat = new NAudio.Wave.WaveFormat(44100, WaveIn.GetCapabilities(inputDevice).Channels);

                //in the presence of incoming data, write the data to a buffer
                waveIn.DataAvailable += waveIn_DataAvailable;
                waveWriter = new WaveFileWriter(Environment.CurrentDirectory + @"\Media\" + wordName + ".wav", waveIn.WaveFormat);
                waveIn.StartRecording();
                
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }
 private void Processing()
 {
     try
     {
         using (var waveWriterYour = new WaveFileWriter(@"F:\Desktop\\Recordshit\\" + Environment.UserName + " - " + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") + ".wav", new WaveFormat(48000, 16, 2)))
         while (true)
         {
             byte[] bufBytes;
             if (BufferCollection.TryTake(out bufBytes, Timeout.Infinite))
             {
                 if (bufBytes.Length == 0 || !_socketClient.Connected)
                     break;
                 _socketClient.Send(bufBytes);
                 waveWriterYour.Write(bufBytes, 0, bufBytes.Length);
                 waveWriterYour.Flush();
             }
             else
             {
                 break;
             }
         }
     }
     catch (Exception e)
     {
     }
 }
Esempio n. 25
0
 private void CreateCaptureStream(WaveFormat captureFormat)
 {
     int maxSeconds = CaptureSeconds == 0 ? 30 : CaptureSeconds;
     int captureBytes = maxSeconds * captureFormat.AverageBytesPerSecond;
     this.maxCaptureBytes = CaptureSeconds == 0 ? 0 : captureBytes;
     recordedStream = new MemoryStream(captureBytes + 50);
     writer = new WaveFileWriter(new IgnoreDisposeStream(recordedStream), captureFormat);
 }
Esempio n. 26
0
 public AudioRecorder(int microphone)
 {
     waveIn = new WaveIn();
     waveIn.DeviceNumber = microphone;
     waveIn.WaveFormat = new WaveFormat(44100, 1);
     bufferedWaveProvider = new BufferedWaveProvider(waveIn.WaveFormat);
     writer = new WaveFileWriter(Settings.Default.tempSoundLocation, waveIn.WaveFormat);
 }
Esempio n. 27
0
 public void stop()
 {
     waveInStream.StopRecording();
     waveInStream.Dispose();
     waveInStream = null;
     writer.Close();
     writer = null;
 }
Esempio n. 28
0
 /// <summary>
 /// Closes the WAV file
 /// </summary>
 public void Dispose()
 {
     if (writer != null)
     {
         writer.Dispose();
         writer = null;
     }
 }
Esempio n. 29
0
 //Event arguments to stop recording
 private void wavSource_RecordingStopped(object sender, EventArgs e)
 {
     wavSource.Dispose();
     wavSource = null;
     wavFile.Close();
     wavFile.Dispose();
     wavFile = null;
 }
Esempio n. 30
0
        public void iniciarCaptura()
        {
            try
            {
                /*WaveInCapabilities capabilities;

                for (int numberDevice = 0; numberDevice < WaveIn.DeviceCount; numberDevice++)
                {
                    capabilities = WaveIn.GetCapabilities(numberDevice);
                    Console.WriteLine("Producto->" + capabilities.ProductName.ToUpper().Trim());
                    if (capabilities.ProductName.ToUpper().Trim().Contains("BLUETOOTH"))
                    {
                        deviceBluetooth = numberDevice;
                        break;
                    }
                }*/

                foreach (IPAddress ip in System.Net.Dns.GetHostAddresses(""))
                {
                    if (Regex.IsMatch(ip.ToString(), @"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"))
                    {
                        ipLocal = ip.ToString();
                    }
                }

                wi = new WaveInEvent();
                wi.BufferMilliseconds = 1000;
                wi.DeviceNumber = deviceBluetooth;
                wi.WaveFormat = new WaveFormat(44100, 2);
                wi.DataAvailable += new EventHandler<WaveInEventArgs>(wi_DataAvailable);
                wi.StartRecording();

                /*wo = new WaveOutEvent();
                bwp = new BufferedWaveProvider(wi.WaveFormat);
                bwp.DiscardOnBufferOverflow = true;
                wo.Init(bwp);
                wo.Play();*/

                tempFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".wav");
                writer = new WaveFileWriter(tempFile, wi.WaveFormat);

                hilo = new Thread(new ThreadStart(iniciarStreaming));
                hilo.Start();
            }
            catch (Exception ex)
            {
                logger.WriteToEventLog("ERROR: " + ex.Message +
                                        Environment.NewLine +
                                        "STACK TRACE: " + ex.StackTrace,
                                        "Servicio de captura de audio [iniciarCaptura]",
                                        EventLogEntryType.Error,
                                        "LogSucursalAudio");
                logger.WriteToErrorLog("ERROR: " + ex.Message,
                                        ex.StackTrace,
                                        "capturaAudio.cs");
                Console.WriteLine("Error [iniciarCaptura]->" + ex.Message);
            }
        }
Esempio n. 31
0
 public void StartRecord()
 {
     //creates temporary wave file
     waveFileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString() + ".wav");
     waveWriter = new WaveFileWriter(waveFileName, recordingStream.WaveFormat);
     //Record data
     recordingStream.DataAvailable += new EventHandler<WaveInEventArgs>(recordingStream_DataAvailable);
     recordingStream.StartRecording();
 }
Esempio n. 32
0
 public void BeginRecording(string waveFileName)
 {
     if (recordingState != RecordingState.Monitoring)
     {
         throw new InvalidOperationException("Can't begin recording while we are in this state: " + recordingState.ToString());
     }
     writer = new WaveFileWriter(waveFileName, recordingFormat);
     recordingState = RecordingState.Recording;
 }
Esempio n. 33
0
 // Method to create wav file from float array
 public static void createWav(float[] array, String name, NAudio.Wave.WaveFormat audio)
 {
     NAudio.Wave.WaveFormat waveFormat = audio;
     // Console.WriteLine(waveFormat.SampleRate + " " + waveFormat.BitsPerSample + " " + waveFormat.Channels);
     using (NAudio.Wave.WaveFileWriter writer = new NAudio.Wave.WaveFileWriter(name + ".wav", waveFormat))
     {
         writer.WriteSamples(array, 0, array.Length);
     }
 }
Esempio n. 34
0
        public SoundCardRecorder(MMDevice device, string filePath, string song)
        {
            Device = device;
            FilePath = filePath;
            Song = song;

            _waveIn = new WasapiCapture(Device);
            _writer = new WaveFileWriter(FilePath, _waveIn.WaveFormat);
            _waveIn.DataAvailable += OnDataAvailable;
        }
Esempio n. 35
0
        public void Record(string fileName, int volume = 100)
        {
            _waveIn = new WaveIn { WaveFormat = new WaveFormat() };
            _writer = new WaveFileWriter(fileName, _waveIn.WaveFormat);

            TrySetVolumeControl(_waveIn.GetMixerLine(), volume);

            _waveIn.DataAvailable += new_dataAvailable;
            _waveIn.StartRecording();
        }
Esempio n. 36
0
		/// ------------------------------------------------------------------------------------
		public FileWriterThread(WaveFileWriter writer)
		{
			if (writer == null)
				throw new ArgumentNullException("writer");
			_writer = writer;
			_data = new Queue<byte[]>();
			_thread = new Thread(ProcessData);
			_thread.Name = GetType().Name;
			_thread.Priority = ThreadPriority.BelowNormal;
			_thread.Start();
		}
Esempio n. 37
0
        public void Run()
        {
            var filename = "test.wav";
            waveIn = new WasapiLoopbackCapture();
            waveIn.DataAvailable += OnDataAvailable;
            //waveIn.RecordingStopped += waveIn_RecordingStopped;

            _writer = new WaveFileWriter(filename, waveIn.WaveFormat);

            waveIn.StartRecording();
        }
Esempio n. 38
0
        /// <summary>
        /// Starts recording.
        /// </summary>
        public void StartRecord(string audioFileName)
        {
            waveIn = new WaveInEvent();
            waveIn.DeviceNumber = AudioController.getInstance().GetDefaultInputDeviceNumber();
            waveIn.WaveFormat = new WaveFormat(44100, 2);
            waveIn.DataAvailable += OnDataAvailable;
            writer = new WaveFileWriter(audioFileName, waveIn.WaveFormat);
            isRecording = true;

            waveIn.StartRecording();
        }
Esempio n. 39
0
 public void Stop()
 {
     if (_waveIn != null)
     {
         _waveIn.StopRecording();
         _waveIn.Dispose();
         _waveIn = null;
         _writer.Close();
         _writer = null;
     }
 }
        public void StartRecording()
        {
            waveInStream = new WaveIn();
            waveInStream.WaveFormat = new WaveFormat(44100, 16, 1);

            writer = new WaveFileWriter(FileName, waveInStream.WaveFormat);

            waveInStream.DataAvailable += WaveInStream_DataAvailable;

            waveInStream.StartRecording();
        }
Esempio n. 41
0
        private void recordBtn_Click(object sender, EventArgs e)
        {
            if (setMode)
            {
                try
                {
                    String filename = "Class" + LoginForm.classSec + "_kidWordAudio/test.wav";
                    recordBtn.Text       = "STOP";
                    wavSource            = new NAudio.Wave.WaveIn();
                    wavSource.WaveFormat = new NAudio.Wave.WaveFormat(44100, 1);

                    wavSource.DataAvailable    += new EventHandler <NAudio.Wave.WaveInEventArgs>(wavSource_DataAvail);
                    wavSource.RecordingStopped += new EventHandler <NAudio.Wave.StoppedEventArgs>(wavSource_RecordingStop);

                    wavFile = new NAudio.Wave.WaveFileWriter(filename, wavSource.WaveFormat);
                    wavSource.StartRecording();
                    setMode = false;
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                //When you press "STOP", it automatically compares
                wavSource.StopRecording();

                String recordWAV_file = "Class" + LoginForm.classSec + "_kidWordAudio/test.wav";
                String refWAV_file    = "Class" + LoginForm.classSec + "_kidWordAudio/" + levels[curPos] + ";.wav";

                java.io.File f1 = new java.io.File(recordWAV_file);
                java.io.File f2 = new java.io.File(refWAV_file);

                if (!f1.exists() || !f2.exists())
                {
                    MessageBox.Show("WARNING: One of the files might be missing!");
                }
                else
                {
                    float compute_Result = compareAudio(recordWAV_file, refWAV_file);
                    if (compute_Result >= 10.0)
                    {
                        MessageBox.Show("Matched: " + compute_Result.ToString() + "\n You Win !");
                    }
                    else
                    {
                        MessageBox.Show("Matched: " + compute_Result.ToString() + "\n Try Again !");
                    }
                }
                recordBtn.Text = "RECORD";
                setMode        = true;
            }
        }
Esempio n. 42
0
        //public RtpRecordInfo() : this (WaveFormat.CreateMuLawFormat(8000, 1), "", "")
        //{
        //}

        public RtpRecordInfo(WaveFormat _codec, string savepath, string filename)
        {
            DateTime now = DateTime.Now;
            TimeSpan ts = now - (new DateTime(1970, 1, 1, 0, 0, 0, 0));
            this.idx = ts.TotalMilliseconds;
            this.codec = _codec;
            this.savepath = savepath;
            this.filename = filename;

            writer = new WaveFileWriter(string.Format(@"{0}\{1}", savepath, filename), pcmFormat8);
            this.InitTimer();
        }
Esempio n. 43
0
        private void btn_RECSTOP_Click(object sender, EventArgs e)
        {
            if (!isRecording)
            {
                if (cmb_InputsList.SelectedItem == null)
                {
                    MessageBox.Show("Error! \n No Input Selected, Please select an Audio Input before recording");
                    return;
                }

                SaveFileDialog save = new SaveFileDialog();
                save.Filter = "Wave File(*.wav)|*.wav;";
                if (save.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }
                else
                {
                    lst_samplelist.Items.Add(save.FileName);
                }

                int deviceNumber = cmb_InputsList.SelectedIndex;

                InputStream = new NAudio.Wave.WaveIn();
                InputStream.DeviceNumber = deviceNumber;
                InputStream.WaveFormat   = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);

                InputStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(InputStream_DataAvailable);
                waveWriter = new NAudio.Wave.WaveFileWriter(save.FileName, InputStream.WaveFormat);

                InputStream.StartRecording();

                btn_RECSTOP.Text = "STOP";
                isRecording      = true;
            }
            else
            {
                if (InputStream != null)
                {
                    InputStream.StopRecording();
                    InputStream.Dispose();
                    InputStream = null;
                }
                if (waveWriter != null)
                {
                    waveWriter.Dispose();
                    waveWriter = null;
                }
                btn_RECSTOP.Text = "REC";
                isRecording      = false;
            }
        }
Esempio n. 44
0
        public void waveSource_RecordingStopped(object sender, StoppedEventArgs e)
        {
            if (WaveSource != null)
            {
                WaveSource.Dispose();
                WaveSource = null;
            }

            if (WaveFile != null)
            {
                WaveFile.Dispose();
                WaveFile = null;
            }
        }
Esempio n. 45
0
        /// <summary>
        /// 开始录音
        /// </summary>
        public void beginSave()
        {
            //Accord.DirectSound.AudioDeviceCollection a1 = new AudioDeviceCollection(AudioDeviceCategory.Capture);
            //Accord.DirectSound.AudioDeviceCollection a2 = new AudioDeviceCollection(AudioDeviceCategory.Output);
            //AudioCaptureDevice a3 = new AudioCaptureDevice();

            //this.source = new AudioCaptureDevice()
            //{
            //    DesiredFrameSize = 4096,
            //    SampleRate = 22050,
            //    Format = SampleFormat.Format16Bit
            //};


            //this.source.NewFrame += Source_NewFrame;
            //this.source.AudioSourceError += Source_AudioSourceError;

            //MemoryStream s = new MemoryStream();
            //this.encoder = new WaveEncoder(s);

            //this.source.Start();

            //this.soundStream = s;
            this.source                   = new WaveIn();
            this.source.WaveFormat        = new WaveFormat(8000, 1);
            this.source.DataAvailable    += this.Source_NewFrame;
            this.source.RecordingStopped += Source_RecordingStopped;

            //MemoryStream s = new MemoryStream();
            //this.encoder = new WaveEncoder(s);

            //@"a.wav"
            fileName = Guid.NewGuid().ToString().Replace("-", "");

            string path = Path.Combine(Application.StartupPath, "voices");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path         = Path.Combine(path, string.Format("{0}.wav", fileName));
            this.encoder = new WaveFileWriter(path, this.source.WaveFormat);
            //this.encoder = new WaveFileWriter(string.Format("{0}.wav", fileName), this.source.WaveFormat);
            this.source.StartRecording();


            isRun       = true;
            currentTime = 0;
            this.tmVoice.Start();
        }
        private void stopRecordSound()
        {
            if (sourceStream != null)
            {
                sourceStream.StopRecording();
                sourceStream.Dispose();
                sourceStream = null;
            }

            if (waveWriter != null)
            {
                waveWriter.Dispose();
                waveWriter = null;
            }
        }
Esempio n. 47
0
        //Event args to stop recording events
        private void wavSource_RecordingStop(object sender, NAudio.Wave.StoppedEventArgs e)
        {
            if (wavSource != null)
            {
                wavSource.Dispose();
                wavSource = null;
            }

            if (wavFile != null)
            {
                wavFile.Dispose();
                wavFile = null;
            }
            //recBtn.Enabled = true;
        }
        private void stopRecordSound()
        {
            if (_sourceStream != null)
            {
                _sourceStream.StopRecording();
                _sourceStream.Dispose();
                _sourceStream = null;
            }

            if (_waveWriter != null)
            {
                _waveWriter.Dispose();
                _waveWriter = null;
            }
        }
Esempio n. 49
0
        private void recordButton_Click(object sender, EventArgs e)
        {
            state = "record";
            recordButton.Enabled = false;
            outputFilename       = String.Format("Clip {0:yyy-MM-dd HH-mm-ss}.wav", DateTime.Now);
            outputFilePath       = Path.Combine(outputFolder, outputFilename);
            Debug.Print(outputFilePath);
            sourceStream = new NAudio.Wave.WaveIn();
            sourceStream.DeviceNumber = deviceNumber;
            sourceStream.WaveFormat   = new NAudio.Wave.WaveFormat(sampleRate, inChannels);

            sourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable);
            waveWriter = new NAudio.Wave.WaveFileWriter(outputFilePath, sourceStream.WaveFormat);

            sourceStream.StartRecording();
        }
Esempio n. 50
0
        static void Main(string[] args)
        {
            var fileName = @"C:\Users\milkitic\Downloads\HuΣeR Vs. SYUNN feat.いちか - 狂水一華.mp3";
            var obj      = new AudioDataHelper(fileName);
            var data     = obj.GetData(out var waveFormat);

            var memoryStream = new MemoryStream(data);
            var waveStream   = new RawSourceWaveStream(memoryStream, waveFormat);
            var p            = new WaveFloatTo16Provider(waveStream);

            WaveFileWriter.CreateWaveFile("a.wav", p);

            var reader = new Mp3FileReaderBase(fileName, format => new DmoMp3FrameDecompressor(format));

            WaveFileWriter.CreateWaveFile("b.wav", reader);
        }
Esempio n. 51
0
        private void button_stop_Click(object sender, EventArgs e)
        {
            waveOut?.Stop();
            waveOut?.Dispose();
            waveOut = null;

            sourceStream?.StopRecording();
            sourceStream?.Dispose();
            sourceStream = null;

            waveWriter?.Dispose();
            waveWriter = null;

            //Label
            this.Label_Status.Text = "待機中";
        }
Esempio n. 52
0
        private void button11_Click(object sender, EventArgs e)
        {
            if (sourceStream != null)
            {
                sourceStream.StopRecording();
                sourceStream.Dispose();
                sourceStream = null;
            }
            if (waveWriter != null)
            {
                waveWriter.Dispose();
                waveWriter = null;
            }

            recording_timer.Stop();
        }
Esempio n. 53
0
        //NAudio.Wave.WaveFileWriter waveWriter = null;
        //NAudio.Wave.WaveFileReader waveReader = null;
        //NAudio.Wave.DirectSoundOut output = null;

        public frmRecording()
        {
            InitializeComponent();

            this.WindowState   = FormWindowState.Minimized;
            this.ShowInTaskbar = false;

            outputFilename = String.Format("Clip {0:yyy-MM-dd HH-mm-ss}.wav", DateTime.Now);
            outputFilePath = Path.Combine(outputFolder, outputFilename);
            Debug.Print(outputFilePath);
            sourceStream = new NAudio.Wave.WaveIn();
            sourceStream.DeviceNumber   = deviceNumber;
            sourceStream.WaveFormat     = new NAudio.Wave.WaveFormat(sampleRate, inChannels);
            sourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable);
            waveWriter = new NAudio.Wave.WaveFileWriter(outputFilePath, sourceStream.WaveFormat);

            sourceStream.StartRecording();
        }
        //This function combines each of the individual audio files into one master audio file for refrenece.
        public static void Combine_Audio_Files(string outputFile, string sourceFiles)
        {
            byte[] buffer = new byte[1024];
            NAudio.Wave.WaveFileWriter waveFileWriter = null;
            string sourceFile = "";

            try
            {
                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(sourceFiles);
                foreach (System.IO.FileInfo file in di.GetFiles())
                {
                    sourceFile = sourceFiles + file.Name;

                    using (WaveFileReader reader = new WaveFileReader(sourceFile))
                    {
                        if (waveFileWriter == null)
                        {
                            // first time in create new Writer
                            waveFileWriter = new WaveFileWriter(outputFile, reader.WaveFormat);
                        }
                        else
                        {
                            if (!reader.WaveFormat.Equals(waveFileWriter.WaveFormat))
                            {
                                throw new InvalidOperationException("Can't concatenate WAV Files that don't share the same format");
                            }
                        }

                        int read;
                        while ((read = reader.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            waveFileWriter.WriteData(buffer, 0, read);
                        }
                    }
                }
            }
            finally
            {
                if (waveFileWriter != null)
                {
                    waveFileWriter.Dispose();
                }
            }
        }
Esempio n. 55
0
        private void button_Start_Click(object sender, EventArgs e)
        {
            //マイク元を指定していない場合。
            if (listview_sources.SelectedItems.Count == 0)
            {
                return;
            }

            //オーディオチェーン:WaveIn(rec)  ⇒ Callback() ⇒ waveWriter

            //録音先のwavファイル
            SaveFileDialog save = new SaveFileDialog();

            save.Filter = "Wave File (*.wav)|*.wav;";
            if (save.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //選択した録音デバイス番号
            int deviceNumber = listview_sources.SelectedItems[0].Index;

            //waveIn selet Recording Deivce

            sourceStream = new WaveIn();   //sourceStreamは、78で定義
            sourceStream.DeviceNumber = deviceNumber;
            //  sourceStream.WaveFormat = new WaveFormat(16000, WaveIn.GetCapabilities(deviceNumber).Channels);
            sourceStream.WaveFormat = new WaveFormat(16000, 1);

            //録音のコールバックkな数 k??
            sourceStream.DataAvailable += new EventHandler <WaveInEventArgs>(sourceStream_DataAvailable);

            //wave 出力
            waveWriter = new WaveFileWriter(save.FileName, sourceStream.WaveFormat);


            //Label
            this.Label_Status.Text = "録音中" + "\r\n" + "開始時間:" + DateTime.Now;;

            //録音開始
            sourceStream.StartRecording();
        }
Esempio n. 56
0
        public void record()
        {
            Console.WriteLine();
            Console.WriteLine("Recording on Device  # 0 ");

            WaveSource = new WaveInEvent();
            WaveSource.DeviceNumber = ActiveDevice;
            WaveSource.WaveFormat   = new WaveFormat(44100, 1);

            WaveSource.DataAvailable    += new EventHandler <WaveInEventArgs>(waveSource_DataAvailable);
            WaveSource.RecordingStopped += new EventHandler <StoppedEventArgs>(waveSource_RecordingStopped);

            long milliseconds = (long)Math.Round(DateTime.Now.Subtract(DateTime.MinValue.AddYears(1969)).TotalMilliseconds);

            Filename = Path.Combine(samplePath, $"{sampleCount}_AudioSample_{milliseconds}.wav");
            sampleCount++;
            WaveFile = new WaveFileWriter(Filename, WaveSource.WaveFormat);

            WaveSource.StartRecording();
        }
Esempio n. 57
0
 // wywolanie dispose oraz zatrzymanie i ustawienie na null wszystkiego co uzywamy
 private void stopBtn_Click_1(object sender, EventArgs e)
 {
     if (waveOut != null)
     {
         waveOut.Stop();
         waveOut.Dispose();
         waveOut = null;
     }
     if (sourceStream != null)
     {
         sourceStream.StopRecording();
         sourceStream.Dispose();
         sourceStream = null;
     }
     if (waveWriter != null)
     {
         waveWriter.Dispose();
         waveWriter = null;
     }
 }
Esempio n. 58
0
 private void frmRecording_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (waveOut != null)
     {
         waveOut.Stop();
         waveOut.Dispose();
         waveOut = null;
     }
     if (sourceStream != null)
     {
         sourceStream.StopRecording();
         sourceStream.Dispose();
         sourceStream = null;
     }
     if (waveWriter != null)
     {
         waveWriter.Dispose();
         waveWriter = null;
     }
 }
Esempio n. 59
0
        private void btnIniciar_Click(object sender, EventArgs e)
        {
            string pasta = @"C:\PEDGRAVACAO\Audios",
                   nmAudio;

            int dia = DateTime.Now.Day,
                mes = DateTime.Now.Month,
                ano = DateTime.Now.Year;

            if (!Directory.Exists(pasta))
            {
                Directory.CreateDirectory(pasta);
            }

            if (micList.SelectedItem == null)
            {
                MessageBox.Show("Por favor selecionar o Microfone a ser usado!");
            }
            else
            {
                nmAudio = ano.ToString() + "_" + mes.ToString() + "_" + dia.ToString() + ".wav";
                String nvCaminho = Path.Combine(pasta, nmAudio);



                var deviceNumber = micList.SelectedIndex;

                sourceStream = new NAudio.Wave.WaveIn();
                sourceStream.DeviceNumber = deviceNumber;
                sourceStream.WaveFormat   = new NAudio.Wave.WaveFormat(16000, 1);

                sourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable);
                waveWriter = new NAudio.Wave.WaveFileWriter(nvCaminho, sourceStream.WaveFormat);

                sourceStream.StartRecording();

                btnParar.Enabled   = true;
                btnIniciar.Enabled = false;
            }
        }
Esempio n. 60
0
        // Method that initialized name, location and thread for
        // wave file to which input stream is going to be recorded
        private void initRecord(bool stream)
        {
            //Console.WriteLine(inputName.Text);
            wavSaveName = inputName.Text + ".wav";
            int deviceNumber;

            if (inputList.SelectedItem == null)
            {
                return;
            }

            deviceNumber = inputList.SelectedIndex;

            sourceStream = new NAudio.Wave.WaveIn();
            sourceStream.DeviceNumber = deviceNumber;
            int rate, bits = 16, chn = 1;

            if (inputFormat.SelectedIndex == 0)
            {
                rate = 11025;
            }
            else
            {
                rate = 16000;
            }
            sourceStream.WaveFormat         = new NAudio.Wave.WaveFormat(rate, bits, chn);
            sourceStream.BufferMilliseconds = 50;
            if (!stream)
            {
                sourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(OnDataAvailable);
                waveWriter = new NAudio.Wave.WaveFileWriter(wavSaveName, sourceStream.WaveFormat);
            }
            else
            {
                algo.originalWavSamples     = new double[800];
                sourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(StreamDataAvailable);
                waveBuffer = new NAudio.Wave.BufferedWaveProvider(sourceStream.WaveFormat);
                samples    = waveBuffer.ToSampleProvider();
            }
        }