Skip to content

Commit

Permalink
Corrected master volume calculation (resolves #399)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielku15 committed Sep 9, 2020
1 parent 2ad19bd commit 10e3632
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/synth/AlphaSynth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ export class AlphaSynth implements IAlphaSynth {
}

public get masterVolume(): number {
return this._synthesizer.globalGainDb;
return this._synthesizer.masterVolume;
}

public set masterVolume(value: number) {
value = SynthHelper.clamp(value, SynthConstants.MinVolume, SynthConstants.MaxVolume);
this._synthesizer.globalGainDb = value;
this._synthesizer.masterVolume = value;
}

public get metronomeVolume(): number {
Expand Down
23 changes: 22 additions & 1 deletion src/synth/synthesis/TinySoundFont.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,27 @@ export class TinySoundFont {
}
}


public get masterVolume(): number {
return SynthHelper.decibelsToGain(this.globalGainDb);
}

public set masterVolume(value: number) {
var gainDb = SynthHelper.gainToDecibels(value);
const gainDBChange: number = gainDb - this.globalGainDb;
if (gainDBChange === 0) {
return;
}

for (const v of this._voices) {
if (v.playingPreset !== -1) {
v.noteGainDb += gainDBChange;
}
}

this.globalGainDb = gainDb;
}

/**
* Stop all playing notes immediatly and reset all channel parameters but keeps user
* defined settings
Expand Down Expand Up @@ -1016,7 +1037,7 @@ export class TinySoundFont {
: 0.0;
}

public resetPresets():void {
public resetPresets(): void {
this.presets = [];
}

Expand Down

0 comments on commit 10e3632

Please sign in to comment.