Skip to content
QuaAudio
On this page

Quack solid bundling

Bundle game audio automatically in @quajs/quack with latency-aware .qaa streaming separation, sharded .qaab banks, and transparent QAAR stubs.

@quajs/quaaudio/quack connects QuaAudio directly to Quack (@quajs/quack), QuaEngine's asset packager, so games gain cross-track solid compression without rewriting any .qs script paths.

Enabling in quack.config.ts

TypeScript
import { defineConfig } from '@quajs/quack'export default defineConfig({ source: './assets', output: './dist/game.qpk', format: 'qpk', // Default: spectral lossless + cross-track .qaab solid banks with QAAR pointers solidAudio: true, // Or configure perceptual spatial VBR with a target compression ratio: // solidAudio: { mode: 'lossy', targetRatio: 12 },})

Latency-aware packing strategy

packAudioAssetsIntoSolidBank(assets, options) splits audio assets by duration so streaming music and short voice/SFX clips each get optimal layout:

  1. Long tracks (duration >= streamThresholdSeconds, default 15 seconds, e.g., BGM):
    • Encoded as standalone seekable .qaa payloads (mimeType = 'audio/x-quaaudio') at their original logical path.
    • Enables O(1)-memory cluster streaming via QaaStreamDecoder without decompressing an entire multi-track solid chunk.
  2. Short & medium clips (< 15 seconds, e.g., dialogue & SFX):
    • Sorted by (localePrefix, dirname, relativePath) to keep related directory assets together, then acoustically ordered inside .qaab.
    • Partitioned by maxBankRawBytes (default 8 MiB raw PCM per shard, typically ~500 KiB – 1.2 MiB on disk) into data/__quaaudio__/solid.qaab, data/__quaaudio__/solid.0001.qaab, and so on.
    • Original asset entries retain their logical path (e.g., audio/voice/ch01/001.ogg), storing a compact QAAR pointer stub (mimeType = 'audio/x-quaaudio-ref') carrying bankPath and trackKey (${localePrefix}:${relativePath}).

Tip: Set streamThresholdSeconds to 0 or Infinity to force all audio into .qaab shards, or set solidBank: false to emit standalone .qaa tracks for every asset.

Per-asset QuaAudioPlugin

For custom Quack plugin pipelines that transcode tracks individually to .qaa:

TypeScript
import { QuaAudioPlugin } from '@quajs/quaaudio/quack'const plugin = new QuaAudioPlugin({ mode: 'lossy', targetRatio: 12, rewriteExtension: false, // Default: keeps @PlayBGM('audio/bgm/night.ogg') paths intact})

Source format decoding & ffmpeg

WAV and existing .qaa buffers decode directly inside QuaAudio with zero subprocess calls. Other extensions (.ogg, .opus, .mp3, .flac, .aac, .m4a) are decoded to 24-bit lossless pcm_s24le WAV via ffmpeg:

  • Streams over pipe:0 / pipe:1 first to avoid temporary disk writes;
  • Falls back cleanly to a temporary file for seek-dependent containers such as .m4a;
  • Supports custom ffmpegBinary paths and allowPassthroughOnDecodeError: true when mock/placeholder audio buffers appear in tests.