/// <summary> /// Read as many frames as possible from the mic sample buffer and pass them to the encoding thread /// </summary> private void SendFrame() { //Drain as many frames as possible while (_rawMicSamples.Count > _rawMicFrames.FrameSize) { //Try to get a frame var segment = new ArraySegment <float>(_frame); var available = _rawMicFrames.Read(segment); if (!available) { break; } //Create diagnostic writer (if necessary) if (DebugSettings.Instance.EnableRecordingDiagnostics && DebugSettings.Instance.RecordMicrophoneRawAudio) { if (_microphoneDiagnosticOutput == null) { var filename = string.Format("Dissonance_Diagnostics/MicrophoneRawAudio_{0}", DateTime.UtcNow.ToFileTime()); _microphoneDiagnosticOutput = new AudioFileWriter(filename, _format); } } else if (_microphoneDiagnosticOutput != null) { _microphoneDiagnosticOutput.Dispose(); _microphoneDiagnosticOutput = null; } //Write out the diagnostic info if (_microphoneDiagnosticOutput != null) { _microphoneDiagnosticOutput.WriteSamples(segment); _microphoneDiagnosticOutput.Flush(); } //Send frame to subscribers for (var i = 0; i < _subscribers.Count; i++) { _subscribers[i].ReceiveMicrophoneData(segment, _format); } } }
/// <summary> /// Read as many frames as possible from the mic sample buffer and pass them to the encoding thread /// </summary> private void SendFrame() { while (_rawMicSamples.Count > _preprocessing.InputFrameSize) { //Get an empty buffer from the pool of buffers (sent back from the audio processing thread) var frameBuffer = _preprocessing.GetFrameBuffer(); //Read a complete frame _rawMicFrames.Read(new ArraySegment <float>(frameBuffer)); //Create diagnostic writer (if necessary) if (DebugSettings.Instance.EnableRecordingDiagnostics && DebugSettings.Instance.RecordMicrophoneRawAudio) { if (_microphoneDiagnosticOutput == null) { var filename = string.Format("Dissonance_Diagnostics/MicrophoneRawAudio_{0}", DateTime.UtcNow.ToFileTime()); _microphoneDiagnosticOutput = new AudioFileWriter(filename, _rawMicSamples.WaveFormat); } } else if (_microphoneDiagnosticOutput != null) { _microphoneDiagnosticOutput.Dispose(); _microphoneDiagnosticOutput = null; } //Write out the diagnostic info if (_microphoneDiagnosticOutput != null) { _microphoneDiagnosticOutput.WriteSamples(new ArraySegment <float>(frameBuffer)); _microphoneDiagnosticOutput.Flush(); } //Send the full buffer to the audio thread for processing (no copying, just pass the entire buffer across by ref) _preprocessing.Send(frameBuffer); } }