audio filters
This commit is contained in:
parent
2bb209baf5
commit
df731445fd
4 changed files with 43 additions and 14 deletions
|
@ -19,9 +19,9 @@ class Queue<T = unknown> {
|
||||||
public playing = false;
|
public playing = false;
|
||||||
public metadata?: T = null;
|
public metadata?: T = null;
|
||||||
public repeatMode: QueueRepeatMode = 0;
|
public repeatMode: QueueRepeatMode = 0;
|
||||||
public _streamTime: number = 0;
|
private _streamTime: number = 0;
|
||||||
public _cooldownsTimeout = new Collection<string, NodeJS.Timeout>();
|
public _cooldownsTimeout = new Collection<string, NodeJS.Timeout>();
|
||||||
private _activeFilters: any = {};
|
private _activeFilters: any[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue constructor
|
* Queue constructor
|
||||||
|
@ -61,7 +61,7 @@ class Queue<T = unknown> {
|
||||||
useSafeSearch: false,
|
useSafeSearch: false,
|
||||||
disableAutoRegister: false,
|
disableAutoRegister: false,
|
||||||
fetchBeforeQueued: false,
|
fetchBeforeQueued: false,
|
||||||
initialVolume: 50
|
initialVolume: 100
|
||||||
} as PlayerOptions,
|
} as PlayerOptions,
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
|
@ -205,11 +205,34 @@ class Queue<T = unknown> {
|
||||||
|
|
||||||
get streamTime() {
|
get streamTime() {
|
||||||
if (!this.connection) return 0;
|
if (!this.connection) return 0;
|
||||||
return this._streamTime + this.connection.streamTime;
|
const playbackTime = this._streamTime + this.connection.streamTime;
|
||||||
|
const NC = this._activeFilters.includes("nightcore") ? 1.25 : null;
|
||||||
|
const VW = this._activeFilters.includes("vaporwave") ? 0.8 : null;
|
||||||
|
|
||||||
|
if (NC && VW) return playbackTime * (NC + VW);
|
||||||
|
return NC ? playbackTime * NC : VW ? playbackTime * VW : playbackTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
async setFilters(filters: QueueFilters) {
|
getFiltersEnabled() {
|
||||||
if (!Object.keys(filters).length) return;
|
return AudioFilters.names.filter((x) => this._activeFilters.includes(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
getFiltersDisabled() {
|
||||||
|
return AudioFilters.names.filter((x) => !this._activeFilters.includes(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
async setFilters(filters?: QueueFilters) {
|
||||||
|
if (!filters || !Object.keys(filters).length) {
|
||||||
|
// reset filters
|
||||||
|
const streamTime = this.streamTime;
|
||||||
|
this._activeFilters = [];
|
||||||
|
return await this.play(this.current, {
|
||||||
|
immediate: true,
|
||||||
|
filtersUpdate: true,
|
||||||
|
seek: streamTime,
|
||||||
|
encoderArgs: []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const _filters: any[] = [];
|
const _filters: any[] = [];
|
||||||
|
|
||||||
|
@ -217,12 +240,16 @@ class Queue<T = unknown> {
|
||||||
if (filters[filter as keyof QueueFilters] === true) _filters.push(filter);
|
if (filters[filter as keyof QueueFilters] === true) _filters.push(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._activeFilters.join("") === _filters.join("")) return;
|
||||||
|
|
||||||
const newFilters = AudioFilters.create(_filters);
|
const newFilters = AudioFilters.create(_filters);
|
||||||
|
const streamTime = this.streamTime;
|
||||||
|
this._activeFilters = _filters;
|
||||||
|
|
||||||
return await this.play(this.current, {
|
return await this.play(this.current, {
|
||||||
immediate: true,
|
immediate: true,
|
||||||
filtersUpdate: true,
|
filtersUpdate: true,
|
||||||
seek: this.streamTime,
|
seek: streamTime,
|
||||||
encoderArgs: ["-af", newFilters]
|
encoderArgs: ["-af", newFilters]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -266,8 +293,8 @@ class Queue<T = unknown> {
|
||||||
// discord-ytdl-core
|
// discord-ytdl-core
|
||||||
opusEncoded: false,
|
opusEncoded: false,
|
||||||
fmt: "s16le",
|
fmt: "s16le",
|
||||||
encoderArgs: options.encoderArgs ?? [],
|
encoderArgs: options.encoderArgs ?? this._activeFilters.length ? ["-af", AudioFilters.create(this._activeFilters)] : [],
|
||||||
seek: options.seek
|
seek: options.seek ? options.seek / 1000 : 0
|
||||||
}).on("error", (err) => (err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err)));
|
}).on("error", (err) => (err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err)));
|
||||||
} else {
|
} else {
|
||||||
stream = ytdl
|
stream = ytdl
|
||||||
|
@ -276,8 +303,8 @@ class Queue<T = unknown> {
|
||||||
{
|
{
|
||||||
opusEncoded: false,
|
opusEncoded: false,
|
||||||
fmt: "s16le",
|
fmt: "s16le",
|
||||||
encoderArgs: options.encoderArgs ?? [],
|
encoderArgs: options.encoderArgs ?? this._activeFilters.length ? ["-af", AudioFilters.create(this._activeFilters)] : [],
|
||||||
seek: options.seek
|
seek: options.seek ? options.seek / 1000 : 0
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.on("error", (err) => (err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err)));
|
.on("error", (err) => (err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err)));
|
||||||
|
@ -291,7 +318,7 @@ class Queue<T = unknown> {
|
||||||
if (options.seek) this._streamTime = options.seek;
|
if (options.seek) this._streamTime = options.seek;
|
||||||
|
|
||||||
const dispatcher = await this.connection.playStream(resource);
|
const dispatcher = await this.connection.playStream(resource);
|
||||||
dispatcher.setVolume(options.encoderArgs && options.encoderArgs[1]?.includes("bass=g") ? this.options.initialVolume + 35 : this.options.initialVolume);
|
dispatcher.setVolume(this.options.initialVolume);
|
||||||
|
|
||||||
// need to use these events here
|
// need to use these events here
|
||||||
dispatcher.once("start", () => {
|
dispatcher.once("start", () => {
|
||||||
|
|
|
@ -160,7 +160,7 @@ class BasicStreamDispatcher extends EventEmitter<VoiceEvents> {
|
||||||
|
|
||||||
get streamTime() {
|
get streamTime() {
|
||||||
if (!this.audioResource) return 0;
|
if (!this.audioResource) return 0;
|
||||||
return Math.floor(this.audioResource.playbackDuration / 1000);
|
return this.audioResource.playbackDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
get paused() {
|
get paused() {
|
||||||
|
|
|
@ -19,6 +19,7 @@ export type QueueFilters = {
|
||||||
reverse?: boolean;
|
reverse?: boolean;
|
||||||
treble?: boolean;
|
treble?: boolean;
|
||||||
normalizer?: boolean;
|
normalizer?: boolean;
|
||||||
|
normalizer2?: boolean;
|
||||||
surrounding?: boolean;
|
surrounding?: boolean;
|
||||||
pulsator?: boolean;
|
pulsator?: boolean;
|
||||||
subboost?: boolean;
|
subboost?: boolean;
|
||||||
|
|
|
@ -34,7 +34,7 @@ import { FiltersName } from "../types/types";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const FilterList = {
|
const FilterList = {
|
||||||
bassboost: "bass=g=20",
|
bassboost: "bass=g=20:f=110:w=0.3",
|
||||||
"8D": "apulsator=hz=0.09",
|
"8D": "apulsator=hz=0.09",
|
||||||
vaporwave: "aresample=48000,asetrate=48000*0.8",
|
vaporwave: "aresample=48000,asetrate=48000*0.8",
|
||||||
nightcore: "aresample=48000,asetrate=48000*1.25",
|
nightcore: "aresample=48000,asetrate=48000*1.25",
|
||||||
|
@ -44,6 +44,7 @@ const FilterList = {
|
||||||
reverse: "areverse",
|
reverse: "areverse",
|
||||||
treble: "treble=g=5",
|
treble: "treble=g=5",
|
||||||
normalizer: "dynaudnorm=g=101",
|
normalizer: "dynaudnorm=g=101",
|
||||||
|
normalizer2: "acompressor",
|
||||||
surrounding: "surround",
|
surrounding: "surround",
|
||||||
pulsator: "apulsator=hz=1",
|
pulsator: "apulsator=hz=1",
|
||||||
subboost: "asubboost",
|
subboost: "asubboost",
|
||||||
|
|
Loading…
Reference in a new issue