Skip to main content

Documentation 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.

When network access is unavailable — or when the 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

function encodeWAV(chunksL, chunksR, sampleRate)
// chunksL:    Float32Array[] — left channel PCM chunks collected during recording
// chunksR:    Float32Array[] — right channel PCM chunks collected during recording
// sampleRate: number         — from AudioContext.sampleRate (typically 44100 or 48000 Hz)
// returns:    Blob           (type: "audio/wav")
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:
1

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.
let total = 0;
chunksL.forEach(c => total += c.length);
const L = new Float32Array(total), R = new Float32Array(total);
let o = 0;
for (let i = 0; i < chunksL.length; i++) {
  L.set(chunksL[i], o);
  R.set(chunksR[i], o);
  o += chunksL[i].length;
}
2

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:
OffsetSizeValueDescription
04"RIFF"Chunk ID
4436 + dataLenChunk size (little-endian)
84"WAVE"Format
124"fmt "Sub-chunk 1 ID
16416Sub-chunk 1 size (PCM)
2021Audio format (PCM = 1)
2222Number of channels
244sampleRateSample rate
284sampleRate × 4Byte rate
3224Block align
34216Bits per sample
364"data"Sub-chunk 2 ID
404dataLenSub-chunk 2 size
3

Interleave Channels and Convert to 16-bit PCM

Samples are written in standard interleaved stereo order (L, R, L, R, …). Each Float32 sample in the range [−1.0, 1.0] is clamped and scaled to a signed 16-bit integer:
for (let i = 0; i < total; i++) {
  let l = Math.max(-1, Math.min(1, L[i]));
  view.setInt16(off, l < 0 ? l * 0x8000 : l * 0x7FFF, true); // little-endian
  off += 2;
  let r = Math.max(-1, Math.min(1, R[i]));
  view.setInt16(off, r < 0 ? r * 0x8000 : r * 0x7FFF, true);
  off += 2;
}
The clamping (Math.max(-1, Math.min(1, …))) provides a final safety net against any out-of-range float values before conversion.
The function returns a 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

Once encodeWAV returns a Blob, the download is triggered entirely client-side using a temporary anchor element:
const dl = (blob, ext) => {
  const url = URL.createObjectURL(blob);
  const a = document.createElement("a");
  a.href = url;
  a.download = "mi-mezcla-" + Date.now() + ext;  // e.g. mi-mezcla-1718123456789.wav
  document.body.appendChild(a);
  a.click();
  a.remove();
  setTimeout(() => URL.revokeObjectURL(url), 1500); // release object URL from memory
};
The object URL is revoked after 1.5 seconds to free the memory held by the blob reference. The file is saved to your browser’s default download location.

WAV vs. MP3 Fallback

NEON DJ always attempts to encode as MP3 first by loading the lamejs encoder from a CDN. WAV export is the automatic fallback for offline use:
loadLame()
  .then(() => dl(encodeMP3(recL, recR, sr), ".mp3"))
  .catch(() => dl(encodeWAV(recL, recR, sr), ".wav"));
When lamejs loads successfully, a 128 kbps stereo MP3 is downloaded — smaller file size, same stereo fidelity.
The WAV file is perfect for importing into a DAW (Ableton Live, Logic Pro, Reaper, Audacity, etc.) for further processing. Because it is uncompressed 16-bit PCM, there is no generation loss — you can apply EQ, compression, mastering chains, or export to any format without any quality degradation from the original capture.

Compatibility

The WAV file produced by encodeWAV conforms to the standard PCM WAV specification and is compatible with:
VLC, Windows Media Player, iTunes/Music, QuickTime, foobar2000, and any other player that supports standard WAV files.
Ableton Live, Logic Pro, Pro Tools, Reaper, FL Studio, GarageBand, Audacity, Adobe Audition, and any DAW that accepts PCM WAV imports.
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.

Build docs developers (and LLMs) love