discord-player 5.3.0-dev.3 → 5.3.2-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Player.js +582 -581
- package/dist/Structures/ExtractorModel.js +65 -65
- package/dist/Structures/PlayerError.js +48 -48
- package/dist/Structures/Playlist.js +108 -108
- package/dist/Structures/Queue.js +785 -769
- package/dist/Structures/Track.js +155 -155
- package/dist/VoiceInterface/StreamDispatcher.js +225 -225
- package/dist/VoiceInterface/VoiceUtils.js +65 -65
- package/dist/VoiceInterface/VolumeTransformer.js +120 -120
- package/dist/index.d.ts +1126 -1122
- package/dist/index.js +33 -33
- package/dist/smoothVolume.js +13 -13
- package/dist/types/types.js +58 -58
- package/dist/utils/AudioFilters.js +97 -98
- package/dist/utils/FFmpegStream.js +53 -53
- package/dist/utils/QueryResolver.js +68 -68
- package/dist/utils/Util.js +135 -133
- package/package.json +22 -16
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// prism's volume transformer with smooth volume support
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.VolumeTransformer = void 0;
|
|
5
|
-
const stream_1 = require("stream");
|
|
6
|
-
class VolumeTransformer extends stream_1.Transform {
|
|
7
|
-
constructor(options = {}) {
|
|
8
|
-
super(options);
|
|
9
|
-
switch (options.type) {
|
|
10
|
-
case "s16le":
|
|
11
|
-
this._readInt = (buffer, index) => buffer.readInt16LE(index);
|
|
12
|
-
this._writeInt = (buffer, int, index) => buffer.writeInt16LE(int, index);
|
|
13
|
-
this._bits = 16;
|
|
14
|
-
break;
|
|
15
|
-
case "s16be":
|
|
16
|
-
this._readInt = (buffer, index) => buffer.readInt16BE(index);
|
|
17
|
-
this._writeInt = (buffer, int, index) => buffer.writeInt16BE(int, index);
|
|
18
|
-
this._bits = 16;
|
|
19
|
-
break;
|
|
20
|
-
case "s32le":
|
|
21
|
-
this._readInt = (buffer, index) => buffer.readInt32LE(index);
|
|
22
|
-
this._writeInt = (buffer, int, index) => buffer.writeInt32LE(int, index);
|
|
23
|
-
this._bits = 32;
|
|
24
|
-
break;
|
|
25
|
-
case "s32be":
|
|
26
|
-
this._readInt = (buffer, index) => buffer.readInt32BE(index);
|
|
27
|
-
this._writeInt = (buffer, int, index) => buffer.writeInt32BE(int, index);
|
|
28
|
-
this._bits = 32;
|
|
29
|
-
break;
|
|
30
|
-
default:
|
|
31
|
-
throw new Error("VolumeTransformer type should be one of s16le, s16be, s32le, s32be");
|
|
32
|
-
}
|
|
33
|
-
this.type = options.type;
|
|
34
|
-
this._bytes = this._bits / 8;
|
|
35
|
-
this._extremum = Math.pow(2, this._bits - 1);
|
|
36
|
-
this.volume = Number.isNaN(options.volume) ? 1 : Number(options.volume);
|
|
37
|
-
if (!Number.isFinite(this.volume))
|
|
38
|
-
this.volume = 1;
|
|
39
|
-
this._targetVolume = this.volume;
|
|
40
|
-
this._chunk = Buffer.alloc(0);
|
|
41
|
-
this._smoothing = options.smoothness || 0;
|
|
42
|
-
}
|
|
43
|
-
_readInt(buffer, index) {
|
|
44
|
-
return index;
|
|
45
|
-
}
|
|
46
|
-
_writeInt(buffer, int, index) {
|
|
47
|
-
return index;
|
|
48
|
-
}
|
|
49
|
-
_applySmoothness() {
|
|
50
|
-
if (this.volume < this._targetVolume) {
|
|
51
|
-
this.volume = this.volume + this._smoothing >= this._targetVolume ? this._targetVolume : this.volume + this._smoothing;
|
|
52
|
-
}
|
|
53
|
-
else if (this.volume > this._targetVolume) {
|
|
54
|
-
this.volume = this.volume - this._smoothing <= this._targetVolume ? this._targetVolume : this.volume - this._smoothing;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
_transform(chunk, encoding, done) {
|
|
58
|
-
if (this.smoothingEnabled() && this.volume !== this._targetVolume)
|
|
59
|
-
this._applySmoothness();
|
|
60
|
-
if (this.volume === 1) {
|
|
61
|
-
this.push(chunk);
|
|
62
|
-
return done();
|
|
63
|
-
}
|
|
64
|
-
const { _bytes, _extremum } = this;
|
|
65
|
-
chunk = this._chunk = Buffer.concat([this._chunk, chunk]);
|
|
66
|
-
if (chunk.length < _bytes)
|
|
67
|
-
return done();
|
|
68
|
-
const complete = Math.floor(chunk.length / _bytes) * _bytes;
|
|
69
|
-
for (let i = 0; i < complete; i += _bytes) {
|
|
70
|
-
const int = Math.min(_extremum - 1, Math.max(-_extremum, Math.floor(this.volume * this._readInt(chunk, i))));
|
|
71
|
-
this._writeInt(chunk, int, i);
|
|
72
|
-
}
|
|
73
|
-
this._chunk = chunk.slice(complete);
|
|
74
|
-
this.push(chunk.slice(0, complete));
|
|
75
|
-
return done();
|
|
76
|
-
}
|
|
77
|
-
_destroy(err, cb) {
|
|
78
|
-
super._destroy(err, cb);
|
|
79
|
-
this._chunk = null;
|
|
80
|
-
}
|
|
81
|
-
setVolume(volume) {
|
|
82
|
-
if (Number.isNaN(volume))
|
|
83
|
-
volume = 1;
|
|
84
|
-
if (typeof volume !== "number")
|
|
85
|
-
volume = Number(volume);
|
|
86
|
-
if (!Number.isFinite(volume))
|
|
87
|
-
volume = volume < 0 ? 0 : 1;
|
|
88
|
-
this._targetVolume = volume;
|
|
89
|
-
if (this._smoothing <= 0)
|
|
90
|
-
this.volume = volume;
|
|
91
|
-
}
|
|
92
|
-
setVolumeDecibels(db) {
|
|
93
|
-
this.setVolume(Math.pow(10, db / 20));
|
|
94
|
-
}
|
|
95
|
-
setVolumeLogarithmic(value) {
|
|
96
|
-
this.setVolume(Math.pow(value, 1.660964));
|
|
97
|
-
}
|
|
98
|
-
get volumeDecibels() {
|
|
99
|
-
return Math.log10(this.volume) * 20;
|
|
100
|
-
}
|
|
101
|
-
get volumeLogarithmic() {
|
|
102
|
-
return Math.pow(this.volume, 1 / 1.660964);
|
|
103
|
-
}
|
|
104
|
-
get smoothness() {
|
|
105
|
-
return this._smoothing;
|
|
106
|
-
}
|
|
107
|
-
setSmoothness(smoothness) {
|
|
108
|
-
this._smoothing = smoothness;
|
|
109
|
-
}
|
|
110
|
-
smoothingEnabled() {
|
|
111
|
-
return Number.isFinite(this._smoothing) && this._smoothing > 0;
|
|
112
|
-
}
|
|
113
|
-
get hasSmoothness() {
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
static get hasSmoothing() {
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.VolumeTransformer = VolumeTransformer;
|
|
1
|
+
"use strict";
|
|
2
|
+
// prism's volume transformer with smooth volume support
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.VolumeTransformer = void 0;
|
|
5
|
+
const stream_1 = require("stream");
|
|
6
|
+
class VolumeTransformer extends stream_1.Transform {
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
super(options);
|
|
9
|
+
switch (options.type) {
|
|
10
|
+
case "s16le":
|
|
11
|
+
this._readInt = (buffer, index) => buffer.readInt16LE(index);
|
|
12
|
+
this._writeInt = (buffer, int, index) => buffer.writeInt16LE(int, index);
|
|
13
|
+
this._bits = 16;
|
|
14
|
+
break;
|
|
15
|
+
case "s16be":
|
|
16
|
+
this._readInt = (buffer, index) => buffer.readInt16BE(index);
|
|
17
|
+
this._writeInt = (buffer, int, index) => buffer.writeInt16BE(int, index);
|
|
18
|
+
this._bits = 16;
|
|
19
|
+
break;
|
|
20
|
+
case "s32le":
|
|
21
|
+
this._readInt = (buffer, index) => buffer.readInt32LE(index);
|
|
22
|
+
this._writeInt = (buffer, int, index) => buffer.writeInt32LE(int, index);
|
|
23
|
+
this._bits = 32;
|
|
24
|
+
break;
|
|
25
|
+
case "s32be":
|
|
26
|
+
this._readInt = (buffer, index) => buffer.readInt32BE(index);
|
|
27
|
+
this._writeInt = (buffer, int, index) => buffer.writeInt32BE(int, index);
|
|
28
|
+
this._bits = 32;
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
throw new Error("VolumeTransformer type should be one of s16le, s16be, s32le, s32be");
|
|
32
|
+
}
|
|
33
|
+
this.type = options.type;
|
|
34
|
+
this._bytes = this._bits / 8;
|
|
35
|
+
this._extremum = Math.pow(2, this._bits - 1);
|
|
36
|
+
this.volume = Number.isNaN(options.volume) ? 1 : Number(options.volume);
|
|
37
|
+
if (!Number.isFinite(this.volume))
|
|
38
|
+
this.volume = 1;
|
|
39
|
+
this._targetVolume = this.volume;
|
|
40
|
+
this._chunk = Buffer.alloc(0);
|
|
41
|
+
this._smoothing = options.smoothness || 0;
|
|
42
|
+
}
|
|
43
|
+
_readInt(buffer, index) {
|
|
44
|
+
return index;
|
|
45
|
+
}
|
|
46
|
+
_writeInt(buffer, int, index) {
|
|
47
|
+
return index;
|
|
48
|
+
}
|
|
49
|
+
_applySmoothness() {
|
|
50
|
+
if (this.volume < this._targetVolume) {
|
|
51
|
+
this.volume = this.volume + this._smoothing >= this._targetVolume ? this._targetVolume : this.volume + this._smoothing;
|
|
52
|
+
}
|
|
53
|
+
else if (this.volume > this._targetVolume) {
|
|
54
|
+
this.volume = this.volume - this._smoothing <= this._targetVolume ? this._targetVolume : this.volume - this._smoothing;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
_transform(chunk, encoding, done) {
|
|
58
|
+
if (this.smoothingEnabled() && this.volume !== this._targetVolume)
|
|
59
|
+
this._applySmoothness();
|
|
60
|
+
if (this.volume === 1) {
|
|
61
|
+
this.push(chunk);
|
|
62
|
+
return done();
|
|
63
|
+
}
|
|
64
|
+
const { _bytes, _extremum } = this;
|
|
65
|
+
chunk = this._chunk = Buffer.concat([this._chunk, chunk]);
|
|
66
|
+
if (chunk.length < _bytes)
|
|
67
|
+
return done();
|
|
68
|
+
const complete = Math.floor(chunk.length / _bytes) * _bytes;
|
|
69
|
+
for (let i = 0; i < complete; i += _bytes) {
|
|
70
|
+
const int = Math.min(_extremum - 1, Math.max(-_extremum, Math.floor(this.volume * this._readInt(chunk, i))));
|
|
71
|
+
this._writeInt(chunk, int, i);
|
|
72
|
+
}
|
|
73
|
+
this._chunk = chunk.slice(complete);
|
|
74
|
+
this.push(chunk.slice(0, complete));
|
|
75
|
+
return done();
|
|
76
|
+
}
|
|
77
|
+
_destroy(err, cb) {
|
|
78
|
+
super._destroy(err, cb);
|
|
79
|
+
this._chunk = null;
|
|
80
|
+
}
|
|
81
|
+
setVolume(volume) {
|
|
82
|
+
if (Number.isNaN(volume))
|
|
83
|
+
volume = 1;
|
|
84
|
+
if (typeof volume !== "number")
|
|
85
|
+
volume = Number(volume);
|
|
86
|
+
if (!Number.isFinite(volume))
|
|
87
|
+
volume = volume < 0 ? 0 : 1;
|
|
88
|
+
this._targetVolume = volume;
|
|
89
|
+
if (this._smoothing <= 0)
|
|
90
|
+
this.volume = volume;
|
|
91
|
+
}
|
|
92
|
+
setVolumeDecibels(db) {
|
|
93
|
+
this.setVolume(Math.pow(10, db / 20));
|
|
94
|
+
}
|
|
95
|
+
setVolumeLogarithmic(value) {
|
|
96
|
+
this.setVolume(Math.pow(value, 1.660964));
|
|
97
|
+
}
|
|
98
|
+
get volumeDecibels() {
|
|
99
|
+
return Math.log10(this.volume) * 20;
|
|
100
|
+
}
|
|
101
|
+
get volumeLogarithmic() {
|
|
102
|
+
return Math.pow(this.volume, 1 / 1.660964);
|
|
103
|
+
}
|
|
104
|
+
get smoothness() {
|
|
105
|
+
return this._smoothing;
|
|
106
|
+
}
|
|
107
|
+
setSmoothness(smoothness) {
|
|
108
|
+
this._smoothing = smoothness;
|
|
109
|
+
}
|
|
110
|
+
smoothingEnabled() {
|
|
111
|
+
return Number.isFinite(this._smoothing) && this._smoothing > 0;
|
|
112
|
+
}
|
|
113
|
+
get hasSmoothness() {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
static get hasSmoothing() {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.VolumeTransformer = VolumeTransformer;
|