{"record":{"id":"484c856eae822c7d","repo":"libgdx/libgdx","slug":"pcm-wav-files-must-be-8-or-16-bit","errorCode":null,"errorMessage":"PCM WAV files must be 8 or 16-bit: ","messagePattern":"PCM WAV files must be 8 or 16-bit: ","errorType":"exception","errorClass":"GdxRuntimeException","httpStatus":null,"severity":"error","filePath":"backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/audio/Wav.java","lineNumber":112,"sourceCode":"\t\t\t\tint fmtChunkLength = seekToChunk('f', 'm', 't', ' ');\n\n\t\t\t\t// http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html\n\t\t\t\t// http://soundfile.sapp.org/doc/WaveFormat/\n\t\t\t\ttype = read() & 0xff | (read() & 0xff) << 8;\n\n\t\t\t\tif (type == 0x0055) return; // Handle MP3 in constructor instead\n\t\t\t\tif (type != 0x0001 && type != 0x0003) throw new GdxRuntimeException(\n\t\t\t\t\t\"WAV files must be PCM, unsupported format: \" + getCodecName(type) + \" (\" + type + \")\");\n\n\t\t\t\tchannels = read() & 0xff | (read() & 0xff) << 8;\n\t\t\t\tsampleRate = read() & 0xff | (read() & 0xff) << 8 | (read() & 0xff) << 16 | (read() & 0xff) << 24;\n\n\t\t\t\tskipFully(6);\n\n\t\t\t\tbitDepth = read() & 0xff | (read() & 0xff) << 8;\n\t\t\t\tif (type == 0x0001) { // PCM\n\t\t\t\t\tif (bitDepth != 8 && bitDepth != 16)\n\t\t\t\t\t\tthrow new GdxRuntimeException(\"PCM WAV files must be 8 or 16-bit: \" + bitDepth);\n\t\t\t\t} else if (type == 0x0003) { // Float\n\t\t\t\t\tif (bitDepth != 32 && bitDepth != 64)\n\t\t\t\t\t\tthrow new GdxRuntimeException(\"Floating-point WAV files must be 32 or 64-bit: \" + bitDepth);\n\t\t\t\t}\n\n\t\t\t\tskipFully(fmtChunkLength - 16);\n\n\t\t\t\tdataRemaining = seekToChunk('d', 'a', 't', 'a');\n\t\t\t} catch (Throwable ex) {\n\t\t\t\tStreamUtils.closeQuietly(this);\n\t\t\t\tthrow new GdxRuntimeException(\"Error reading WAV file: \" + file, ex);\n\t\t\t}\n\t\t}\n\n\t\tprivate int seekToChunk (char c1, char c2, char c3, char c4) throws IOException {\n\t\t\twhile (true) {\n\t\t\t\tboolean found = read() == c1;\n\t\t\t\tfound &= read() == c2;","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/libgdx/libgdx/blob/97f40861878058087be0685ca167ddfde132134b/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/audio/Wav.java#L94-L130","documentation":"For format tag 0x0001 (integer PCM), WavInputStream only accepts bitDepth of 8 or 16 — the widths the fixed OpenAL PCM path handles. Values such as 24 or 32-bit integer PCM throw with the offending depth printed.","triggerScenarios":"Loading a PCM WAV with 24-bit samples (very common studio default) or 32-bit integer samples; the check happens right after reading the 2-byte bits-per-sample field of the fmt chunk.","commonSituations":"Pro Tools/Ableton/Reaper default exports at 24-bit; libraries handing 32-bit int PCM; users assuming '32' works because float32 WAVs do (tag 3 is a different branch).","solutions":["Re-export or convert to 16-bit PCM WAV for shipped assets.","If you need >16-bit precision, export as 32-bit FLOAT WAV (format tag 3), which is accepted.","For 24-bit masters: dither down to 16-bit in your audio tool, not by renaming."],"exampleFix":"// before: 24-bit PCM export throws\n// after: ffmpeg -i in24.wav -c:a pcm_s16le in16.wav\nSound s = Gdx.audio.newSound(Gdx.files.internal(\"in16.wav\"));","handlingStrategy":"validation","validationCode":"if (fmtTag == 1 && bitsPerSample != 8 && bitsPerSample != 16)\n    throw new IllegalArgumentException(\"PCM WAV must be 8/16-bit, got \" + bitsPerSample);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Change the DAW/project export preset to 16-bit PCM.","Prefer float32 over 24-bit int if >16-bit headroom is needed."],"tags":["audio","libgdx","wav","pcm","bit-depth"],"backgroundTag":null,"analyzedSha":"97f40861878058087be0685ca167ddfde132134b","analyzedAt":"2026-08-14T10:52:53.492Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}