amplitude demodulation in javascript

index.tsx
// Amplitude Demodulation function
function amplitudeDemodulation(audioBuffer) {
    const demodulatedBuffer = new Float32Array(audioBuffer.length);

    for (let i = 0; i < audioBuffer.length; i++) {
        demodulatedBuffer[i] = Math.abs(audioBuffer[i]);
    }

    return demodulatedBuffer;
}

// Usage
const audioBuffer = [0.1, 0.3, -0.2, 0.5, -0.8];
const demodulatedBuffer = amplitudeDemodulation(audioBuffer);
console.log(demodulatedBuffer);
450 chars
16 lines

gistlibby LogSnag