StartRecording() public method

Start Recording
public StartRecording ( ) : void
return void
 public void CanCaptureDefaultDeviceInDefaultFormatUsingWasapiCapture()
 {
     using (var wasapiClient = new WasapiCapture())
     {
         wasapiClient.StartRecording();
         Thread.Sleep(1000);
         wasapiClient.StopRecording();
     }
 }
Example #2
0
 public void Start()
 {
     if (_isStarting) return;
     _isStarting = true;
     ResetSampleAggregator();
     _waveIn = new WasapiCapture(Device);
     _waveIn.DataAvailable +=OnDataAvailable;
     //_waveIn.RecordingStopped += new EventHandler<StoppedEventArgs>(OnRecordingStopped)
     _waveIn.StartRecording();
 }
 private void Record()
 {
     try
     {
         capture = new WasapiCapture(SelectedDevice);
         capture.ShareMode = ShareModeIndex == 0 ? AudioClientShareMode.Shared : AudioClientShareMode.Exclusive;
         capture.WaveFormat =
             SampleTypeIndex == 0 ? WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channelCount) :
             new WaveFormat(sampleRate, bitDepth, channelCount);
         currentFileName = String.Format("NAudioDemo {0:yyy-MM-dd HH-mm-ss}.wav", DateTime.Now);
         RecordLevel = SelectedDevice.AudioEndpointVolume.MasterVolumeLevelScalar;
         capture.StartRecording();
         capture.RecordingStopped += OnRecordingStopped;
         capture.DataAvailable += CaptureOnDataAvailable;
         RecordCommand.IsEnabled = false;
         StopCommand.IsEnabled = true;
         Message = "Recording...";
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
Example #4
0
        static void WaveInExample()
        {
            var waveIn = new WasapiCapture();
            waveIn.WaveFormat = new WaveFormat(44100, 8, 2);

            Console.WriteLine("Device format: " + waveIn.WaveFormat.ToString());
            FDecoder = new LTCSharp.Decoder(waveIn.WaveFormat.SampleRate, 25, 32);
            waveIn.DataAvailable += waveIn_DataAvailable;
            waveIn.StartRecording();

            Stopwatch timer = new Stopwatch();
            timer.Start();
            while (true) //timer.Elapsed < new TimeSpan(0, 0, 60))
            {
                lock (FDecoder)
                {
                    if (FDecoder.GetQueueLength() > 0)
                    {
                        try
                        {
                            var frame = FDecoder.Read();
                            var timecode = frame.getTimecode();
                            Console.WriteLine(timecode.ToString());
                        }
                        catch (Exception e)
                        {
                            Console.Write(e);
                        }
                    }
                    else
                    {
                        Thread.Sleep(10);
                    }
                }
            }
            timer.Stop();
        }
Example #5
0
 public void CanReuseWasapiCapture()
 {
     using (var wasapiClient = new WasapiCapture())
     {
         wasapiClient.StartRecording();
         Thread.Sleep(1000);
         wasapiClient.StopRecording();
         Thread.Sleep(1000);
         wasapiClient.StartRecording();
     }
 } 
Example #6
0
            public DecodeInstance(MMDevice device, uint channels, uint channel, double framerate)
            {
                if (device == null)
                    throw (new Exception("No device selected"));

                FChannel = (int) channel;
                FCapture = new WasapiCapture(device);
                FCapture.WaveFormat = new WaveFormat(44100, 8, (int) channels);
                channels = (uint) FCapture.WaveFormat.Channels;

                if (channel >= channels)
                {
                    throw (new Exception("Capture channel index out of range"));
                }

                FDecoder = new LTCSharp.Decoder(FCapture.WaveFormat.SampleRate, (int) framerate, 32);

                FCapture.DataAvailable += FCapture_DataAvailable;
                FCapture.StartRecording();
            }
        /// <summary>
        /// Adds a device to the monitoring list
        /// </summary>
        /// <param name="device">Device to add</param>
        public void Add(MMDevice device)
        {
            if (Devices.Contains(device)) return;

            if (device.DataFlow == DataFlow.Capture)
            {
                WasapiCapture deviceCapture = new WasapiCapture(device);
                deviceCapture.StartRecording();
                deviceCaptures.Add(device, deviceCapture);
            }

            timer.Enabled = true;

            Devices.Add(device);
        }
Example #8
0
        public static void Record()
        {
            Init();
            _filename = Core.UserDir + "\\" + Path.GetRandomFileName().Replace(".", "") + ".wav";

            if (_recorddevice.DataFlow == DataFlow.Render)
            {
                cap = new WasapiLoopbackCapture(_recorddevice);
                writer = new WaveFileWriter(_filename, cap.WaveFormat);
                cap.RecordingStopped += new EventHandler<StoppedEventArgs>(cap_RecordingStopped);
                cap.StartRecording();
                cap.DataAvailable += new EventHandler<WaveInEventArgs>(cap_DataAvailable);
                _running = true;
            }
            else
            {
                cap = new WasapiCapture(_recorddevice);
                writer = new WaveFileWriter(_filename, cap.WaveFormat);
                cap.RecordingStopped += new EventHandler<StoppedEventArgs>(cap_RecordingStopped);
                cap.StartRecording();
                cap.DataAvailable += new EventHandler<WaveInEventArgs>(cap_DataAvailable);
                _running = true;
               }
        }
Example #9
0
        private void setDevice(MMDevice dev)
        {
            if (FIsRecording)
                return;

            FDevice = dev;
            closeDevice();

            if (FPinInDevice[0] == null)
            {
                FPinOutStatus[0] = "No device selected";
                return;
            }

            FWaveIn = new WasapiCapture(FPinInDevice[0]);

            //if (FWaveIn.WaveFormat.Channels > 2)
            //{
            //    FWaveQuadToStereo = new QuadToStereoStream32(FWaveIn);
            //    FDownsampleQuad = true;
            //}

            FWaveIn.StartRecording();
            handleData = new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);
            FWaveIn.DataAvailable += handleData;

            FPinOutStatus[0] = "Device opened";
        }