コード例 #1
0
        public bool Read(ArraySegment <float> frame)
        {
            EncodedAudio?encoded;
            var          lastFrame = _buffer.Read(out encoded);

            int decodedCount;

            if (encoded != null)
            {
                Log.Trace("Decoding frame {0}", encoded.Value.Sequence);
                decodedCount = _decoder.Decode(encoded.Value.Data, frame);
                _recycleFrame(encoded.Value);
            }
            else
            {
                Log.Trace("Running decoder PLC");
                decodedCount = _decoder.Decode(null, frame);
            }

            //Sanity check that decoding got correct number of samples
            if (decodedCount != _frameSize)
            {
                throw new InvalidOperationException(string.Format("Decoding a frame of audio got {0} samples, but should have decoded {1} samples", decodedCount, _frameSize));
            }

            if (_diagnosticOutput != null)
            {
                _diagnosticOutput.WriteSamples(frame);
            }

            return(lastFrame);
        }
コード例 #2
0
        public bool Read(ArraySegment <float> frame)
        {
            VoicePacket?encoded;
            var         lastFrame = _buffer.Read(out encoded);

            int decodedCount;

            if (encoded != null)
            {
                Log.Trace("Decoding frame {0}", encoded.Value.SequenceNumber);
                decodedCount = _decoder.Decode(encoded.Value.EncodedAudioFrame, frame);

                //Expose the playback options for this packet
                using (var l = _options.Lock())
                    l.Value = encoded.Value.PlaybackOptions;

                //Expose the channel list for this packet (if it's null just assume the previous value is still correct)
                if (encoded.Value.Channels != null)
                {
                    using (var l = _channels.Lock())
                    {
                        _approxChannelCount = encoded.Value.Channels.Count;
                        l.Value.Clear();
                        l.Value.AddRange(encoded.Value.Channels);
                    }
                }

                _recycleFrame(encoded.Value);
            }
            else
            {
                Log.Trace("Running decoder PLC");
                decodedCount = _decoder.Decode(null, frame);
            }

            //Sanity check that decoding got correct number of samples
            if (decodedCount != _frameSize)
            {
                throw new InvalidOperationException(string.Format("Decoding a frame of audio got {0} samples, but should have decoded {1} samples", decodedCount, _frameSize));
            }

            if (_diagnosticOutput != null)
            {
                _diagnosticOutput.WriteSamples(frame);
            }

            return(lastFrame);
        }
コード例 #3
0
        public bool Read(ArraySegment <float> frame)
        {
            VoicePacket?encoded;
            var         lastFrame = _buffer.Read(out encoded);

            int decodedCount;

            if (encoded != null)
            {
                Log.Trace("Decoding frame {0}", encoded.Value.SequenceNumber);
                decodedCount = _decoder.Decode(encoded.Value.EncodedAudioFrame, frame);

                //Expose the playback options for this packet
                using (var l = _options.Lock())
                    l.Value = encoded.Value.PlaybackOptions;

                //Read the channel data into a separate list
                ExtractChannels(encoded.Value);

                _recycleFrame(encoded.Value);
            }
            else
            {
                Log.Trace("Running decoder PLC");
                decodedCount = _decoder.Decode(null, frame);
            }

            //Sanity check that decoding got correct number of samples
            if (decodedCount != _frameSize)
            {
                throw new InvalidOperationException(string.Format("Decoding a frame of audio got {0} samples, but should have decoded {1} samples", decodedCount, _frameSize));
            }

            if (_diagnosticOutput != null)
            {
                _diagnosticOutput.WriteSamples(frame);
            }

            return(lastFrame);
        }
コード例 #4
0
        public bool Read(ArraySegment <float> frame)
        {
            VoicePacket?encoded;
            bool        peekLostPacket;
            var         lastFrame = _buffer.Read(out encoded, out peekLostPacket);

            var p = new EncodedBuffer(encoded.HasValue ? encoded.Value.EncodedAudioFrame : (ArraySegment <byte>?)null, peekLostPacket || !encoded.HasValue);

            //Decode the frame
            int decodedCount = _decoder.Decode(p, frame);

            //If it was not a lost frame, also decode the metadata
            if (!p.PacketLost && encoded.HasValue)
            {
                //Expose the playback options for this packet
                using (var l = _options.Lock())
                    l.Value = encoded.Value.PlaybackOptions;

                //Read the channel data into a separate list
                ExtractChannels(encoded.Value);

                //Recycle the frame for re-use with a future packet. Only done with frames which were not peek ahead frames
                _recycleFrame(encoded.Value);
            }

            //Sanity check that decoding got correct number of samples
            if (decodedCount != _frameSize)
            {
                throw new InvalidOperationException(string.Format("Decoding a frame of audio got {0} samples, but should have decoded {1} samples", decodedCount, _frameSize));
            }

            if (_diagnosticOutput != null)
            {
                _diagnosticOutput.WriteSamples(frame);
            }

            return(lastFrame);
        }