mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
Volume!!
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const VolumeInterface = require('./util/VolumeInterface');
|
||||
class VolumeInterface {}
|
||||
const OpusEncoders = require('./opus/OpusEngineList');
|
||||
const Collection = require('../../util/Collection');
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const { VoiceStatus } = require('../../../util/Constants');
|
||||
const VolumeInterface = require('../util/VolumeInterface');
|
||||
const { Writable } = require('stream');
|
||||
|
||||
const secretbox = require('../util/Secretbox');
|
||||
@@ -159,6 +160,18 @@ class StreamDispatcher extends Writable {
|
||||
*/
|
||||
this.emit('speaking', value);
|
||||
}
|
||||
|
||||
get volume() {
|
||||
return this.player.streams.volume ? this.player.streams.volume.volume : 1;
|
||||
}
|
||||
|
||||
setVolume(value) {
|
||||
if (!this.player.streams.volume) return false;
|
||||
this.player.streams.volume.setVolume(value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
VolumeInterface.applyToClass(StreamDispatcher);
|
||||
|
||||
module.exports = StreamDispatcher;
|
||||
|
||||
@@ -69,8 +69,9 @@ class AudioPlayer extends EventEmitter {
|
||||
|
||||
playPCMStream(stream, options = {}) {
|
||||
this.destroyDispatcher();
|
||||
const volume = this.streams.volume = new prism.VolumeTransformer16LE(null, { volume: 0.2 });
|
||||
const opus = this.streams.opus = new prism.opus.Encoder({ channels: 2, rate: 48000, frameSize: 960 });
|
||||
stream.pipe(opus);
|
||||
stream.pipe(volume).pipe(opus);
|
||||
return this.playOpusStream(opus, options);
|
||||
}
|
||||
|
||||
@@ -85,7 +86,6 @@ class AudioPlayer extends EventEmitter {
|
||||
this.destroyDispatcher();
|
||||
const options = { seek, volume, passes };
|
||||
const dispatcher = new StreamDispatcher(this, options);
|
||||
this.streamingData.count = 0;
|
||||
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class VolumeInterface extends EventEmitter {
|
||||
* @type {number}
|
||||
*/
|
||||
get volumeDecibels() {
|
||||
return Math.log10(this._volume) * 20;
|
||||
return Math.log10(this.volume) * 20;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,7 +34,7 @@ class VolumeInterface extends EventEmitter {
|
||||
* @type {number}
|
||||
*/
|
||||
get volumeLogarithmic() {
|
||||
return Math.pow(this._volume, 1 / 1.660964);
|
||||
return Math.pow(this.volume, 1 / 1.660964);
|
||||
}
|
||||
|
||||
applyVolume(buffer, volume) {
|
||||
@@ -83,4 +83,19 @@ class VolumeInterface extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VolumeInterface;
|
||||
const props = [
|
||||
'volumeDecibels',
|
||||
'volumeLogarithmic',
|
||||
'setVolumeDecibels',
|
||||
'setVolumeLogarithmic',
|
||||
];
|
||||
|
||||
exports.applyToClass = function applyToClass(structure) {
|
||||
for (const prop of props) {
|
||||
Object.defineProperty(
|
||||
structure.prototype,
|
||||
prop,
|
||||
Object.getOwnPropertyDescriptor(VolumeInterface.prototype, prop)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user