-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
212 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
using System; | ||
using System.Buffers; | ||
|
||
namespace DSharpPlus.VoiceLink.AudioCodecs | ||
{ | ||
public delegate IAudioCodec AudioCodecFactory(IServiceProvider serviceProvider); | ||
public interface IAudioCodec | ||
{ | ||
public int GetMaxBufferSize(); | ||
public int Decode(bool hasPacketLoss, ReadOnlySpan<byte> input, Span<byte> output); | ||
public int EncodeOpus(ReadOnlySequence<byte> input, Span<byte> output); | ||
public int DecodeOpus(bool hasPacketLoss, ReadOnlySpan<byte> input, Span<byte> output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,33 @@ | ||
using System; | ||
using System.Buffers; | ||
|
||
namespace DSharpPlus.VoiceLink.AudioCodecs | ||
{ | ||
public class OpusAudioCodec : IAudioCodec | ||
{ | ||
private const int CHANNELS = 2; | ||
private const int MAX_FRAME_SIZE = 5760; | ||
private const int MAX_BUFFER_SIZE = MAX_FRAME_SIZE * 2 * CHANNELS; | ||
public const int CHANNELS = 2; | ||
public const int MAX_FRAME_SIZE = 5760; | ||
public const int MAX_BUFFER_SIZE = MAX_FRAME_SIZE * 2 * CHANNELS; | ||
public static readonly byte[] SilenceFrame = [0xF8, 0xFF, 0xFE]; | ||
|
||
public int GetMaxBufferSize() => MAX_BUFFER_SIZE; | ||
public int Decode(bool hasPacketLoss, ReadOnlySpan<byte> input, Span<byte> output) | ||
public int DecodeOpus(bool hasPacketLoss, ReadOnlySpan<byte> input, Span<byte> output) | ||
{ | ||
if (hasPacketLoss) | ||
{ | ||
SilenceFrame.AsSpan().CopyTo(output); | ||
return SilenceFrame.Length; | ||
} | ||
|
||
input.CopyTo(output); | ||
return input.Length; | ||
} | ||
|
||
public int EncodeOpus(ReadOnlySequence<byte> input, Span<byte> output) | ||
{ | ||
int frameSize = (int)Math.Min(input.Length, MAX_FRAME_SIZE); | ||
input.Slice(0, frameSize).CopyTo(output); | ||
return frameSize; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.