/// <summary> /// Asynchronously starts capturing. /// </summary> /// <param name="outputStream">A writeable stream where the captured data will be /// written (in formate specified by OutputType property).</param> private void Start(Stream outputStream, bool ownsOutputStream) { if (capturing == null) { lock (CaptureLock) { if (capturing == null) { try { capturing = new CapturingProcess(); capturing.OwnsOutputStream = ownsOutputStream; FireEvent(Starting); SoundCapture capture = new SoundCapture(WaveFormat, outputStream, UseSynchronizationContext); capturing.Process = capture; capture.CaptureDevice = CaptureDevice; if (NormalizeVolume) { capture.Filters.Add(new Filters.PcmNormalizerFilter()); } if (OutputType == Outputs.Mp3) { Filters.Mp3CompressingFilter compressor = new Filters.Mp3CompressingFilter(); compressor.Mp3BitRate = Mp3BitRate; capture.Filters.Add(compressor); } else if (OutputType == Outputs.Wav) { capture.Filters.Add(new Filters.RiffFilter()); } //Else a raw PCM will go off. capture.Started += (o, e) => { if (Started != null) { Started(this, e); } }; //Stopped is fired by this component itself. capture.Start(); } catch { Stop(); throw; } } } } }
/// <summary> /// Asynchronously starts capturing. /// </summary> /// <param name="outputStream">A writeable stream where the captured data will be /// written (in formate specified by OutputType property).</param> private void Start(Stream outputStream, bool ownsOutputStream) { if (capturing == null) { lock (CaptureLock) { if (capturing == null) { try { capturing = new CapturingProcess(); capturing.OwnsOutputStream = ownsOutputStream; SoundCapture capture = new SoundCapture(WaveFormat, outputStream, UseSynchronizationContext); capturing.Process = capture; capture.CaptureDevice = CaptureDevice; if (UseVOX) { int OneSecBufferSize = WaveFormat.SampleRate * ((WaveFormat.BitsPerSample * WaveFormat.Channels) / 8); this.vox = new Filters.VOXFilter(OneSecBufferSize * BufferSeconds); this.vox.NAttack = MinSoundSeconds * 8; // One buffer is 1/8 sec (125usec) this.vox.NDecay = MinSoundSeconds * 8; this.vox.VolumeThreshold = VOXThreshold; this.vox.VOXStopping += new EventHandler(vox_VOXStopping); capture.Filters.Add(vox); } if (NormalizeVolume) { capture.Filters.Add(new Filters.PcmNormalizerFilter()); } if (OutputType == Outputs.Mp3) { Filters.Mp3CompressingFilter compressor = new Filters.Mp3CompressingFilter(); compressor.Mp3BitRate = Mp3BitRate; capture.Filters.Add(compressor); } else if (OutputType == Outputs.Wav) { capture.Filters.Add(new Filters.RiffFilter()); } //Else a raw PCM will go off. capture.Started += (o, e) => { if (Started != null) { Started(this, e); } }; //Stopped is fired by this component itself. capture.Start(); } catch { Stop(); throw; } } } } }