Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions dist/src/playback/processing/streamProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2416,8 +2416,8 @@ class StreamAudioResource extends BaseAudioResource {
type: 's16le',
volume,
enableAGC,
lookaheadMs: this.nodelink?.options?.audio?.lookaheadMs,
gateThresholdLUFS: this.nodelink?.options?.audio?.gateThresholdLUFS
lookaheadMs: this.nodelink?.options?.playback?.audio?.lookaheadMs,
gateThresholdLUFS: this.nodelink?.options?.playback?.audio?.gateThresholdLUFS
});
pipeline(pcmStream, volumeTransformer, (err) => {
if (err && !this._destroyed) {
Expand Down Expand Up @@ -2520,7 +2520,7 @@ export const createSeekeableAudioResource = async (guildId, url, seekTime, endTi
return _createErrorResponse(err.message, cause);
}
};
export const createPCMStream = (_guildId, stream, type, nodelink, volume = 1.0, filters = {}) => {
export const createPCMStream = (_guildId, stream, type, nodelink, volume = 1.0, filters = {}, enableAGC = false) => {
const resamplingQuality = nodelink.options.playback.audio?.resamplingQuality || 'fastest';
const normalizedType = normalizeFormat(type);
const streams = [stream];
Expand Down Expand Up @@ -2584,7 +2584,13 @@ export const createPCMStream = (_guildId, stream, type, nodelink, volume = 1.0,
default:
throw new Error(`Unsupported audio format: '${type}'`);
}
streams.push(new VolumeTransformer({ type: 's16le', volume }));
streams.push(new VolumeTransformer({
type: 's16le',
volume,
enableAGC,
lookaheadMs: nodelink.options.playback.audio?.lookaheadMs,
gateThresholdLUFS: nodelink.options.playback.audio?.gateThresholdLUFS
}));
streams.push(new FiltersManager(nodelink, filters));
for (const s of streams) {
if (s !== stream) {
Expand Down
2 changes: 1 addition & 1 deletion dist/src/workers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ async function startLoadStream(streamId, payload) {
throw new Error(fetched.exception.message || 'Failed to load stream');
}
const createPCMStream = await getCreatePCMStream();
const pcmStream = createPCMStream(payload?.guildId ?? 'worker-stream', fetched.stream, fetched.type || urlResult.format || 'unknown', nodelink, (payload?.volume ?? 100) / 100, payload?.filters || {});
const pcmStream = createPCMStream(payload?.guildId ?? 'worker-stream', fetched.stream, fetched.type || urlResult.format || 'unknown', nodelink, (payload?.volume ?? 100) / 100, payload?.filters || {}, nodelink.options.playback?.audio?.loudnessNormalizer ?? false);
const entry = {
pcmStream,
fetched,
Expand Down
4 changes: 2 additions & 2 deletions dist/src/workers/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ else {
if (urlResult.url && !isHls && !isLocal && !isSabr) {
const resource = await createSeekeableAudioResource(id, urlResult.url, payload?.position || 0, undefined, nodelink, {}, {
streamInfo: urlResult,
loudnessNormalizer: nodelink.options.audio?.loudnessNormalizer
loudnessNormalizer: nodelink.options.playback?.audio?.loudnessNormalizer ?? false
}, (payload?.volume ?? 100) / 100, null, true);
if ('exception' in resource) {
throw new Error(resource.exception.message);
Expand All @@ -1015,7 +1015,7 @@ else {
if (!fetched || fetched.exception) {
throw new Error(fetched?.exception?.message || 'Failed to load stream');
}
pcmStream = createPCMStream(id, fetched.stream, fetched.type || urlResult.format || 'unknown', nodelink, (payload?.volume ?? 100) / 100, payload?.filters || {});
pcmStream = createPCMStream(id, fetched.stream, fetched.type || urlResult.format || 'unknown', nodelink, (payload?.volume ?? 100) / 100, payload?.filters || {}, nodelink.options.playback?.audio?.loudnessNormalizer ?? false);
}
pcmStream.on('data', (chunk) => {
if (!finished)
Expand Down
18 changes: 14 additions & 4 deletions src/playback/processing/streamProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3210,8 +3210,9 @@ class StreamAudioResource extends BaseAudioResource {
type: 's16le',
volume,
enableAGC,
lookaheadMs: this.nodelink?.options?.audio?.lookaheadMs,
gateThresholdLUFS: this.nodelink?.options?.audio?.gateThresholdLUFS
lookaheadMs: this.nodelink?.options?.playback?.audio?.lookaheadMs,
gateThresholdLUFS:
this.nodelink?.options?.playback?.audio?.gateThresholdLUFS
})

pipeline(pcmStream, volumeTransformer, (err: Error | null): void => {
Expand Down Expand Up @@ -3429,7 +3430,8 @@ export const createPCMStream = (
type: string,
nodelink: NodeLink,
volume: number = 1.0,
filters: FiltersState = {}
filters: FiltersState = {},
enableAGC: boolean = false
): Transform => {
const resamplingQuality =
nodelink.options.playback.audio?.resamplingQuality || 'fastest'
Expand Down Expand Up @@ -3514,7 +3516,15 @@ export const createPCMStream = (
throw new Error(`Unsupported audio format: '${type}'`)
}

streams.push(new VolumeTransformer({ type: 's16le', volume }))
streams.push(
new VolumeTransformer({
type: 's16le',
volume,
enableAGC,
lookaheadMs: nodelink.options.playback.audio?.lookaheadMs,
gateThresholdLUFS: nodelink.options.playback.audio?.gateThresholdLUFS
})
)
streams.push(new FiltersManager(nodelink, filters))

for (const s of streams) {
Expand Down
3 changes: 2 additions & 1 deletion src/workers/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,8 @@ async function startLoadStream(
fetched.type || (urlResult.format as string) || 'unknown',
nodelink as unknown as NodeLink,
(payload?.volume ?? 100) / 100,
payload?.filters || {}
payload?.filters || {},
nodelink.options.playback?.audio?.loudnessNormalizer ?? false
) as unknown as PCMStream

const entry: ActiveStreamEntry = {
Expand Down
10 changes: 4 additions & 6 deletions src/workers/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1380,11 +1380,8 @@ if (isMainThread) {
{},
{
streamInfo: urlResult,
loudnessNormalizer: (
nodelink.options as unknown as {
audio?: { loudnessNormalizer?: boolean }
}
).audio?.loudnessNormalizer
loudnessNormalizer:
nodelink.options.playback?.audio?.loudnessNormalizer ?? false
},
(payload?.volume ?? 100) / 100,
null,
Expand Down Expand Up @@ -1423,7 +1420,8 @@ if (isMainThread) {
fetched.type || (urlResult.format as string) || 'unknown',
nodelink as unknown as NodeLink,
(payload?.volume ?? 100) / 100,
payload?.filters || {}
payload?.filters || {},
nodelink.options.playback?.audio?.loudnessNormalizer ?? false
) as unknown as PCMStream
}

Expand Down
Loading