mirror of
https://github.com/danbulant/discord.js
synced 2026-07-06 11:40:41 +00:00
Volume!!
This commit is contained in:
parent
863e38676f
commit
780e67d19f
4 changed files with 34 additions and 6 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
const VolumeInterface = require('./util/VolumeInterface');
|
class VolumeInterface {}
|
||||||
const OpusEncoders = require('./opus/OpusEngineList');
|
const OpusEncoders = require('./opus/OpusEngineList');
|
||||||
const Collection = require('../../util/Collection');
|
const Collection = require('../../util/Collection');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
const { VoiceStatus } = require('../../../util/Constants');
|
const { VoiceStatus } = require('../../../util/Constants');
|
||||||
|
const VolumeInterface = require('../util/VolumeInterface');
|
||||||
const { Writable } = require('stream');
|
const { Writable } = require('stream');
|
||||||
|
|
||||||
const secretbox = require('../util/Secretbox');
|
const secretbox = require('../util/Secretbox');
|
||||||
|
|
@ -159,6 +160,18 @@ class StreamDispatcher extends Writable {
|
||||||
*/
|
*/
|
||||||
this.emit('speaking', value);
|
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;
|
module.exports = StreamDispatcher;
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,9 @@ class AudioPlayer extends EventEmitter {
|
||||||
|
|
||||||
playPCMStream(stream, options = {}) {
|
playPCMStream(stream, options = {}) {
|
||||||
this.destroyDispatcher();
|
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 });
|
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);
|
return this.playOpusStream(opus, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,7 +86,6 @@ class AudioPlayer extends EventEmitter {
|
||||||
this.destroyDispatcher();
|
this.destroyDispatcher();
|
||||||
const options = { seek, volume, passes };
|
const options = { seek, volume, passes };
|
||||||
const dispatcher = new StreamDispatcher(this, options);
|
const dispatcher = new StreamDispatcher(this, options);
|
||||||
this.streamingData.count = 0;
|
|
||||||
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
|
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
|
||||||
return dispatcher;
|
return dispatcher;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class VolumeInterface extends EventEmitter {
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
get volumeDecibels() {
|
get volumeDecibels() {
|
||||||
return Math.log10(this._volume) * 20;
|
return Math.log10(this.volume) * 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -34,7 +34,7 @@ class VolumeInterface extends EventEmitter {
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
get volumeLogarithmic() {
|
get volumeLogarithmic() {
|
||||||
return Math.pow(this._volume, 1 / 1.660964);
|
return Math.pow(this.volume, 1 / 1.660964);
|
||||||
}
|
}
|
||||||
|
|
||||||
applyVolume(buffer, volume) {
|
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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue