@@ -32,11 +32,11 @@ namespace Discord.Audio | |||||
int result = 0; | int result = 0; | ||||
fixed (byte* inPtr = input) | fixed (byte* inPtr = input) | ||||
fixed (byte* outPtr = output) | fixed (byte* outPtr = output) | ||||
result = Decode(_ptr, inPtr + inputOffset, inputCount, outPtr + outputOffset, (output.Length - outputOffset) / SampleSize / MaxChannels, 0); | |||||
result = Decode(_ptr, inPtr + inputOffset, inputCount, outPtr + outputOffset, (output.Length - outputOffset) / SampleSize, 0); //TODO: Enable FEC | |||||
if (result < 0) | if (result < 0) | ||||
throw new Exception($"Opus Error: {(OpusError)result}"); | throw new Exception($"Opus Error: {(OpusError)result}"); | ||||
return result; | |||||
return result * 4; | |||||
} | } | ||||
protected override void Dispose(bool disposing) | protected override void Dispose(bool disposing) | ||||
@@ -12,7 +12,7 @@ namespace Discord.Audio.Streams | |||||
private readonly byte[] _buffer; | private readonly byte[] _buffer; | ||||
private readonly OpusDecoder _decoder; | private readonly OpusDecoder _decoder; | ||||
public OpusDecodeStream(AudioStream next, int channels = OpusConverter.MaxChannels, int bufferSize = 4000) | |||||
public OpusDecodeStream(AudioStream next, int channels = OpusConverter.MaxChannels, int bufferSize = 5760 * 4) | |||||
{ | { | ||||
_next = next; | _next = next; | ||||
_buffer = new byte[bufferSize]; | _buffer = new byte[bufferSize]; | ||||
@@ -54,7 +54,7 @@ namespace Discord.Audio | |||||
_udp = udpSocketProvider(); | _udp = udpSocketProvider(); | ||||
_udp.ReceivedDatagram += async (data, index, count) => | _udp.ReceivedDatagram += async (data, index, count) => | ||||
{ | { | ||||
if (index != 0) | |||||
if (index != 0 || count != data.Length) | |||||
{ | { | ||||
var newData = new byte[count]; | var newData = new byte[count]; | ||||
Buffer.BlockCopy(data, index, newData, 0, count); | Buffer.BlockCopy(data, index, newData, 0, count); | ||||