Esempio n. 1
0
        private int EncodeFrames([NotNull] IVoiceEncoder encoder, int maxCount)
        {
            var count = 0;

            //Read frames of resampled samples (as many as we can, we want to keep this buffer empty and latency low)
            var encoderInput = new ArraySegment <float>(_plainSamples, 0, encoder.FrameSize);

            while (_output.Read(encoderInput) && count < maxCount)
            {
                //Encode it
                var encoded = encoder.Encode(encoderInput, new ArraySegment <byte>(_encodedBytes));

                //Transmit it
                _net.SendVoice(encoded);
                count++;
            }

            return(count);
        }
Esempio n. 2
0
        private void EncodeFrames()
        {
            //Read frames of resampled samples (as many as we can, we want to keep this buffer empty and latency low)
            var encoderInput = new ArraySegment <float>(_plainSamples, 0, _encoder.FrameSize);

            while (_output.Read(encoderInput))
            {
                if (_preEncodeDiagnosticOutput != null)
                {
                    _preEncodeDiagnosticOutput.WriteSamples(encoderInput);
                }

                //Encode it
                var encoded = _encoder.Encode(encoderInput, new ArraySegment <byte>(_encodedBytes));

                //Transmit it
                _net.SendVoice(encoded);
            }
        }
Esempio n. 3
0
        /// <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);
                }
            }
        }
Esempio n. 4
0
        /// <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);
            }
        }