diff --git a/src/Discord.Net/Audio/Opus/OpusDecoder.cs b/src/Discord.Net/Audio/Opus/OpusDecoder.cs
index e3a3fa649..ea9376f82 100644
--- a/src/Discord.Net/Audio/Opus/OpusDecoder.cs
+++ b/src/Discord.Net/Audio/Opus/OpusDecoder.cs
@@ -18,7 +18,7 @@ namespace Discord.Audio
OpusError error;
_ptr = CreateDecoder(samplingRate, channels, out error);
if (error != OpusError.OK)
- throw new InvalidOperationException($"Error occured while creating decoder: {error}");
+ throw new Exception($"Opus Error: {error}");
}
/// Produces PCM samples from Opus-encoded audio.
@@ -33,7 +33,7 @@ namespace Discord.Audio
result = Decode(_ptr, inPtr + inputOffset, inputCount, outPtr + outputOffset, (output.Length - outputOffset) / SampleSize / MaxChannels, 0);
if (result < 0)
- throw new Exception(((OpusError)result).ToString());
+ throw new Exception($"Opus Error: {(OpusError)result}");
return result;
}
diff --git a/src/Discord.Net/Audio/Opus/OpusEncoder.cs b/src/Discord.Net/Audio/Opus/OpusEncoder.cs
index 145447194..447613d1c 100644
--- a/src/Discord.Net/Audio/Opus/OpusEncoder.cs
+++ b/src/Discord.Net/Audio/Opus/OpusEncoder.cs
@@ -25,13 +25,12 @@ namespace Discord.Audio
OpusError error;
_ptr = CreateEncoder(samplingRate, channels, (int)application, out error);
if (error != OpusError.OK)
- throw new InvalidOperationException($"Error occured while creating encoder: {error}");
+ throw new Exception($"Opus Error: {error}");
}
/// Produces Opus encoded audio from PCM samples.
/// PCM samples to encode.
- /// Offset of the frame in pcmSamples.
/// Buffer to store the encoded frame.
/// Length of the frame contained in outputBuffer.
public unsafe int EncodeFrame(byte[] input, int inputOffset, int inputCount, byte[] output, int outputOffset)
@@ -42,7 +41,7 @@ namespace Discord.Audio
result = Encode(_ptr, inPtr + inputOffset, inputCount / SampleSize, outPtr + outputOffset, output.Length - outputOffset);
if (result < 0)
- throw new Exception(((OpusError)result).ToString());
+ throw new Exception($"Opus Error: {(OpusError)result}");
return result;
}
@@ -51,7 +50,7 @@ namespace Discord.Audio
{
var result = EncoderCtl(_ptr, OpusCtl.SetInbandFECRequest, value ? 1 : 0);
if (result < 0)
- throw new Exception(((OpusError)result).ToString());
+ throw new Exception($"Opus Error: {(OpusError)result}");
}
/// Gets or sets whether Forward Error Correction is enabled.
@@ -62,7 +61,7 @@ namespace Discord.Audio
var result = EncoderCtl(_ptr, OpusCtl.SetBitrateRequest, value * 1000);
if (result < 0)
- throw new Exception(((OpusError)result).ToString());
+ throw new Exception($"Opus Error: {(OpusError)result}");
}
protected override void Dispose(bool disposing)
diff --git a/src/Discord.Net/Audio/Sodium/SecretBox.cs b/src/Discord.Net/Audio/Sodium/SecretBox.cs
index ba4bc2e62..4187c9f08 100644
--- a/src/Discord.Net/Audio/Sodium/SecretBox.cs
+++ b/src/Discord.Net/Audio/Sodium/SecretBox.cs
@@ -1,4 +1,5 @@
-using System.Runtime.InteropServices;
+using System;
+using System.Runtime.InteropServices;
namespace Discord.Audio
{
@@ -9,17 +10,27 @@ namespace Discord.Audio
[DllImport("libsodium", EntryPoint = "crypto_secretbox_open_easy", CallingConvention = CallingConvention.Cdecl)]
private static extern int SecretBoxOpenEasy(byte* output, byte* input, long inputLength, byte[] nonce, byte[] secret);
- public static int Encrypt(byte[] input, int inputOffset, long inputLength, byte[] output, int outputOffset, byte[] nonce, byte[] secret)
+ public static int Encrypt(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, byte[] nonce, byte[] secret)
{
fixed (byte* inPtr = input)
fixed (byte* outPtr = output)
- return SecretBoxEasy(outPtr + outputOffset, inPtr + inputOffset, inputLength, nonce, secret);
+ {
+ int error = SecretBoxEasy(outPtr + outputOffset, inPtr + inputOffset, inputLength, nonce, secret);
+ if (error != 0)
+ throw new Exception($"Sodium Error: {error}");
+ return inputLength + 16;
+ }
}
- public static int Decrypt(byte[] input, int inputOffset, long inputLength, byte[] output, int outputOffset, byte[] nonce, byte[] secret)
+ public static int Decrypt(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, byte[] nonce, byte[] secret)
{
fixed (byte* inPtr = input)
fixed (byte* outPtr = output)
- return SecretBoxOpenEasy(outPtr + outputOffset, inPtr + inputOffset, inputLength, nonce, secret);
+ {
+ int error = SecretBoxOpenEasy(outPtr + outputOffset, inPtr + inputOffset, inputLength, nonce, secret);
+ if (error != 0)
+ throw new Exception($"Sodium Error: {error}");
+ return inputLength - 16;
+ }
}
}
}