Indie dev efficiency3 min read

Web Audio hits shift after compression? Measure lookahead with an impulse

Render a dry and compressed impulse offline to distinguish compressor lookahead from silence already baked into a game sound.

Web Audio hits shift after compression? Measure lookahead with an impulse
Two audio tracks with the lower impulse shifted to the right
Concept illustration

A hit that sounds sharp in isolation can become a double tick when the game mixes a dry layer with a compressed copy. Use a synthetic impulse to measure the compressor branch before trimming silence from the source asset.

Measure the graph offline at 48 kHz

  1. Make a 48 kHz OfflineAudioContext and a mono test buffer. Write a 0.5 impulse at zero-based sample 480 and leave the rest silent. Render at least 4,800 samples. Split the same source into a direct route and a route containing only a DynamicsCompressorNode.
  2. Wire dry to input 0 and compressed to input 1 on a ChannelMergerNode. In the rendered buffer, find the first sample with absolute amplitude above 1e-5 in each channel. Verify both signals actually arrived. Subtract the dry index from the compressed index and divide by the sample rate.
  3. The Web Audio reference graph uses 6 ms of lookahead, equivalent to 288 samples at 48 kHz. Expect roughly sample 768 against the dry reference at 480. Record the exact indices from your target browser along with the graph and sample rate.

Repeat with a real hit

Use Image & Audio Compressor to check the delivery size of companion audio files. Keep the original hit for this test and use the same decoded buffer on both branches. If the layers must play in parallel, try delaying the dry layer by the measured amount within that mix group and check the resulting input-to-sound timing. A zero attack affects how gain responds. The pre-delay in the reference graph and the device's output latency are separate.

Ready to try "Web Audio hits shift after compression? Measure lookahead with an impulse"?

Use our online tools to apply this tutorial to your indie game project right away.