Audio bitrate support (#1439)

* Audio bitrate support

Note: not implemented for VoiceBroadcasts

* Fix default args, auto bitrate

* Late night typos are the best

* Changes bitrate to kbps for VoiceChannel stuff

* Add methods to manipulate bitrate while encoding
This commit is contained in:
aemino
2017-07-26 01:06:40 -07:00
committed by Crawl
parent 7eb9e65c41
commit 4342ed29a8
9 changed files with 97 additions and 58 deletions

View File

@@ -4,21 +4,38 @@
*/
class BaseOpus {
/**
* @param {Object} [options] The options to apply to the Opus engine
* @param {boolean} [options.fec] Whether to enable forward error correction (defaults to false)
* @param {number} [options.plp] The expected packet loss percentage (0-1 inclusive, defaults to 0)
* @param {Object} [options] The options to apply to the Opus engine.
* @param {number} [options.bitrate=48] The desired bitrate (kbps).
* @param {boolean} [options.fec=false] Whether to enable forward error correction.
* @param {number} [options.plp=0] The expected packet loss percentage.
*/
constructor(options = {}) {
constructor({ bitrate = 48, fec = false, plp = 0 } = {}) {
this.ctl = {
BITRATE: 4002,
FEC: 4012,
PLP: 4014,
};
this.options = options;
this.samplingRate = 48000;
this.channels = 2;
/**
* The desired bitrate (kbps)
* @type {number}
*/
this.bitrate = bitrate;
/**
* Miscellaneous Opus options
* @type {Object}
*/
this.options = { fec, plp };
}
init() {
try {
this.setBitrate(this.bitrate);
// Set FEC (forward error correction)
if (this.options.fec) this.setFEC(this.options.fec);