Skip to content

Commit a0f2171

Browse files
authored
fix(synth): let a local initialAttenuation replace the global zone value (#2994)
1 parent 6c5b7f9 commit a0f2171

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎packages/alphatab/src/synth/synthesis/Region.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export class Region {
333333
this.loopStart += TypeConversions.int16ToUint32(amount.shortAmount) * 32768;
334334
break;
335335
case GenOperators.InitialAttenuation:
336-
this.attenuation += amount.shortAmount * 0.1;
336+
this.attenuation = amount.shortAmount * 0.1;
337337
break;
338338
case GenOperators.EndloopAddrsCoarseOffset:
339339
this.loopEnd += TypeConversions.int16ToUint32(amount.shortAmount) * 32768;

‎packages/alphatab/test/audio/AlphaSynth.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import type { Score } from '@coderline/alphatab/model/Score';
1919
import { Settings } from '@coderline/alphatab/Settings';
2020
import { AlphaSynth } from '@coderline/alphatab/synth/AlphaSynth';
2121
import { AudioExportOptions } from '@coderline/alphatab/synth/IAudioExporter';
22-
import { Hydra } from '@coderline/alphatab/synth/soundfont/Hydra';
22+
import { Hydra, HydraGenAmount } from '@coderline/alphatab/synth/soundfont/Hydra';
2323
import { SynthConstants } from '@coderline/alphatab/synth/SynthConstants';
24+
import { GenOperators, Region } from '@coderline/alphatab/synth/synthesis/Region';
2425
import { TinySoundFont } from '@coderline/alphatab/synth/synthesis/TinySoundFont';
2526
import { Mdct } from '@coderline/alphatab/synth/vorbis/Mdct';
2627
import { VorbisDecoder } from '@coderline/alphatab/synth/vorbis/VorbisDecoder';
@@ -522,4 +523,19 @@ describe('AlphaSynthTests', () => {
522523

523524
await testPlaythrough(midi);
524525
});
526+
527+
it('soundfont-attenuation-local-overrides-global', () => {
528+
const attenuation = GenOperators.InitialAttenuation as number;
529+
const amount = (v: number) =>
530+
new HydraGenAmount(ByteBuffer.fromBuffer(new Uint8Array([v & 0xff, (v >> 8) & 0xff])));
531+
const globalZone = new Region();
532+
globalZone.clear(true);
533+
globalZone.operator(attenuation, amount(100));
534+
const localZone = new Region(globalZone);
535+
expect(localZone.attenuation).toBeCloseTo(10);
536+
localZone.operator(attenuation, amount(60));
537+
expect(localZone.attenuation).toBeCloseTo(6);
538+
localZone.operator(attenuation, amount(0));
539+
expect(localZone.attenuation).toBe(0);
540+
});
525541
});

0 commit comments

Comments
 (0)