Ajout du sampler et de l'input
This commit is contained in:
29
src/lib/audio/processors/BitCrusher.ts
Normal file
29
src/lib/audio/processors/BitCrusher.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import type { AudioProcessor } from "./AudioProcessor";
|
||||
|
||||
export class BitCrusher implements AudioProcessor {
|
||||
getName(): string {
|
||||
return "Bit Crusher";
|
||||
}
|
||||
|
||||
getDescription(): string {
|
||||
return "Reduces bit depth for lo-fi digital distortion";
|
||||
}
|
||||
|
||||
async process(
|
||||
leftChannel: Float32Array,
|
||||
rightChannel: Float32Array
|
||||
): Promise<[Float32Array, Float32Array]> {
|
||||
const bitDepth = Math.floor(Math.random() * 6) + 3;
|
||||
const levels = Math.pow(2, bitDepth);
|
||||
|
||||
const newLeft = new Float32Array(leftChannel.length);
|
||||
const newRight = new Float32Array(rightChannel.length);
|
||||
|
||||
for (let i = 0; i < leftChannel.length; i++) {
|
||||
newLeft[i] = Math.floor(leftChannel[i] * levels) / levels;
|
||||
newRight[i] = Math.floor(rightChannel[i] * levels) / levels;
|
||||
}
|
||||
|
||||
return [newLeft, newRight];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user