Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | 15x 15x 15x 15x 15x 99x 2x 2x 99x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 6x 73x 71x 71x 71x 71x 71x 2x 2x 2x 71x 72x 72x 4x 72x 72x 72x 72x 72x 72x 72x 72x 72x 72x 72x 72x 72x 101x 101x 100x 100x 1x 99x 99x 99x 1x 98x 98x 98x 101x 62x 98x 98x 98x 71x 100x 100x 100x 1x 99x 100x 100x 99x 100x 82x 17x 98x 98x 98x 2x 99x 99x 99x 99x 99x 99x 99x 72x 27x 27x 27x 1x 26x 26x 98x 36x 62x 62x 56x 6x 6x 6x 98x 71x 98x 98x 98x 98x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 98x 2x 2x 96x 96x 96x 96x 98x 96x 96x 96x 96x 96x 96x 15x 40088x 40088x 40088x 40088x 40088x 40088x 15x 81x 81x 3245982x 3245982x 3245982x 3245982x 81x 2x 2x 2x 2x 2x 2x 2x 16016x 16016x 16016x 16016x 16016x 16016x 16016x 4x 8x | import {
collectBmsWAVVolumeMultipliers,
collectBmsWAVPlaybackModifiers,
firesBeforeTempoReversal,
playsAtKeysoundVolume,
resolveChart,
usesMonophonicWAVPlayback,
type ResolvedVolumeChange,
type TimedSampleTrigger,
volWAVToLinearGain,
} from '@be-music/chart-model';
// Load filesystem adapters only when rendering from or writing to disk.
type NodeFSPromises = typeof import('node:fs/promises');
type NodePath = typeof import('node:path');
let nodeFSPromisesPromise: Promise<NodeFSPromises> | undefined;
let nodePathPromise: Promise<NodePath> | undefined;
const loadNodeFSPromises = (): Promise<NodeFSPromises> => (nodeFSPromisesPromise ??= import('node:fs/promises'));
const loadNodePath = (): Promise<NodePath> => (nodePathPromise ??= import('node:path'));
import type { BeMusicJSON } from '@be-music/chart-source';
import {
readSampleFrame,
resolveSampleVoiceEnvelope,
resolveStereoBalance,
sampleSliceEnvelopeGain,
SAMPLE_SLICE_FADE_SECONDS,
throwIfAborted,
type SampleSliceEnvelope,
} from '@be-music/shared-utils/core';
import { parseChartFile, resolveBMSControlFlow } from '@be-music/chart-parser';
import { detectAudioFormat, encodeAIFF16, encodeWAV16 } from './file-codec.ts';
import {
createSampleLoader,
measurePeak,
type RenderSampleLoadProgress,
type RenderResult,
type StereoSample,
} from '@be-music/audio-sample';
export interface RenderOptions {
sampleRate?: number;
normalize?: boolean;
tailSeconds?: number;
gain?: number;
startSeconds?: number;
baseDir?: string;
fallbackToneSeconds?: number;
signal?: AbortSignal;
resolveTriggerGain?: (trigger: TimedSampleTrigger) => number;
onSampleLoadProgress?: (progress: RenderSampleLoadProgress) => void;
inferBmsLNTypeWhenMissing?: boolean;
}
/** A BMS dynamic volume change from the resolved chart (`ResolvedChart.volumeChanges`). */
type DynamicVolumeChange = Pick<ResolvedVolumeChange, 'bus' | 'seconds' | 'gain'>;
type DynamicVolumeBus = DynamicVolumeChange['bus'];
interface DynamicVolumeState {
index: number;
gain: number;
}
interface DynamicVolumeChangesByBus {
bgm: DynamicVolumeChange[];
play: DynamicVolumeChange[];
}
interface ScheduledSampleRender {
start: number;
sample: StereoSample;
triggerGain: number;
sampleOffsetFrames: number;
/** Source frames the voice plays; at a rate other than 1 it sounds for `sampleMaxFrames / voice.rate` frames. */
sampleMaxFrames?: number;
slice?: ScheduledSampleSlice;
voice?: ScheduledSampleVoice;
}
/** A trigger's own rate and stereo balance (an LRX note's `frq` and `pan`). */
interface ScheduledSampleVoice {
rate: number;
leftGain: number;
rightGain: number;
}
/** A slice window that cuts its source file, with the ramps that keep the cut from clicking. */
interface ScheduledSampleSlice {
lengthFrames: number;
envelope: SampleSliceEnvelope;
}
interface ScheduledSampleFrameWindow {
sampleOffsetFrames: number;
sampleMaxFrames: number;
slice?: ScheduledSampleSlice;
}
const DEFAULT_SAMPLE_RATE = 44_100;
const DEFAULT_TAIL_SECONDS = 2;
const DEFAULT_GAIN = 0.9;
function advanceDynamicVolumeGain(
changes: readonly DynamicVolumeChange[],
seconds: number,
state: DynamicVolumeState,
): number {
while (state.index < changes.length && changes[state.index]!.seconds <= seconds) {
state.gain = changes[state.index]!.gain;
state.index += 1;
}
return state.gain;
}
export async function renderJSON(json: BeMusicJSON, options: RenderOptions = {}): Promise<RenderResult> {
const sampleRate = options.sampleRate ?? DEFAULT_SAMPLE_RATE;
const normalize = options.normalize ?? true;
const tailSeconds = options.tailSeconds ?? DEFAULT_TAIL_SECONDS;
const gain = (options.gain ?? DEFAULT_GAIN) * volWAVToLinearGain(json.bms.volWAV);
const startSeconds = Number.isFinite(options.startSeconds) ? Math.max(0, options.startSeconds ?? 0) : 0;
// BMS spec — an undefined / missing / undecodable `#WAVxx` reference is SILENT (LR2 / beatoraja both skip it).
// `fallbackToneSeconds` exists as an opt-in debug aid; 0 renders a 1-frame silent placeholder so every downstream
// path (scheduling, gain, progress reporting) still sees a sample.
const fallbackToneSeconds = options.fallbackToneSeconds ?? 0;
const baseDir = options.baseDir ?? process.cwd();
const signal = options.signal;
const resolveTriggerGain = options.resolveTriggerGain;
const onSampleLoadProgress = options.onSampleLoadProgress;
throwIfAborted(signal);
const resolved = resolveChart(json, { inferBmsLNTypeWhenMissing: options.inferBmsLNTypeWhenMissing === true });
const dynamicVolumeChanges = splitDynamicVolumeChangesByBus(resolved.volumeChanges);
// LR2's event pump freezes at a negative-BPM reversal: nothing behind the reversal ever sounds, and on the reversal
// tick only the BGM ordered before the negative BPM does (Scene04_Play.cpp:1267-1269). Match that audibility in the
// offline render.
const reversal = resolved.reversal;
const triggers =
reversal === undefined
? resolved.sampleTriggers
: resolved.sampleTriggers.filter((trigger) =>
firesBeforeTempoReversal(reversal, trigger.seconds, trigger.channel),
);
const { scheduled, maxFrame } = await scheduleSampleRenders({
json,
triggers,
sampleRate,
tailSeconds,
startSeconds,
baseDir,
fallbackToneSeconds,
signal,
onSampleLoadProgress,
resolveTriggerGain,
dynamicVolumeChanges,
});
const left = new Float32Array(maxFrame);
const right = new Float32Array(maxFrame);
mixScheduledSamples(left, right, scheduled, gain, signal);
const peak = measurePeak(left, right);
if (normalize && peak > 1) {
const scale = 1 / peak;
scalePCM(left, scale);
scalePCM(right, scale);
}
return {
sampleRate,
left,
right,
durationSeconds: left.length / sampleRate,
peak: normalize && peak > 1 ? 1 : peak,
};
}
function splitDynamicVolumeChangesByBus(changes: ReadonlyArray<DynamicVolumeChange>): DynamicVolumeChangesByBus {
const partitioned: DynamicVolumeChangesByBus = {
bgm: [],
play: [],
};
for (const change of changes) {
partitioned[change.bus].push(change);
}
return partitioned;
}
async function scheduleSampleRenders(params: {
json: BeMusicJSON;
triggers: ReadonlyArray<TimedSampleTrigger>;
sampleRate: number;
tailSeconds: number;
startSeconds: number;
baseDir: string;
fallbackToneSeconds: number;
signal?: AbortSignal;
onSampleLoadProgress?: (progress: RenderSampleLoadProgress) => void;
resolveTriggerGain?: (trigger: TimedSampleTrigger) => number;
dynamicVolumeChanges: DynamicVolumeChangesByBus;
}): Promise<{ scheduled: ScheduledSampleRender[]; maxFrame: number }> {
const {
json,
triggers,
sampleRate,
tailSeconds,
startSeconds,
baseDir,
fallbackToneSeconds,
signal,
onSampleLoadProgress,
resolveTriggerGain,
dynamicVolumeChanges,
} = params;
const scheduled: ScheduledSampleRender[] = [];
const bmsonScheduledSlices = new Set<string>();
const latestBMSScheduleBySampleKey = new Map<string, number>();
const bgmVolumeState: DynamicVolumeState = { index: 0, gain: 1 };
const playVolumeState: DynamicVolumeState = { index: 0, gain: 1 };
let maxFrame = Math.max(1, Math.round(tailSeconds * sampleRate));
// BMS spec — `#PATH_WAV` declares a directory prefix the chart's WAVs live under. The sample-path resolver tries
// `pathPrefix + samplePath` before the bare path so charts that organize their WAVs under a sub-folder (e.g.
// `wav/kick.wav` reachable via `#PATH_WAV wav/`) resolve correctly.
const pathWAVPrefix = typeof json.bms.pathWAV === 'string' ? json.bms.pathWAV : undefined;
// MacBeat WAVCMD volume is a percentage (100 = unity). Pitch and duration are handled separately.
const wavCmdVolumeMultipliers = collectBmsWAVVolumeMultipliers(json);
const playbackModifiers = collectBmsWAVPlaybackModifiers(json);
const loadSample = createSampleLoader({
sampleRate,
baseDir,
fallbackToneSeconds,
signal,
onSampleLoadProgress,
pathPrefix: pathWAVPrefix,
});
for (const trigger of triggers) {
throwIfAborted(signal);
const sample = await loadSample(trigger.sampleKey, trigger.samplePath, playbackModifiers.get(trigger.sampleKey));
const frameWindow = resolveScheduledSampleFrameWindow(trigger, sampleRate, sample);
if (!frameWindow) {
continue;
}
const triggerGain = resolveScheduledTriggerGain(
trigger,
resolveTriggerGain,
dynamicVolumeChanges,
bgmVolumeState,
playVolumeState,
wavCmdVolumeMultipliers,
);
const start = Math.max(0, Math.round((trigger.seconds - startSeconds) * sampleRate));
if (!shouldScheduleTrigger(json, trigger, start, bmsonScheduledSlices)) {
continue;
}
trimPreviousBMSRetrigger(json, trigger, start, scheduled, latestBMSScheduleBySampleKey);
const voice = resolveScheduledSampleVoice(trigger);
const scheduleIndex =
scheduled.push({
start,
sample,
triggerGain,
sampleOffsetFrames: frameWindow.sampleOffsetFrames,
sampleMaxFrames: frameWindow.sampleMaxFrames,
slice: frameWindow.slice,
...(voice ? { voice } : {}),
}) - 1;
if (usesMonophonicWAVPlayback(json, trigger.sampleKey)) {
latestBMSScheduleBySampleKey.set(trigger.sampleKey, scheduleIndex);
}
Eif (triggerGain > 0) {
const soundingFrames = Math.ceil(frameWindow.sampleMaxFrames / (voice?.rate ?? 1));
maxFrame = Math.max(maxFrame, start + soundingFrames + Math.round(tailSeconds * sampleRate));
}
}
return { scheduled, maxFrame };
}
function resolveScheduledSampleFrameWindow(
trigger: TimedSampleTrigger,
sampleRate: number,
sample: StereoSample,
): ScheduledSampleFrameWindow | undefined {
const sampleOffsetFrames = Math.max(0, Math.round(trigger.sampleOffsetSeconds * sampleRate));
const availableFrames = sample.left.length - sampleOffsetFrames;
if (availableFrames <= 0) {
return undefined;
}
const requestedDurationFrames =
typeof trigger.sampleDurationSeconds === 'number' && Number.isFinite(trigger.sampleDurationSeconds)
? Math.max(1, Math.round(trigger.sampleDurationSeconds * sampleRate))
: undefined;
const lengthFrames =
requestedDurationFrames === undefined ? availableFrames : Math.min(availableFrames, requestedDurationFrames);
Iif (lengthFrames <= 0) {
return undefined;
}
const envelope = resolveSampleVoiceEnvelope(
sampleOffsetFrames,
requestedDurationFrames,
sample.left.length,
Math.round(SAMPLE_SLICE_FADE_SECONDS * sampleRate),
Math.round((trigger.sampleAttackSeconds ?? 0) * sampleRate),
Math.round((trigger.sampleReleaseSeconds ?? 0) * sampleRate),
);
if (envelope.fadeIn === 0 && envelope.fadeOut === 0) {
return { sampleOffsetFrames, sampleMaxFrames: lengthFrames };
}
// A cut slice rings on past its end while it fades out, so the window grows by the fade-out.
return {
sampleOffsetFrames,
sampleMaxFrames: lengthFrames + envelope.fadeOut,
slice: { lengthFrames, envelope },
};
}
/** A trigger's own rate and balance, or `undefined` when it plays at rate 1 in the centre. */
function resolveScheduledSampleVoice(trigger: TimedSampleTrigger): ScheduledSampleVoice | undefined {
const rate =
typeof trigger.samplePlaybackRate === 'number' && trigger.samplePlaybackRate > 0 ? trigger.samplePlaybackRate : 1;
const balance = resolveStereoBalance(trigger.samplePan ?? 0);
if (rate === 1 && balance.left === 1 && balance.right === 1) return undefined;
return { rate, leftGain: balance.left, rightGain: balance.right };
}
function resolveScheduledTriggerGain(
trigger: TimedSampleTrigger,
resolveTriggerGain: ((trigger: TimedSampleTrigger) => number) | undefined,
dynamicVolumeChanges: DynamicVolumeChangesByBus,
bgmVolumeState: DynamicVolumeState,
playVolumeState: DynamicVolumeState,
wavCmdVolumeMultipliers: ReadonlyMap<string, number>,
): number {
const rawTriggerGain = resolveTriggerGain?.(trigger) ?? 1;
const volumeBus: DynamicVolumeBus = playsAtKeysoundVolume(trigger.channel, trigger.event) ? 'play' : 'bgm';
const dynamicGain =
volumeBus === 'play'
? advanceDynamicVolumeGain(dynamicVolumeChanges.play, trigger.seconds, playVolumeState)
: advanceDynamicVolumeGain(dynamicVolumeChanges.bgm, trigger.seconds, bgmVolumeState);
// `#WAVCMD 01 xx vv` per-slot volume — multiplied in alongside the dynamic-volume bus state so a chart can stack a
// 50% `#WAVCMD` slot under a `97`/`98` runtime cut.
const wavCmdGain = wavCmdVolumeMultipliers.get(trigger.sampleKey) ?? 1;
// An LRX note's own `vol`.
const noteGain = typeof trigger.sampleGain === 'number' && trigger.sampleGain >= 0 ? trigger.sampleGain : 1;
return (Number.isFinite(rawTriggerGain) ? Math.max(0, rawTriggerGain) : 1) * dynamicGain * wavCmdGain * noteGain;
}
function shouldScheduleTrigger(
json: BeMusicJSON,
trigger: TimedSampleTrigger,
start: number,
bmsonScheduledSlices: Set<string>,
): boolean {
if (json.sourceFormat !== 'bmson') {
return true;
}
// Each pulse plays its assigned slice, including continuations. Only simultaneous uses of that slice share audio.
Iif (!trigger.sampleSliceId) {
return true;
}
const dedupeKey = `${trigger.sampleSliceId}@${start}`;
if (bmsonScheduledSlices.has(dedupeKey)) {
return false;
}
bmsonScheduledSlices.add(dedupeKey);
return true;
}
function trimPreviousBMSRetrigger(
json: BeMusicJSON,
trigger: TimedSampleTrigger,
start: number,
scheduled: ScheduledSampleRender[],
latestBMSScheduleBySampleKey: Map<string, number>,
): void {
if (!usesMonophonicWAVPlayback(json, trigger.sampleKey)) {
return;
}
const previousIndex = latestBMSScheduleBySampleKey.get(trigger.sampleKey);
if (previousIndex === undefined) {
return;
}
const previous = scheduled[previousIndex];
const maxFramesUntilRetrigger = Math.max(0, start - previous.start);
const currentPreviousMaxFrames =
previous.sampleMaxFrames ?? previous.sample.left.length - previous.sampleOffsetFrames;
previous.sampleMaxFrames = Math.min(currentPreviousMaxFrames, maxFramesUntilRetrigger);
}
function mixScheduledSamples(
destinationLeft: Float32Array,
destinationRight: Float32Array,
scheduled: readonly ScheduledSampleRender[],
gain: number,
signal?: AbortSignal,
): void {
for (let scheduleIndex = 0; scheduleIndex < scheduled.length; scheduleIndex += 1) {
Iif (signal && (scheduleIndex & 0x1f) === 0) {
throwIfAborted(signal);
}
const item = scheduled[scheduleIndex]!;
Iif (item.triggerGain <= 0) {
continue;
}
mixSample(
destinationLeft,
destinationRight,
item.sample,
item.start,
gain * item.triggerGain,
item.sampleOffsetFrames,
item.sampleMaxFrames,
signal,
item.slice,
item.voice,
);
}
}
export async function renderChartFile(
inputPath: string,
outputPath: string,
options: RenderOptions = {},
): Promise<RenderResult> {
const { resolve, dirname } = await loadNodePath();
const chartPath = resolve(inputPath);
const json = resolveBMSControlFlow(await parseChartFile(chartPath, { signal: options.signal }));
const audioRendered = await renderJSON(json, {
...options,
baseDir: options.baseDir ?? dirname(chartPath),
});
await writeAudioFile(outputPath, audioRendered);
return audioRendered;
}
export async function writeAudioFile(outputPath: string, result: RenderResult): Promise<void> {
const [{ resolve }, { writeFile }] = await Promise.all([loadNodePath(), loadNodeFSPromises()]);
const destination = resolve(outputPath);
const format = detectAudioFormat(destination);
const encoded = format === 'aiff' ? encodeAIFF16(result) : encodeWAV16(result);
await writeFile(destination, encoded);
}
function mixSample(
destinationLeft: Float32Array,
destinationRight: Float32Array,
sample: StereoSample,
startFrame: number,
gain: number,
sampleOffsetFrames = 0,
sampleMaxFrames?: number,
signal?: AbortSignal,
slice?: ScheduledSampleSlice,
voice?: ScheduledSampleVoice,
): void {
if (voice) {
mixSampleVoice(
destinationLeft,
destinationRight,
sample,
startFrame,
gain,
sampleOffsetFrames,
sampleMaxFrames,
voice,
slice,
signal,
);
return;
}
const sourceStart = Math.max(0, sampleOffsetFrames);
const availableFrames = sample.left.length - sourceStart;
Iif (availableFrames <= 0) {
return;
}
const requestedFrames = sampleMaxFrames ?? availableFrames;
Iif (requestedFrames <= 0) {
return;
}
const destinationAvailable = destinationLeft.length - startFrame;
Iif (destinationAvailable <= 0) {
return;
}
const framesToMix = Math.min(availableFrames, requestedFrames, destinationAvailable);
const sourceLeft = sample.left;
const sourceRight = sample.right;
if (slice) {
for (let index = 0; index < framesToMix; index += 1) {
Iif (signal && (index & 0x7ff) === 0) {
throwIfAborted(signal);
}
const source = sourceStart + index;
const target = startFrame + index;
const frameGain = gain * sampleSliceEnvelopeGain(index, slice.lengthFrames, slice.envelope);
destinationLeft[target] += sourceLeft[source] * frameGain;
destinationRight[target] += sourceRight[source] * frameGain;
}
return;
}
Eif (!signal) {
for (let index = 0; index < framesToMix; index += 1) {
const source = sourceStart + index;
const target = startFrame + index;
destinationLeft[target] += sourceLeft[source] * gain;
destinationRight[target] += sourceRight[source] * gain;
}
return;
}
for (let index = 0; index < framesToMix; index += 1) {
if ((index & 0x7ff) === 0) {
throwIfAborted(signal);
}
const source = sourceStart + index;
const target = startFrame + index;
destinationLeft[target] += sourceLeft[source] * gain;
destinationRight[target] += sourceRight[source] * gain;
}
}
/**
* {@link mixSample} for a voice with its own rate and balance: each output frame reads the source `rate` frames on,
* interpolated, and the slice envelope runs over source frames as it does at rate 1.
*/
function mixSampleVoice(
destinationLeft: Float32Array,
destinationRight: Float32Array,
sample: StereoSample,
startFrame: number,
gain: number,
sampleOffsetFrames: number,
sampleMaxFrames: number | undefined,
voice: ScheduledSampleVoice,
slice: ScheduledSampleSlice | undefined,
signal: AbortSignal | undefined,
): void {
const sourceStart = Math.max(0, sampleOffsetFrames);
const sourceFrames = Math.min(sample.left.length - sourceStart, sampleMaxFrames ?? Number.POSITIVE_INFINITY);
Iif (!(sourceFrames > 0)) return;
const outputFrames = Math.min(Math.ceil(sourceFrames / voice.rate), destinationLeft.length - startFrame);
const leftGain = gain * voice.leftGain;
const rightGain = gain * voice.rightGain;
for (let index = 0; index < outputFrames; index += 1) {
Iif (signal && (index & 0x7ff) === 0) throwIfAborted(signal);
const played = index * voice.rate;
Iif (played >= sourceFrames) break;
const envelope = slice ? sampleSliceEnvelopeGain(played, slice.lengthFrames, slice.envelope) : 1;
const target = startFrame + index;
destinationLeft[target] += readSampleFrame(sample.left, sourceStart + played) * leftGain * envelope;
destinationRight[target] += readSampleFrame(sample.right, sourceStart + played) * rightGain * envelope;
}
}
function scalePCM(channel: Float32Array, scale: number): void {
for (let index = 0; index < channel.length; index += 1) {
channel[index] *= scale;
}
}
|