Skip to content

Commit

Permalink
limit generators at modulator level
Browse files Browse the repository at this point in the history
  • Loading branch information
spessasus committed Sep 29, 2024
1 parent b56b2fa commit f074e9d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SpessaSynth",
"version": "3.20.32",
"version": "3.20.33",
"type": "module",
"scripts": {
"start": "node src/website/server/server.js"
Expand Down
2 changes: 1 addition & 1 deletion src/spessasynth_lib/soundfont/read_sf2/generators.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ generatorLimits[generatorTypes.initialAttenuation] = {min: -250, max: 1440, def:
generatorLimits[generatorTypes.endloopAddrsCoarseOffset] = {min: -32768, max: 32768, def: 0};

generatorLimits[generatorTypes.coarseTune] = {min: -120, max: 120, def: 0};
generatorLimits[generatorTypes.fineTune] = {min: -99, max: 99, def: 0};
generatorLimits[generatorTypes.fineTune] = {min: -12700, max: 12700, def: 0}; // this generator is used as initial pitch, hence this range
generatorLimits[generatorTypes.scaleTuning] = {min: 0, max: 1200, def: 100};
generatorLimits[generatorTypes.exclusiveClass] = {min: 0, max: 99999, def: 0};
generatorLimits[generatorTypes.overridingRootKey] = {min: 0-1, max: 127, def: -1};
Expand Down
18 changes: 9 additions & 9 deletions src/spessasynth_lib/synthetizer/worklet_processor.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { modulatorSources } from '../../../soundfont/read_sf2/modulators.js'
import { getModulatorCurveValue, MOD_PRECOMPUTED_LENGTH } from './modulator_curves.js'
import { NON_CC_INDEX_OFFSET } from './worklet_processor_channel.js'
import { generatorTypes } from '../../../soundfont/read_sf2/generators.js'
import { generatorLimits, generatorTypes } from '../../../soundfont/read_sf2/generators.js'
import { WorkletVolumeEnvelope } from './volume_envelope.js'
import { WorkletModulationEnvelope } from './modulation_envelope.js'

Expand Down Expand Up @@ -123,7 +123,10 @@ export function computeModulators(voice, controllerTable, sourceUsesCC = -1, sou
// All modulators mode: compute all modulators
modulatedGenerators.set(generators);
modulators.forEach(mod => {
modulatedGenerators[mod.modulatorDestination] += computeWorkletModulator(controllerTable, mod, voice);
const limits = generatorLimits[mod.modulatorDestination];
if(modulatedGenerators[mod.modulatorDestination] === limits.min || modulatedGenerators[mod.modulatorDestination] === limits.max) return;
const newValue = modulatedGenerators[mod.modulatorDestination] + computeWorkletModulator(controllerTable, mod, voice);
modulatedGenerators[mod.modulatorDestination] = Math.max(limits.min, Math.min(newValue, limits.max));
});
WorkletVolumeEnvelope.recalculate(voice);
return;
Expand Down Expand Up @@ -158,7 +161,11 @@ export function computeModulators(voice, controllerTable, sourceUsesCC = -1, sou
modulators.forEach(m => {
if (m.modulatorDestination === destination)
{
modulatedGenerators[destination] += computeWorkletModulator(controllerTable, m, voice);
const limits = generatorLimits[mod.modulatorDestination];
const current = modulatedGenerators[mod.modulatorDestination];
if(current === limits.min || current === limits.max) return;
const newValue = current + computeWorkletModulator(controllerTable, m, voice);
modulatedGenerators[mod.modulatorDestination] = Math.max(limits.min, Math.min(newValue, limits.max));
}
});
computedDestinations.add(destination);
Expand All @@ -183,16 +190,16 @@ const transforms = [];
for(let curve = 0; curve < 4; curve++)
{
transforms[curve] =
[
[
new Float32Array(MOD_PRECOMPUTED_LENGTH),
new Float32Array(MOD_PRECOMPUTED_LENGTH)
],
[
new Float32Array(MOD_PRECOMPUTED_LENGTH),
new Float32Array(MOD_PRECOMPUTED_LENGTH)
]
];
[
new Float32Array(MOD_PRECOMPUTED_LENGTH),
new Float32Array(MOD_PRECOMPUTED_LENGTH)
],
[
new Float32Array(MOD_PRECOMPUTED_LENGTH),
new Float32Array(MOD_PRECOMPUTED_LENGTH)
]
];
for (let i = 0; i < MOD_PRECOMPUTED_LENGTH; i++) {

// polarity 0 dir 0
Expand Down
2 changes: 1 addition & 1 deletion src/website/minified/demo_main.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/website/minified/local_main.min.js

Large diffs are not rendered by default.

0 comments on commit f074e9d

Please sign in to comment.