VolumeBooster: Support browser and Vesktop (#2730)

This commit is contained in:
sadan4 2024-08-31 23:08:33 -04:00 committed by GitHub
parent 273981deb7
commit e07a4e19e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 68 additions and 6 deletions

View file

@ -0,0 +1,9 @@
# Volume Booster
Allows you to boost the volume over 200% on desktop and over 100% on other clients.
Works on users, bots, and streams!
![the volume being moved up to 270% on vesktop](https://github.com/user-attachments/assets/793e012e-c069-4fa4-a3d5-61c2f55edd3e)
![the volume being moved up to 297% on a stream](https://github.com/user-attachments/assets/77463eb9-2537-4821-a3ab-82f60633ccbc)

View file

@ -31,10 +31,27 @@ const settings = definePluginSettings({
} }
}); });
interface StreamData {
audioContext: AudioContext,
audioElement: HTMLAudioElement,
emitter: any,
// added by this plugin
gainNode?: GainNode,
id: string,
levelNode: AudioWorkletNode,
sinkId: string,
stream: MediaStream,
streamSourceNode?: MediaStreamAudioSourceNode,
videoStreamId: string,
_mute: boolean,
_speakingFlags: number,
_volume: number;
}
export default definePlugin({ export default definePlugin({
name: "VolumeBooster", name: "VolumeBooster",
authors: [Devs.Nuckyz], authors: [Devs.Nuckyz, Devs.sadan],
description: "Allows you to set the user and stream volume above the default maximum.", description: "Allows you to set the user and stream volume above the default maximum",
settings, settings,
patches: [ patches: [
@ -45,12 +62,28 @@ export default definePlugin({
].map(find => ({ ].map(find => ({
find, find,
replacement: { replacement: {
match: /(?<=maxValue:\i\.\i)\?(\d+?):(\d+?)(?=,)/, match: /(?<=maxValue:)\i\.\i\?(\d+?):(\d+?)(?=,)/,
replace: (_, higherMaxVolume, minorMaxVolume) => "" replace: (_, higherMaxVolume, minorMaxVolume) => `${higherMaxVolume}*$self.settings.store.multiplier`
+ `?${higherMaxVolume}*$self.settings.store.multiplier`
+ `:${minorMaxVolume}*$self.settings.store.multiplier`
} }
})), })),
// Patches needed for web/vesktop
{
find: "streamSourceNode",
predicate: () => IS_WEB,
group: true,
replacement: [
// Remove rounding algorithm
{
match: /Math\.max.{0,30}\)\)/,
replace: "arguments[0]"
},
// Patch the volume
{
match: /\.volume=this\._volume\/100;/,
replace: ".volume=0.00;$self.patchVolume(this);"
}
]
},
// Prevent Audio Context Settings sync from trying to sync with values above 200, changing them to 200 before we send to Discord // Prevent Audio Context Settings sync from trying to sync with values above 200, changing them to 200 before we send to Discord
{ {
find: "AudioContextSettingsMigrated", find: "AudioContextSettingsMigrated",
@ -83,4 +116,20 @@ export default definePlugin({
] ]
} }
], ],
patchVolume(data: StreamData) {
if (data.stream.getAudioTracks().length === 0) return;
data.streamSourceNode ??= data.audioContext.createMediaStreamSource(data.stream);
if (!data.gainNode) {
const gain = data.gainNode = data.audioContext.createGain();
data.streamSourceNode.connect(gain);
gain.connect(data.audioContext.destination);
}
data.gainNode.gain.value = data._mute
? 0
: data._volume / 100;
}
}); });

View file

@ -534,6 +534,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
name: "Joona", name: "Joona",
id: 297410829589020673n id: 297410829589020673n
}, },
sadan: {
name: "sadan",
id: 521819891141967883n,
},
Kylie: { Kylie: {
name: "Cookie", name: "Cookie",
id: 721853658941227088n id: 721853658941227088n