public void StopRecording() { _endTicks = 0; _forceOnEndTicks = 0; _currentKickState = AudioKickState.Off; EndRecording(); }
public void ProcessSamples(bool bHasAudio, byte[] samples) { if (samples == null || samples.Length <= 0) { return; } if (bHasAudio) { KickRecording(AudioKickState.Kick); } if (_recordingEnabled && _waveWriter != null) { if (_useResampler) { Buffer.BlockCopy(samples, 0, _resampleStream.SourceBuffer, 0, samples.Length); int sourceBytesConverted = 0; int convertedBytes = _resampleStream.Convert(samples.Length, out sourceBytesConverted); if (sourceBytesConverted == samples.Length) { byte[] convBytes = new byte[convertedBytes]; Buffer.BlockCopy(_resampleStream.DestBuffer, 0, convBytes, 0, convertedBytes); _waveWriter.Write(convBytes, 0, convBytes.Length); } } else { _waveWriter.Write(samples, 0, samples.Length); } } long curTicks = DateTime.Now.Ticks; if (_currentKickState == AudioKickState.On) { if (_forceOnEndTicks == 0 || _forceOnEndTicks < curTicks) { _forceOnEndTicks = 0; _endTicks = curTicks + RecordingKickTimeTicks; _currentKickState = AudioKickState.Kick; } } else if (!_recordingEnabled || (_endTicks == 0) || (_currentKickState == AudioKickState.Kick && _endTicks < DateTime.Now.Ticks)) { EndRecording(); } }
private void StartRecording(AudioKickState kickType) { if (!_recordingEnabled) { return; } DateTime dt = DateTime.Now; string fileName; _currentKickState = kickType; lock (_lockObj) { _currentFileName = string.Format("{0}_{1}.wav", RecordingPrefix, dt.ToString("yyyyMMdd_HHmmss")); fileName = System.IO.Path.Combine(AppSettings.Instance.RecordFileDirectory, _currentFileName); _waveWriter = new WaveFileWriter(fileName, _fileWaveFormat); } _endTicks = dt.Ticks + RecordingKickTimeTicks; }
public void KickRecording(AudioKickState kickType) { if (_recordingType == SignalRecordingType.Fixed) { if (_waveWriter == null) { _currentKickState = AudioKickState.Kick; _forceOnEndTicks = DateTime.Now.Ticks + RecordingKickTimeTicks; StartRecording(AudioKickState.Kick); } } else { AudioKickState calcKickState = kickType; if (kickType == AudioKickState.Off) { calcKickState = AudioKickState.Kick; _forceOnEndTicks = 0; } else if (kickType == AudioKickState.On) { _forceOnEndTicks = DateTime.Now.Ticks + MAX_FORCE_ON_TIME; } if (_waveWriter == null) { StartRecording(kickType); } else if (_currentKickState == AudioKickState.On && kickType == AudioKickState.Kick) { _forceOnEndTicks = DateTime.Now.Ticks + MAX_FORCE_ON_TIME; } else if (_currentKickState == AudioKickState.On && kickType == AudioKickState.Off) { _currentKickState = AudioKickState.Kick; _endTicks = DateTime.Now.Ticks + RecordingKickTimeTicks; } else { _currentKickState = calcKickState; _endTicks = DateTime.Now.Ticks + RecordingKickTimeTicks; } } }
private void StartRecording(AudioKickState kickType) { if (!_recordingEnabled) return; DateTime dt = DateTime.Now; string fileName; _currentKickState = kickType; lock (_lockObj) { _currentFileName = string.Format("{0}_{1}.wav", RecordingPrefix, dt.ToString("yyyyMMdd_HHmmss")); fileName = System.IO.Path.Combine(AppSettings.Instance.RecordFileDirectory, _currentFileName); _waveWriter = new WaveFileWriter(fileName, _fileWaveFormat); } _endTicks = dt.Ticks + RecordingKickTimeTicks; }
public void ProcessSamples(bool bHasAudio, byte[] samples) { if (samples == null || samples.Length <= 0) return; if (bHasAudio) { KickRecording(AudioKickState.Kick); } if (_recordingEnabled && _waveWriter != null) { if (_useResampler) { Buffer.BlockCopy(samples, 0, _resampleStream.SourceBuffer, 0, samples.Length); int sourceBytesConverted = 0; int convertedBytes = _resampleStream.Convert(samples.Length, out sourceBytesConverted); if (sourceBytesConverted == samples.Length) { byte[] convBytes = new byte[convertedBytes]; Buffer.BlockCopy(_resampleStream.DestBuffer, 0, convBytes, 0, convertedBytes); _waveWriter.Write(convBytes, 0, convBytes.Length); } } else { _waveWriter.Write(samples, 0, samples.Length); } } long curTicks = DateTime.Now.Ticks; if (_currentKickState == AudioKickState.On) { if (_forceOnEndTicks == 0 || _forceOnEndTicks < curTicks) { _forceOnEndTicks = 0; _endTicks = curTicks + RecordingKickTimeTicks; _currentKickState = AudioKickState.Kick; } } else if (!_recordingEnabled || (_endTicks == 0) || (_currentKickState == AudioKickState.Kick && _endTicks < DateTime.Now.Ticks)) { EndRecording(); } }