Skip to content

Commit

Permalink
Feat: effect feature is now stable (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtripg6666tdr authored Aug 25, 2022
1 parent e199248 commit ba7594e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Commands/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class Effect extends BaseCommand {
name: "エフェクト",
alias: ["effect", "音声エフェクト", "音声効果", "効果"],
description: "エフェクトコントロールパネルを表示します",
unlist: true,
unlist: false,
category: "player",
});
}
Expand Down
27 changes: 13 additions & 14 deletions src/Component/streams/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { destroyStream } from ".";
import Util from "../../Util";
import { DefaultUserAgent, FFmpegDefaultArgs } from "../../definition";

export function transformThroughFFmpeg(readable:StreamInfo, effectArgs:string, seek:number, output:"ogg"|"pcm"){
export function transformThroughFFmpeg(readable:StreamInfo, effectArgs:string[], seek:number, output:"ogg"|"pcm"){
const ffmpegUserAgentArgs = readable.type === "url" ? [
"-user_agent", readable.userAgent || DefaultUserAgent
] : [];
Expand All @@ -19,19 +19,18 @@ export function transformThroughFFmpeg(readable:StreamInfo, effectArgs:string, s
] : [
"-f", "s16le",
];
const ffmpeg = new FFmpeg({
args: [
...ffmpegUserAgentArgs,
...ffmpegSeekArgs,
"-i", readable.type === "readable" ? "-" : readable.url,
...FFmpegDefaultArgs,
"-vn",
...outputArgs,
"-ar", "48000",
"-ac", "2",
...effectArgs
]
});
const args = [
...ffmpegUserAgentArgs,
...ffmpegSeekArgs,
"-i", readable.type === "readable" ? "-" : readable.url,
...FFmpegDefaultArgs,
"-vn",
...outputArgs,
"-ar", "48000",
"-ac", "2",
...effectArgs,
];
const ffmpeg = new FFmpeg({args});
if(Util.config.debug) ffmpeg.process.stderr.on("data", chunk => Util.logger.log("[FFmpeg]" + chunk.toString(), "debug"));
if(readable.type === "readable"){
readable.stream
Expand Down
10 changes: 5 additions & 5 deletions src/Component/streams/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Refer at: https://github.com/discordjs/discord.js/blob/13baf75cae395353f0528804f
* @returns if volume transform is required, this will return a stream info that represents Ogg/Webm Opus, otherwise return a stream info represents PCM Opus.
*/
export function resolveStreamToPlayable(streamInfo:StreamInfo, effects:string[], seek:number, volumeTransform:boolean):ReadableStreamInfo{
const effectArgs = effects.join(" ");
if((streamInfo.streamType === "webm" || streamInfo.streamType === "ogg") && seek <= 0 && !effectArgs && !volumeTransform){
const effectEnabled = effects.length !== 0;
if((streamInfo.streamType === "webm" || streamInfo.streamType === "ogg") && seek <= 0 && !effectEnabled && !volumeTransform){
// 1. effect is off, volume is off, stream is webm or ogg
// Webm/Ogg --(Demuxer)--> Opus
// 1
Expand All @@ -43,10 +43,10 @@ export function resolveStreamToPlayable(streamInfo:StreamInfo, effects:string[],
Util.logger.log(`[StreamResolver] stream edges: raw(${streamInfo.streamType || "unknown"}) --(FFmpeg)--> Ogg/Opus (cost: 3)`);
return {
type: "readable",
stream: transformThroughFFmpeg(streamInfo, effectArgs, seek, "ogg"),
stream: transformThroughFFmpeg(streamInfo, effects, seek, "ogg"),
streamType: "ogg",
};
}else if((streamInfo.streamType === "webm" || streamInfo.streamType === "ogg") && !effectArgs){
}else if((streamInfo.streamType === "webm" || streamInfo.streamType === "ogg") && !effectEnabled){
// 3. volume is on and stream is webm or ogg
// Webm/Ogg --(Demuxer)--> Opus --(Decoder)--> PCM --(VolumeTransformer)--> PCM --(Encoder)--> Opus
// 1 1.5 0.5 1.5
Expand Down Expand Up @@ -83,7 +83,7 @@ export function resolveStreamToPlayable(streamInfo:StreamInfo, effects:string[],
// 2 0.5 1.5
// Total: 5
Util.logger.log(`[StreamResolver] stream edges: raw(${streamInfo.streamType || "unknown"}) --(FFmpeg) --> PCM (cost: 5)`);
const ffmpegPCM = transformThroughFFmpeg(streamInfo, effectArgs, seek, "pcm");
const ffmpegPCM = transformThroughFFmpeg(streamInfo, effects, seek, "pcm");
const passThrough = InitPassThrough();
ffmpegPCM
.on("error", e => destroyStream(passThrough, e))
Expand Down
2 changes: 1 addition & 1 deletion src/Util/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const EffectsCustomIds = {

export function getFFmpegEffectArgs(data:GuildDataContainer){
const effect = [];
if(data.EffectPrefs.BassBoost) effect.push("firequalizer=gain_entry='entry(80,6)'");
if(data.EffectPrefs.BassBoost) effect.push("firequalizer=gain_entry='entry(75,2)'");
if(data.EffectPrefs.Reverb) effect.push("aecho=1.0:0.7:20:0.5");
if(data.EffectPrefs.LoudnessEqualization) effect.push("loudnorm");

Expand Down

0 comments on commit ba7594e

Please sign in to comment.