Ajout du sampler et de l'input

This commit is contained in:
2025-10-11 22:48:09 +02:00
parent 7f150e8bb4
commit 00e8b4a3a5
23 changed files with 1048 additions and 46 deletions

View File

@ -0,0 +1,39 @@
import type { AudioProcessor } from "./AudioProcessor";
export class Normalize implements AudioProcessor {
getName(): string {
return "Normalize";
}
getDescription(): string {
return "Normalizes audio to maximum amplitude without clipping";
}
async process(
leftChannel: Float32Array,
rightChannel: Float32Array
): Promise<[Float32Array, Float32Array]> {
let maxAmplitude = 0;
for (let i = 0; i < leftChannel.length; i++) {
maxAmplitude = Math.max(maxAmplitude, Math.abs(leftChannel[i]));
maxAmplitude = Math.max(maxAmplitude, Math.abs(rightChannel[i]));
}
if (maxAmplitude === 0) {
return [leftChannel, rightChannel];
}
const gain = 1.0 / maxAmplitude;
const newLeft = new Float32Array(leftChannel.length);
const newRight = new Float32Array(rightChannel.length);
for (let i = 0; i < leftChannel.length; i++) {
newLeft[i] = leftChannel[i] * gain;
newRight[i] = rightChannel[i] * gain;
}
return [newLeft, newRight];
}
}