Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
Major update of the ResidentSf2Synth
Browse files Browse the repository at this point in the history
See issue #26:
I've just completed a detailed review of the code while
looking as closely as possible at the SoundFont 2.04 specification.
The terminology is a nightmare, but I understand a lot more now,
and am confident that the parsing is working correctly. (At least
of the variables that are currently being used.)
Made a lot of changes to the code, and have given up trying to
document the changes I made to the original gree version.
The most important/drastic correction was to the way envelope
decay times are calculated. The above noteOff function has now
become much simpler (!).
I've tested this version on the Assistant Performer (using just the
Arachno Grand Piano), and on the WebMIDISynthHost (using all
the available presets there). It has to be said that the Grand Piano
does not yet sound as good as it does on the VirtualMIDISynth, so
 there's still some work to do. (I think that work would be best
done by people who are experts with the Web Audio API.)
I've left extensive comments in the code, and think that the
soundFont parsing is now complete and substantially bug-free.
The tweeking will have to be done in only a few functions:
createKeyInfo() in soundFont.js, and the functions in
soundFontSynthNote.js (All the necessary variables have been set.
It will usually just be a case of deciding what to do with them, and
fixing decimal point positions...).
Note: There were some artefacts at loop endings when I first tested
the French Horn in the WebMIDISynthHost. Second time round,
everything was very clean.
The code is uncompressed and currently very verbose. Maybe some
optimization will have to be done, or compromises made, before
this code works perfecly.
  • Loading branch information
notator committed Sep 1, 2017
1 parent c354c59 commit be20ec5
Show file tree
Hide file tree
Showing 4 changed files with 631 additions and 494 deletions.
41 changes: 21 additions & 20 deletions residentSf2Synth/residentSf2Synth.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,11 @@ WebMIDI.residentSf2Synth = (function(window)
{
var bnkIndex = (channel === 9) ? 128 : bankIndex,
bank = bankSet[bnkIndex],
instrument,
instrumentKey,
presetLayers,
keyLayers,
note,
panpot = channelPanpot[channel] - 64,
midi = {},
pan = channelPanpot[channel] - 64,
bankIndexStr, instrStr, channelStr;

// *Setting* the pitchBendSensitivity should be done by
Expand All @@ -450,38 +451,38 @@ WebMIDI.residentSf2Synth = (function(window)
return;
}

instrument = bank[channelInstrument[channel]];
if(instrument === undefined)
presetLayers = bank[channelInstrument[channel]];
if(presetLayers === undefined)
{
bankIndexStr = bnkIndex.toString(10);
instrStr = (channelInstrument[channel]).toString(10);
channelStr = channel.toString(10);
console.warn("instrument not found: bank=" + bankIndexStr + " instrument=" + instrStr + " channel=" + channelStr);
console.warn("presetLayers not found: bank=" + bankIndexStr + " presetLayers=" + instrStr + " channel=" + channelStr);
return;
}

instrumentKey = instrument[key];
if(!instrumentKey)
keyLayers = presetLayers[key];
if(!keyLayers)
{
bankIndexStr = bnkIndex.toString(10);
instrStr = (channelInstrument[channel]).toString(10);
channelStr = channel.toString(10);
console.warn("instrument key not found: bank=" + bankIndexStr + " instrument=" + instrStr + " channel=" + channelStr + " key=" + key);
console.warn("presetLayers[key] not found: bank=" + bankIndexStr + " presetLayers=" + instrStr + " channel=" + channelStr + " key=" + key);
return;
}

panpot /= panpot < 0 ? 64 : 63;
pan /= pan < 0 ? 64 : 63;

instrumentKey.channel = channel;
instrumentKey.key = key;
instrumentKey.velocity = velocity;
instrumentKey.panpot = panpot;
instrumentKey.volume = channelVolume[channel] / 127;
instrumentKey.pitchBend = channelPitchBend[channel] - 8192;
instrumentKey.pitchBendSensitivity = getPitchBendSensitivity(channel);
midi.channel = channel;
midi.key = key;
midi.velocity = velocity;
midi.pan = pan;
midi.volume = channelVolume[channel] / 127;
midi.pitchBend = channelPitchBend[channel] - 8192;
midi.pitchBendSensitivity = getPitchBendSensitivity(channel);

// note on
note = new WebMIDI.soundFontSynthNote.SoundFontSynthNote(ctx, gainMaster, instrumentKey);
note = new WebMIDI.soundFontSynthNote.SoundFontSynthNote(ctx, gainMaster, keyLayers, midi);
note.noteOn();
currentNoteOns[channel].push(note);
};
Expand Down Expand Up @@ -534,9 +535,9 @@ WebMIDI.residentSf2Synth = (function(window)
channelVolume[channel] = volume;
};

ResidentSf2Synth.prototype.panpotChange = function(channel, panpot)
ResidentSf2Synth.prototype.panpotChange = function(channel, pan)
{
channelPanpot[channel] = panpot;
channelPanpot[channel] = pan;
};

ResidentSf2Synth.prototype.pitchBend = function(channel, lowerByte, higherByte)
Expand Down
Loading

0 comments on commit be20ec5

Please sign in to comment.