SoundFont local initialAttenuation does not override global attenuation, making affected presets too quiet
I maintainer di solito rispondono entro 1 giorno
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Is there an existing issue for this?
- I have searched the existing issues
I have read the contribution rules
- I have read CONTRIBUTING.md and, if any AI agent helped draft this issue, AGENTS.md.
AI authorship
AI-assisted (disclosure block included as described in AGENTS.md)
Current Behavior
[!NOTE]
AI-authored disclosure (alphatab-ai-authored-v1)Portions of this content were authored by an AI agent. The agent has read
AGENTS.md and the human submitter accepts responsibility for
compliance with the rules in that document.
With the official npm package @coderline/[email protected], two SoundFonts that should be equivalent produce different PCM levels when one contains a global initialAttenuation value that is overridden locally.
For example, a preset with global attenuation = 200 cB and local attenuation = 120 cB renders at 32 dB attenuation, instead of 12 dB. Removing only the overridden global value makes the output 20 dB louder. The sample, MIDI note, velocity, channel controls, and export settings are identical. The same behavior occurs at the instrument level, including an explicit local value of zero.
This was initially noticed as unusually quiet overdriven guitar playback. The reproduction below uses program 0 and an original generated sine-wave sample, so it does not depend on a particular commercial SoundFont, guitar preset, application, or private score.
Measured attenuation relative to the identical unattenuated fixture:
| Case | Expected dB | Actual dB in 1.8.4 |
|---|---|---|
| Preset global 200 cB, local 120 cB | 12 | 32 |
| Instrument global 127 cB, local 50 cB | 5 | 17.7 |
| Both of the above | 17 | 49.7 |
| Missing locals: preset global 200 cB + instrument global 50 cB | 25 | 25 |
| Preset global 200 cB, local 0; instrument local 50 cB | 5 | 25 |
| Preset local 120 cB; instrument global 127 cB, local 0 | 12 | 24.7 |
| Preset local 120 cB + instrument local 50 cB | 17 | 17 |
| Preset local -60 cB + instrument local 100 cB | 4 | 4 |
| No attenuation generators | 0 | 0 |
Expected Behavior
A local initialAttenuation generator should replace the corresponding global generator at the same level. An omitted local value should inherit the global value; an explicit zero should override it. After resolving each level, preset attenuation should still be added to instrument attenuation.
The two equivalent preset fixtures (global 200 cB/local 120 cB versus local 120 cB alone) should therefore have identical output.
Normative basis: SoundFont 2.04 specification, section 9.4, PDF pages 50–51. It specifies local-over-global replacement separately at the instrument and preset levels, and addition between the preset and instrument levels. Section 9.3 defines one centibel as one tenth of a decibel.
Steps To Reproduce
- Create an empty directory and install the pinned official package:
npm init -y
npm install --ignore-scripts --save-exact @coderline/[email protected]
- Save the following as
repro.cjs. - Run
node repro.cjs(tested with Node v24.11.1). - It prints the table shown above and exits with an assertion failure: five override cases fail, while the four control cases pass. All SF2 data and the MusicXML score are generated in memory; no external assets are required.
Self-contained reproduction: repro.cjs
const assert = require('node:assert/strict');
const alphaTab = require('@coderline/alphatab');
// Build an original, looping sine-wave SF2 in memory. Generator 48 uses centibels.
function sf2({ pg, pl, ig, il } = {}) {
const words = (size, values) => {
const b = Buffer.alloc(size * values.length);
values.forEach((v, i) => size === 2 ? b.writeUInt16LE(v & 65535, i * size) : b.writeUInt32LE(v, i * size));
return b;
};
const u16 = (...v) => words(2, v), u32 = (...v) => words(4, v);
const name = s => { const b = Buffer.alloc(20); b.write(s); return b; };
const chunk = (id, ...parts) => {
const body = Buffer.concat(parts);
return Buffer.concat([Buffer.from(id), u32(body.length), body, Buffer.alloc(body.length % 2)]);
};
function zones(global, local, terminal) {
const gens = [], bags = [u16(0, 0)];
if (global !== undefined) { gens.push(u16(48, global)); bags.push(u16(gens.length, 0)); }
if (local !== undefined) gens.push(u16(48, local));
gens.push(...terminal);
bags.push(u16(gens.length, 0));
gens.push(u16(0, 0));
return { bags: Buffer.concat(bags), gens: Buffer.concat(gens), count: bags.length - 1 };
}
const p = zones(pg, pl, [u16(41, 0)]);
const i = zones(ig, il, [u16(54, 1), u16(53, 0)]);
const pcm = Buffer.alloc((512 + 46) * 2);
for (let n = 0; n < 512; n++) pcm.writeInt16LE(Math.round(8000 * Math.sin(2 * Math.PI * n / 64)), n * 2);
return chunk('RIFF', Buffer.from('sfbk'),
chunk('LIST', Buffer.from('INFO'), chunk('ifil', u16(2, 1))),
chunk('LIST', Buffer.from('sdta'), chunk('smpl', pcm)),
chunk('LIST', Buffer.from('pdta'),
chunk('phdr', name('Test'), u16(0, 0, 0), u32(0, 0, 0), name('EOP'), u16(0, 0, p.count), u32(0, 0, 0)),
chunk('pbag', p.bags), chunk('pmod', Buffer.alloc(10)), chunk('pgen', p.gens),
chunk('inst', name('Test'), u16(0), name('EOI'), u16(i.count)),
chunk('ibag', i.bags), chunk('imod', Buffer.alloc(10)), chunk('igen', i.gens),
chunk('shdr', name('Sine'), u32(0, 512, 64, 448, 22050), Buffer.from([60, 0]), u16(0, 1),
name('EOS'), u32(512, 512, 512, 512, 0), Buffer.from([0, 0]), u16(0, 1))));
}
const xml = `<score-partwise version="4.0"><part-list><score-part id="P">
<part-name>Test</part-name><score-instrument id="I"><instrument-name>Test</instrument-name></score-instrument>
<midi-instrument id="I"><midi-channel>1</midi-channel><midi-program>1</midi-program></midi-instrument>
</score-part></part-list><part id="P"><measure number="1"><attributes><divisions>1</divisions>
<time><beats>4</beats><beat-type>4</beat-type></time><clef><sign>G</sign><line>2</line></clef></attributes>
<direction><sound tempo="96"/></direction><note><pitch><step>C</step><octave>4</octave></pitch>
<duration>4</duration><type>whole</type></note></measure></part></score-partwise>`;
const score = alphaTab.importer.ScoreLoader.loadScoreFromBytes(new TextEncoder().encode(xml));
const midi = new alphaTab.midi.MidiFile();
const generator = new alphaTab.midi.MidiFileGenerator(score, new alphaTab.Settings(), new alphaTab.midi.AlphaSynthMidiFileHandler(midi));
generator.generate();
class Event { on(f) { this.f = f; } trigger() { this.f?.(); } }
function render(parameters) {
// Offline output adapter: no browser, audio device, network, or external SF2 needed.
const output = {
sampleRate: 44100, ready: new Event(), sampleRequest: new Event(), samplesPlayed: new Event(),
open() { this.ready.trigger(); }, destroy() {}, pause() {}, play() {}, resetSamples() {}, addSamples() {}
};
const synth = new alphaTab.synth.AlphaSynth(output, 200);
const options = new alphaTab.synth.AudioExportOptions();
options.soundFonts = [sf2(parameters)];
const exporter = synth.exportAudio(options, midi, generator.syncPoints, generator.transpositionPitches);
return exporter.render(400).samples;
}
const rms = samples => Math.sqrt(samples.reduce((sum, v) => sum + v * v, 0) / samples.length);
const reference = rms(render({}));
assert.ok(reference > 0.0001, 'Reference must be audible');
const cases = [
['preset override', { pg: 200, pl: 120 }, 12],
['instrument override', { ig: 127, il: 50 }, 5],
['both overrides', { pg: 200, pl: 120, ig: 127, il: 50 }, 17],
['inherit missing locals', { pg: 200, ig: 50 }, 25],
['preset zero override', { pg: 200, pl: 0, il: 50 }, 5],
['instrument zero override', { pl: 120, ig: 127, il: 0 }, 12],
['cross-level addition', { pl: 120, il: 50 }, 17],
['negative preset offset', { pl: -60, il: 100 }, 4],
['default', {}, 0]
];
const results = cases.map(([name, parameters, expectedDb]) => {
const actualDb = -20 * Math.log10(rms(render(parameters)) / reference);
return { name, expectedDb, actualDb: Number(actualDb.toFixed(4)), pass: Math.abs(actualDb - expectedDb) < 0.00001 };
});
console.table(results);
assert.ok(results.every(r => r.pass), 'Local attenuation must replace global attenuation at the same level');
Link to jsFiddle, CodePen, Project
No response
Version and Environment
[Actual output from alphaTab.Environment.printEnvironmentInfo()]
[AlphaTab][VersionInfo] alphaTab 1.8.4
[AlphaTab][VersionInfo] commit: 022a45c8e42370f9e12e68949d11eada370da83d
[AlphaTab][VersionInfo] build date: 2026-07-05T14:46:18.224Z
[AlphaTab][VersionInfo] High DPI: 1
[AlphaTab][VersionInfo] Platform: NodeJs
[AlphaTab][VersionInfo] WebPack: false
[AlphaTab][VersionInfo] Vite: false
Node v24.11.1; process.platform = darwin; process.arch = arm64.
Official npm 1.8.4 tarball verified against its registry SHA512 integrity value.
Offline PCM export at 44100 Hz; no browser or audio device is required.
Platform
Node.js
Anything else?
The reproduction measures PCM from the public AlphaSynth export API, rather than inferring the behavior from internal fields. It also includes passing controls for inheritance, cross-level addition, signed preset offsets, and the default gain.
The generated sine wave, MusicXML, and SF2 are contained entirely in the script; no external score, sample library, or hosted reproduction is required. No files are uploaded separately.
- Lingua principale
- TypeScript
- Stelle
- 1.9k
- Fork
- 297
- Merge medio
- 3h 55m
- PR unite (30g)
- 53
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di CoderLine/alphaTab
-
Respect systems layout of MusicXMLForse già presa @Danielku15 l’ha presa 25 giorni fa. Aperta
CoderLine/alphaTab#2909 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Expose Lyrics in public apiForse già presa @Danielku15 l’ha presa 25 giorni fa. Aperta
CoderLine/alphaTab#2908 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Show accentuations on tab-only stavesForse già presa @Danielku15 l’ha presa 25 giorni fa. Aperta
CoderLine/alphaTab#2906 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Support tuning alterationsForse già presa @kulek1 l’ha presa 77 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
Add Optional Settings below-tab lyric placement for tab-only and standard+tab layoutsForse di nuovo libera @Danielku15 l’ha presa 112 giorni fa e non c’è nessuna pull request aperta. Aperta
CoderLine/alphaTab#2776 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di CoderLine/alphaTab
Issue simili
-
Replace discontinued crypto-js in the themeForse già presa @aelmanaa l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
PaloAltoNetworks/docusaurus-openapi-docs#1689 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
solana-foundation/solana-web3.js#4015 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
formatSearchQuery drops the :present modifier, so `email:present=true` is sent as `email=true`Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 1/5 1-3 ore Idoneità per principianti 90/100
ivopogace/opencode-courier#422 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
chapel-lang/chapel-vscode#158 ·
I maintainer di solito rispondono entro 1 giorno