//what happens when the sourcestream receives data
        private void SourceStream_DataAvailuable(object sender, NAudio.Wave.WaveInEventArgs e)
        {
            if (waveWriter == null) return; //exit method if wavewriter hasnt been set up yet

            waveWriter.Write(e.Buffer, 0, e.BytesRecorded); //write the contents to the savefile using the wavewriter
            waveWriter.Flush(); //flush the wavewriters contents after
        }
 //Event args to check if Data is available
 private void wavSource_DataAvail(object sender, NAudio.Wave.WaveInEventArgs e)
 {
     if (wavFile != null)
     {
         wavFile.Write(e.Buffer, 0, e.BytesRecorded);
         wavFile.Flush();
     }
 }
 /// <summary>
 /// Writes the wave file.
 /// </summary>
 /// <param name="inputArray">The input array.</param>
 void WriteFile(short[] inputArray, string filePath)
 {
     NAudio.Wave.WaveFormat     waveFormat = new NAudio.Wave.WaveFormat(44100, 16, 1);
     NAudio.Wave.WaveFileWriter writer     = new NAudio.Wave.WaveFileWriter(filePath, waveFormat);
     writer.WriteSamples(inputArray, 0, inputArray.Length);
     writer.Flush();
     writer.Dispose();
 }
示例#4
0
 private void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e)
 {
     if (waveWriter == null)
     {
         return;
     }
     waveWriter.WriteData(e.Buffer, 0, e.BytesRecorded);
     waveWriter.Flush();
 }
示例#5
0
 /// <summary>
 /// input stream event for recording
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void waveIn_DataAvailableRecording(object sender, NAudio.Wave.WaveInEventArgs e)
 {
     // if sound is recorded, it is written to file
     if (waveFile != null)
     {
         waveFile.Write(e.Buffer, 0, e.BytesRecorded);
         waveFile.Flush();
     }
 }
示例#6
0
        private void SourceStreamDataAvailableEvent(object sender, NAudio.Wave.WaveInEventArgs e)
        {
            if (m_oWaveWriter == null)
            {
                return;
            }

            m_oWaveWriter.Write(e.Buffer, 0, e.BytesRecorded);
            m_oWaveWriter.Flush();
        }
示例#7
0
        static void Main()
        {
            var stream = new NAudio.Wave.WaveFileWriter(@"E:\C1_single.wav", new NAudio.Wave.WaveFormat(44100, 2));
            var writer = new System.IO.BinaryWriter(stream);

            for (int i = 0; i < 44100 * 10; ++i)
            {
                short value = (short)(Math.Cos(2 * Math.PI * 261 * i / 44100) * 16384); // Not too loud

                writer.Write(value);
                writer.Write(value);
            }
            writer.Flush();
            stream.Flush();
            stream.Close();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormFourier());
        }
示例#8
0
文件: Audio.cs 项目: BSalita/Woundify
        private static void WaveIn_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e)
        {
            if (Options.options.debugLevel >= 4)
            {
                Log.WriteLine("Received buffer: length=" + e.BytesRecorded.ToString());
            }
            else
            {
                Console.Write("*");
            }
            // can't derive waveInFile from WaveInEvent so must use class property

            // add received wave audio to waveProvider buffer
            //if (waveInProvider != null)
            //waveInProvider.AddSamples(e.Buffer, 0, e.BytesRecorded);

            // add received wave audio to memory stream
            if (waveInFile != null)
            {
                waveInFile.Write(e.Buffer, 0, e.BytesRecorded);
                waveInFile.Flush();
            }
        }
        public override void HotkeyTriggered()
        {
            if (recorder == null)
            {
                if (audioDevice.Recorders.Count > 0)
                {
                    recorder = audioDevice.Recorders[0];
                }
            }

            if (recorder == null)
            {
                return;
            }

            int count = recorder.RecordedBytes.Count;

            byte[] audioData = recorder.RecordedBytes.Copy();
            NAudio.Wave.WaveFileWriter waveWriter = new NAudio.Wave.WaveFileWriter(ExtraData1, recorder.WaveSource.WaveFormat);
            waveWriter.Write(audioData, 0, count);
            waveWriter.Flush();
            waveWriter.Dispose();
        }
示例#10
0
 private void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e)
 {
     waveWriter.Write(e.Buffer, 0, e.BytesRecorded); // LAST BYTES ARE NOT RECORDED.
     waveWriter.Flush();
 }