public VoiceWebSocket(DiscordWSClient client)
			: base(client)
		{
			_rand = new Random();
			_decoders = new ConcurrentDictionary<uint, OpusDecoder>();
			_targetAudioBufferLength = client.Config.VoiceBufferLength / 20; //20 ms frames
			_encodingBuffer = new byte[MaxOpusSize];
			_ssrcMapping = new ConcurrentDictionary<uint, string>();
			_encoder = new OpusEncoder(48000, 1, 20, Opus.Application.Audio);
			_sendBuffer = new VoiceBuffer((int)Math.Ceiling(client.Config.VoiceBufferLength / (double)_encoder.FrameLength), _encoder.FrameSize);
        }
Example #2
0
        internal OpusEncodeStream(IAudioTarget target, byte[] secretKey, int channels, int samplesPerFrame, uint ssrc, int?bitrate = null)
            : base(target, secretKey, samplesPerFrame, ssrc)
        {
            _encoder            = new OpusEncoder(SampleRate, channels);
            _frameSize          = samplesPerFrame * channels * 2;
            _partialFrameBuffer = new byte[_frameSize];

            _encoder.SetForwardErrorCorrection(true);
            if (bitrate != null)
            {
                _encoder.SetBitrate(bitrate.Value);
            }
        }
Example #3
0
		public VoiceWebSocket(DiscordSimpleClient client)
			: base(client)
		{
			_rand = new Random();
			_decoders = new ConcurrentDictionary<uint, OpusDecoder>();
			_sendQueue = new ConcurrentQueue<byte[]>();
			_sendQueueWait = new ManualResetEventSlim(true);
			_sendQueueEmptyWait = new ManualResetEventSlim(true);
			_targetAudioBufferLength = client.Config.VoiceBufferLength / 20; //20 ms frames
			_encodingBuffer = new byte[MaxOpusSize];
			_ssrcMapping = new ConcurrentDictionary<uint, string>();
			_encoder = new OpusEncoder(48000, 1, 20, Opus.Application.Audio);
        }