Skip to content

Instantly share code, notes, and snippets.

@darichey
Created December 16, 2018 19:33
Show Gist options
  • Save darichey/2187330edc19bccbdc39a271921c4b95 to your computer and use it in GitHub Desktop.
Save darichey/2187330edc19bccbdc39a271921c4b95 to your computer and use it in GitHub Desktop.
Audio Notes
0 1 2 3
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 2 3 4 5 6 7 0 1 2 3 4 5 6 7
+---+-+-+-------+---------------+-----------------------------+
|V |P|X| CSRC |M|Payload type | Sequence |
+---+-+-+-------+---------------+-----------------------------+
| Timestamp |
+-------------------------------------------------------------+
| SSRC |
+-------------------------------------------------------------+
| Audio Data ... |
+-------------------------------------------------------------+
V (Version): 2 bits
RTP version.
Always 2 (10) for Discord.
P (Padding): 1 bit
Whether padding is used in data.
Always 0 for Discord.
X (Extensions): 1 bit
Whether RTP extensions are used.
Always 0 for Discord.
CSRC: 4 bits
Number of combined audio streams.
Discord does not combine audio streams. Always 0.
M (Marker): 1 bit
Custom use for applications.
Unused by Discord. Always 0.
Payload type: 7 bits
Defines the RTP payload profile.
Discord uses 8 (001000).
Sequence: 2 bytes
Incremented for each RTP packet sent. Used to detect packet loss.
Timestamp: 4 bytes
Used by the receiver to play back the received samples at appropriate time and interval.
Discord expects a sample rate of 48kHz, and a frame size of 20 milliseconds. Therefore, the timestamp is incremented by 960 for every packet sent.
(48000Hz) / (1s / 20ms) = 960
SSRC: 4 bytes
Uniquely identifies the source of a stream.
Each user is a source so they each have a unique SSRC.
Audio Data: 1920 bytes
Opus-encoded audio data encrypted according to the set encryption mode.
960 * 2 channels = 1920
== Notes ==
First byte consiting of V,P,X,CSRC is always 0x80
Second byte consiting of M,PT is always 0x78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment