CLIENT-SIDE WEB AUDIO PCM SLICING & WAV SYNTHESIS
TACTICAL AUDIO SPECIFICATION // RIFF WAVE ENCODING & HARDWARE BUFFERS
In-Browser Decoding & Waveform Peaks
The HTML5 Web Audio API provides the AudioContext.decodeAudioData() method, which asynchronously decompresses encoded audio formats (MP3, AAC, OGG, FLAC) into raw 32-bit floating-point linear PCM samples stored within an AudioBuffer.
To visualize the waveform across a canvas, the raw sample array is downsampled across pixel columns. Peak positive and negative amplitudes within each sample bucket are calculated to paint high-contrast neon peaks with zero latency.
Canonical 44-Byte RIFF/WAVE Packaging
Exporting uncompressed audio without third-party server encoders requires procedural binary assembly. Sonic Slice allocates an ArrayBuffer and populates the canonical 44-byte RIFF/WAVE header using a JavaScript DataView:
Bytes 0–3 identify the chunk ID (RIFF), followed by total filesize, format descriptor (WAVE), subchunk 1 (fmt ), audio format (1 for uncompressed PCM), channel count, sample rate (e.g. 44100 Hz), byte rate, block alignment, and bits per sample (16-bit). Floating-point samples are clamped and converted to signed 16-bit integers (-32768 to 32767) before generating a local Blob.