When network access is unavailable — or when theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/kepabilbao67-bot/musicplayer2/llms.txt
Use this file to discover all available pages before exploring further.
lamejs MP3 encoder fails to load — NEON DJ falls back to a fully self-contained WAV encoder written in plain JavaScript. The encodeWAV function converts the raw PCM chunks captured during your session into a standards-compliant 16-bit stereo WAV file, builds the complete RIFF header in memory, and triggers an immediate browser download. No external libraries, no server round-trips, no cloud uploads: the entire process happens inside your browser tab.
Function Signature
chunksL and chunksR are the two arrays populated by the ScriptProcessorNode during recording — each element is a 4096-sample Float32Array snapshot taken on every onaudioprocess event.
How the Encoder Works
The encoder runs entirely synchronously in three stages:Flatten the Chunk Arrays
All
Float32Array chunks in chunksL and chunksR are concatenated into two single flat Float32Array buffers — one for the left channel, one for the right — by iterating over the chunk list and using .set() to copy each slice into a pre-allocated array sized to the total sample count.Allocate the Output Buffer and Write the WAV Header
A single
ArrayBuffer is allocated for the complete file: 44 bytes for the standard RIFF/WAV header plus total × 2 channels × 2 bytes for the PCM data. A DataView is used for precise byte-level writes.The 44-byte header is written exactly to spec:| Offset | Size | Value | Description |
|---|---|---|---|
| 0 | 4 | "RIFF" | Chunk ID |
| 4 | 4 | 36 + dataLen | Chunk size (little-endian) |
| 8 | 4 | "WAVE" | Format |
| 12 | 4 | "fmt " | Sub-chunk 1 ID |
| 16 | 4 | 16 | Sub-chunk 1 size (PCM) |
| 20 | 2 | 1 | Audio format (PCM = 1) |
| 22 | 2 | 2 | Number of channels |
| 24 | 4 | sampleRate | Sample rate |
| 28 | 4 | sampleRate × 4 | Byte rate |
| 32 | 2 | 4 | Block align |
| 34 | 2 | 16 | Bits per sample |
| 36 | 4 | "data" | Sub-chunk 2 ID |
| 40 | 4 | dataLen | Sub-chunk 2 size |
Interleave Channels and Convert to 16-bit PCM
Samples are written in standard interleaved stereo order (L, R, L, R, …). Each The clamping (
Float32 sample in the range [−1.0, 1.0] is clamped and scaled to a signed 16-bit integer:Math.max(-1, Math.min(1, …))) provides a final safety net against any out-of-range float values before conversion.Blob with MIME type audio/wav wrapping the completed DataView.
Output Format
Format
16-bit signed PCM, RIFF/WAV container — the universal lossless audio interchange format.
Channels
Stereo (2 channels), interleaved left/right samples.
Sample Rate
Matches
AudioContext.sampleRate — typically 44100 Hz on macOS/Windows or 48000 Hz on some Linux and Chromebook configurations.Compatibility
Playable in any media player, DAW, audio editor, or browser without conversion.
16-bit stereo WAV at 44.1 kHz uses approximately 10 MB per minute of recorded audio (44100 samples/sec × 2 channels × 2 bytes = ~176 KB/s). A 10-minute DJ set will produce a file around 100 MB, so make sure you have sufficient disk space before starting a long session.
The Download Trigger
OnceencodeWAV returns a Blob, the download is triggered entirely client-side using a temporary anchor element:
WAV vs. MP3 Fallback
NEON DJ always attempts to encode as MP3 first by loading thelamejs encoder from a CDN. WAV export is the automatic fallback for offline use:
- Online (MP3 preferred)
- Offline (WAV fallback)
lamejs loads successfully, a 128 kbps stereo MP3 is downloaded — smaller file size, same stereo fidelity.Compatibility
The WAV file produced byencodeWAV conforms to the standard PCM WAV specification and is compatible with:
Media Players
Media Players
VLC, Windows Media Player, iTunes/Music, QuickTime, foobar2000, and any other player that supports standard WAV files.
DAWs and Audio Editors
DAWs and Audio Editors
Ableton Live, Logic Pro, Pro Tools, Reaper, FL Studio, GarageBand, Audacity, Adobe Audition, and any DAW that accepts PCM WAV imports.
Browsers and Web Apps
Browsers and Web Apps
All modern browsers support WAV playback natively via
<audio> elements or the Web Audio API. The file can be dropped directly into any browser-based audio tool.