UNPKG

detritus-client

Version:

A Typescript NodeJS library to interact with Discord's API, both Rest and Gateway.

63 lines (62 loc) 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AudioFormat = exports.ValidEndianness = void 0; exports.ValidEndianness = Object.freeze({ BE: 'BE', LE: 'LE', }); class AudioFormat { constructor(options = {}) { this.bitDepth = 16; this.channels = 2; this.endianness = exports.ValidEndianness.LE; this.frameDuration = 20; this.sampleRate = 48000; if (options.bitDepth !== undefined) { this.bitDepth = +options.bitDepth; } if (options.channels !== undefined) { this.channels = +options.channels; } if (options.endianness !== undefined) { this.endianness = options.endianness; } if (options.frameDuration !== undefined) { this.frameDuration = +options.frameDuration; } if (options.sampleRate !== undefined) { this.sampleRate = +options.sampleRate; } } get byteDepth() { return Math.round(this.bitDepth / 8); } get frameSize() { return this.samplesPerFrame * this.sampleSize; } get samplesPerFrame() { return Math.round((this.sampleRate / 1000) * this.frameDuration); } get samplesPerTick() { return Math.round((this.sampleRate / 1000) * this.byteDepth); } get sampleSize() { return this.byteDepth * this.channels; } get pcmMult() { return Math.pow(2, this.bitDepth) / 2; } get pcmMax() { return this.pcmMult - 1; } get pcmMin() { return -this.pcmMax; } get readFunc() { return `readInt${this.bitDepth}${this.endianness}`; } get writeFunc() { return `writeInt${this.bitDepth}${this.endianness}`; } } exports.AudioFormat = AudioFormat;