Audio buffer size
Latency-sensitive scenarios pull the buffer down: on iOS or a mobile browser under scroll load, a small buffer keeps a mixer's Solo button responsive. Stability-sensitive scenarios push it back up: on a shared desktop with a busy audio thread, a larger buffer prevents dropouts. alphaTab's synth renders audio in chunks, and player.bufferTimeInMilliseconds sets how much of the future the synth generates before the backend consumes it โ smaller chunks respond to changes faster, larger chunks survive slower CPUs without glitching.
The knobโ
player.bufferTimeInMilliseconds is a single number, measured in milliseconds of audio. Default is 500.
- Lower it (
100-250ms) when you need responsive live tweaks โ volume sliders, per-track mute buttons, real-time output-device switches. Users hear changes almost immediately. - Raise it (
750-1500ms) when you see or hear crackling on lower-end devices, mobile browsers under heavy scroll load, or shared hosts that starve the audio thread. The synth builds a larger cushion against dropouts.
You can change the value at any time; the synth honors the new size on its next buffer fill. There is no reload needed.
What "latency" means hereโ
Reducing the buffer does not shrink the delay between hitting Play and hearing the first note โ that's dominated by the platform's audio hardware and the JavaScript / native audio stack. The buffer determines how long it takes a change already in flight (a new volume, a track mute, a metronome toggle) to appear in the audio you actually hear.
Show it in codeโ
import * as alphaTab from '@coderline/alphatab';
const container = getAlphaTabContainer();
const api = new alphaTab.AlphaTabApi(container, {
core: { file: '/scores/song.gp' },
player: {
playerMode: alphaTab.PlayerMode.EnabledSynthesizer,
bufferTimeInMilliseconds: 250,
},
});
// Drop the buffer further when the user opens the mixer for live tweaks.
function enterMixerMode() {
api.settings.player.bufferTimeInMilliseconds = 100;
api.updateSettings();
}
// Restore the safer default on constrained hardware or when the mixer closes.
function exitMixerMode() {
api.settings.player.bufferTimeInMilliseconds = 500;
api.updateSettings();
}
getAlphaTabContainer() is a placeholder for the platform-specific step of obtaining the render target โ a <div> on Web, an AlphaTab control on .NET, or an AlphaTabView on Android. Every other line runs unchanged on all three runtimes.
Where to look nextโ
player.bufferTimeInMillisecondsin the settings reference.- Selecting an output device โ routing decisions that interact with buffer sizing.
- Web Audio and AudioWorklet โ the browser backend that consumes the buffered samples.
- The MIDI event stream โ the buffer size directly governs how far behind the audio the event notifications arrive.