From 65154e0d4a61a4e7e2b1a32580d6737dfb4b1900 Mon Sep 17 00:00:00 2001 From: RogueException Date: Fri, 7 Apr 2017 21:28:03 -0300 Subject: [PATCH] Enable FEC decoding --- src/Discord.Net.WebSocket/Audio/Opus/OpusConverter.cs | 2 +- src/Discord.Net.WebSocket/Audio/Opus/OpusDecoder.cs | 4 ++-- src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.WebSocket/Audio/Opus/OpusConverter.cs b/src/Discord.Net.WebSocket/Audio/Opus/OpusConverter.cs index 732006990..95874cdf1 100644 --- a/src/Discord.Net.WebSocket/Audio/Opus/OpusConverter.cs +++ b/src/Discord.Net.WebSocket/Audio/Opus/OpusConverter.cs @@ -7,7 +7,7 @@ namespace Discord.Audio protected IntPtr _ptr; /// Gets the bit rate of this converter. - public const int BitsPerSample = 16; + public const int BitsPerSample = sizeof(short) * 8; /// Gets the bytes per sample. public const int SampleSize = (BitsPerSample / 8) * MaxChannels; /// Gets the maximum amount of channels this encoder supports. diff --git a/src/Discord.Net.WebSocket/Audio/Opus/OpusDecoder.cs b/src/Discord.Net.WebSocket/Audio/Opus/OpusDecoder.cs index c3e90789d..a8c05d781 100644 --- a/src/Discord.Net.WebSocket/Audio/Opus/OpusDecoder.cs +++ b/src/Discord.Net.WebSocket/Audio/Opus/OpusDecoder.cs @@ -32,11 +32,11 @@ namespace Discord.Audio int result = 0; fixed (byte* inPtr = input) fixed (byte* outPtr = output) - result = Decode(_ptr, inPtr + inputOffset, inputCount, outPtr + outputOffset, (output.Length - outputOffset) / SampleSize, 0); //TODO: Enable FEC + result = Decode(_ptr, inPtr + inputOffset, inputCount, outPtr + outputOffset, (output.Length - outputOffset) / SampleSize, 1); if (result < 0) throw new Exception($"Opus Error: {(OpusError)result}"); - return result * 4; + return result * SampleSize; } protected override void Dispose(bool disposing) diff --git a/src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs index 6c9d8b233..c46e16cd3 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs @@ -12,7 +12,7 @@ namespace Discord.Audio.Streams private readonly byte[] _buffer; private readonly OpusDecoder _decoder; - public OpusDecodeStream(AudioStream next, int channels = OpusConverter.MaxChannels, int bufferSize = 5760 * 4) + public OpusDecodeStream(AudioStream next, int channels = OpusConverter.MaxChannels, int bufferSize = 5760 * 2 * sizeof(short)) { _next = next; _buffer = new byte[bufferSize];