diff --git a/dist/esm/index.mjs b/dist/esm/index.mjs index d9674b18f..1bc5e23e6 100644 --- a/dist/esm/index.mjs +++ b/dist/esm/index.mjs @@ -5208,7 +5208,7 @@ var resampleAudioData = ({ destination[newFrameIndex * srcNumberOfChannels + i] = getSourceValues(start, end, i); } } - if (srcNumberOfChannels === 1) { + else if (srcNumberOfChannels === 1) { const m = getSourceValues(start, end, 0); destination[newFrameIndex * 2 + 0] = m; destination[newFrameIndex * 2 + 1] = m; @@ -5225,18 +5225,37 @@ var resampleAudioData = ({ const l = getSourceValues(start, end, 0); const r = getSourceValues(start, end, 1); const c = getSourceValues(start, end, 2); + const lfe = getSourceValues(start, end, 3); const sl = getSourceValues(start, end, 4); const sr = getSourceValues(start, end, 5); const sq = Math.sqrt(1 / 2); - const norm = 1 / (1 + sq + sq); - const l2 = (l + sq * (c + sl)) * norm; - const r2 = (r + sq * (c + sr)) * norm; + const norm = 1 / (1 + sq + sq + 0.5); + const l2 = (l + sq * (c + sl) + 0.5 * lfe) * norm; + const r2 = (r + sq * (c + sr) + 0.5 * lfe) * norm; destination[newFrameIndex * 2 + 0] = clampToS16(l2); destination[newFrameIndex * 2 + 1] = clampToS16(r2); + } else if (srcNumberOfChannels === 8) { + const l = getSourceValues(start, end, 0); + const r = getSourceValues(start, end, 1); + const c = getSourceValues(start, end, 2); + const lfe = getSourceValues(start, end, 3); + const bl = getSourceValues(start, end, 4); + const br = getSourceValues(start, end, 5); + const sl = getSourceValues(start, end, 6); + const sr = getSourceValues(start, end, 7); + const sq = Math.sqrt(1 / 2); + const norm = 1 / (1 + sq + 1 + 0.5); + destination[newFrameIndex * 2] = clampToS16((l + sq * c + 0.5 * (lfe + bl + sl)) * norm); + destination[newFrameIndex * 2 + 1] = clampToS16((r + sq * c + 0.5 * (lfe + br + sr)) * norm); } else { - for (let i = 0;i < srcNumberOfChannels; i++) { - destination[newFrameIndex * TARGET_NUMBER_OF_CHANNELS + i] = getSourceValues(start, end, i); - } + // Include every discrete channel while bounding the sum of channel gains. + let extra = 0; + for (let channel = 2;channel < srcNumberOfChannels; channel++) { + extra += 0.5 * getSourceValues(start, end, channel); + } + const norm = 1 / (1 + 0.5 * (srcNumberOfChannels - 2)); + destination[newFrameIndex * 2] = clampToS16((getSourceValues(start, end, 0) + extra) * norm); + destination[newFrameIndex * 2 + 1] = clampToS16((getSourceValues(start, end, 1) + extra) * norm); } } };