private void OnSampleReceived(object sender, EventArgs e) { byte[] buffer = null; int bytesRead = _capture.ReadBuffer(out buffer); if (bytesRead > 0) { float peak = PcmHelper.GetPeak(buffer, bytesRead); if (_state == RecorderState.Recording && _isCapturing && _writer.CanWrite) { if ((SkipSilence && peak > 0.04) || !SkipSilence) { _size += _writer.Write(buffer, 0, bytesRead); _bytesCaptured += bytesRead; _duration = PcmHelper.GetDuration(_bytesCaptured, _sampleRate, _channels, _bitRate); } } RaiseSampleReceived(peak); } }
private void OnBufferReady(object sender, EventArgs e) { int bytesRead = 0; byte[] buffer = new byte[1024]; while ((bytesRead = this._microphone.GetData(buffer, 0, buffer.Length)) > 0) { float peak = PcmHelper.GetPeak(buffer, bytesRead); if (_state == RecorderState.Recording && _isCapturing && _writer.CanWrite) { if ((SkipSilence && peak > 0.04) || !SkipSilence) { _size += _writer.Write(buffer, 0, bytesRead); _bytesCaptured += bytesRead; _duration = (int)_microphone.GetSampleDuration(_bytesCaptured).TotalSeconds; } } RaiseSampleReceived(peak); } }