SoundFont local initialAttenuation does not override global attenuation, making affected presets too quiet
维护者通常 1 天内回复
@Danielku15 已经在做这个了。
开始于 2026年10月27日。
评估
这个 Issue 还没有评估数据。
描述
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.
- 主要语言
- TypeScript
- 星标
- 1.9k
- 派生
- 297
- 平均合并
- 9 小时 41 分钟
- 30 天内合并 PR
- 41
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
CoderLine/alphaTab 的其他 Issue
-
ai-authored
难度 2/5 1-3 小时 新手友好度 69/100
维护者通常 1 天内回复
-
Fade out: track silent until the end可能已有人在做 @Danielku15 于 2 天前认领。 未关闭
CoderLine/alphaTab#2978 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Rendering issue: Unable to switch to Numbered Notation (jianpu) for specific tracks in v1.8.4可能已有人在做 @Danielku15 于 3 天前认领。 未关闭
CoderLine/alphaTab#2976 · 3 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
ai-authored
难度 3/5 1-2 天 新手友好度 66/100
维护者通常 1 天内回复
-
Respect systems layout of MusicXML可能已有人在做 @Danielku15 于 24 天前认领。 未关闭
CoderLine/alphaTab#2909 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 CoderLine/alphaTab 的全部 Issue
相似的 Issue
-
Parallel reticle_verify opens per-flow leases without the source lease's ignoreHTTPSErrors可能已有人在做 @as992949791 今天认领。 未关闭good first issue help wanted
难度 2/5 1-3 小时 新手友好度 85/100
reticlehq/reticle#2033 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
area:quality p3-medium ready-for-agent type:docs
难度 2/5 1-3 小时 新手友好度 83/100
fderuiter/deruiter.dev#3589 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
manfredsteyer/angular-oauth2-oidc#1514 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
marmelab/react-admin#11431 ·
维护者通常 1 天内回复