Skip to content

Commit

Permalink
fix DLS attenuation modulators
Browse files Browse the repository at this point in the history
  • Loading branch information
spessasus committed Nov 10, 2024
1 parent 59c1262 commit 668863c
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 98 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.22.7",
"version": "3.22.8",
"type": "module",
"scripts": {
"start": "node src/website/server/server.js",
Expand Down
64 changes: 60 additions & 4 deletions src/spessasynth_lib/soundfont/dls/articulator_converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { midiControllers } from "../../midi_parser/midi_message.js";
import { DLSDestinations } from "./dls_destinations.js";

import { generatorTypes } from "../basic_soundfont/generator.js";
import { consoleColors } from "../../utils/other.js";

/**
* @param source {number}
Expand Down Expand Up @@ -174,6 +175,48 @@ function checkForSpecialDLSCombo(source, destination)
}
}

/**
* @param source {number}
* @param control {number}
* @param destination {number}
* @param value {number}
* @param transform {number}
*/
function modulatorConverterDebug(
source,
control,
destination,
value,
transform
)
{
const type = Object.keys(DLSDestinations).find(k => DLSDestinations[k] === destination);
const srcType = Object.keys(DLSSources).find(k => DLSSources[k] === source);
const ctrlType = Object.keys(DLSSources).find(k => DLSSources[k] === control);
const typeString = type ? type : destination.toString(16);
const srcString = srcType ? srcType : source.toString(16);
const ctrlString = ctrlType ? ctrlType : control.toString(16);
console.debug(
`%cAttempting to convert the following DLS Articulator to SF2 Modulator:
Source: %c${srcString}%c
Control: %c${ctrlString}%c
Destination: %c${typeString}%c
Amount: %c${value}%c
Transform: %c${transform}%c...`,
consoleColors.info,
consoleColors.recognized,
consoleColors.info,
consoleColors.recognized,
consoleColors.info,
consoleColors.recognized,
consoleColors.info,
consoleColors.recognized,
consoleColors.info,
consoleColors.recognized,
consoleColors.info
);
}

/**
* @param source {number}
* @param control {number}
Expand Down Expand Up @@ -202,6 +245,7 @@ export function getSF2ModulatorFromArticulator(
let sf2Source;
let swapSources = false;
let isSourceNoController = false;
let newValue = value;
if (specialDestination === undefined)
{
// determine destination
Expand All @@ -217,7 +261,7 @@ export function getSF2ModulatorFromArticulator(
destinationGenerator = sf2GenDestination;
if (sf2GenDestination.newAmount !== undefined)
{
value = sf2GenDestination.newAmount;
newValue = sf2GenDestination.newAmount;
destinationGenerator = sf2GenDestination.gen;
}
sf2Source = getSF2SourceFromDLS(source);
Expand Down Expand Up @@ -263,10 +307,22 @@ export function getSF2ModulatorFromArticulator(
}
const sourceIsBipolar = (transform >> 14) & 1;
let sourceIsNegative = (transform >> 15) & 1;
// special case: for attenuation, invert source
// special case: for attenuation, invert source (dls gain is the opposite of sf2 attenuation)
if (destinationGenerator === generatorTypes.initialAttenuation)
{
sourceIsNegative = !sourceIsNegative;
// modulatorConverterDebug(
// source,
// control,
// destination,
// value,
// transform
// );
// invert only if the actual transform value is not negative.
// if it is, it's already inverted
if (value > 0)
{
sourceIsNegative = !sourceIsNegative;
}
}
sourceEnumFinal = getModSourceEnum(
sourceTransform,
Expand Down Expand Up @@ -301,7 +357,7 @@ export function getSF2ModulatorFromArticulator(
secSrcEnum: secSourceEnumFinal,
dest: destinationGenerator,
transform: 0x0,
amt: value
amt: newValue
});

}
42 changes: 0 additions & 42 deletions src/spessasynth_lib/soundfont/dls/read_articulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,6 @@ import { consoleColors } from "../../utils/other.js";
import { Generator, generatorTypes } from "../basic_soundfont/generator.js";
import { Modulator } from "../basic_soundfont/modulator.js";

/**
* @param source {number}
* @param control {number}
* @param destination {number}
* @param value {number}
* @param transform {number}
*/
function modulatorConverterDebug(
source,
control,
destination,
value,
transform
)
{
const type = Object.keys(DLSDestinations).find(k => DLSDestinations[k] === destination);
const srcType = Object.keys(DLSSources).find(k => DLSSources[k] === source);
const ctrlType = Object.keys(DLSSources).find(k => DLSSources[k] === control);
const typeString = type ? type : destination.toString(16);
const srcString = srcType ? srcType : source.toString(16);
const ctrlString = ctrlType ? ctrlType : control.toString(16);
SpessaSynthInfo(
`%cAttempting to convert the following DLS Articulator to SF2 Modulator:
Source: %c${srcString}%c
Control: %c${ctrlString}%c
Destination: %c${typeString}%c
Amount: %c${value}%c
Transform: %c${transform}%c...`,
consoleColors.info,
consoleColors.recognized,
consoleColors.info,
consoleColors.recognized,
consoleColors.info,
consoleColors.recognized,
consoleColors.info,
consoleColors.recognized,
consoleColors.info,
consoleColors.recognized,
consoleColors.info
);
}

/**
* Reads the articulator chunk
Expand Down Expand Up @@ -80,7 +39,6 @@ export function readArticulation(chunk, disableVibrato)
const scale = readLittleEndian(artData, 4) | 0;
const value = scale >> 16; // convert it to 16 bit as soundfont uses that

// modulatorConverterDebug(source, control, destination, value, transform);
// interpret this somehow...
// if source and control are both zero, it's a generator
if (source === 0 && control === 0 && transform === 0)
Expand Down
20 changes: 10 additions & 10 deletions src/spessasynth_lib/synthetizer/worklet_processor.min.js

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions src/website/minified/demo_main.min.js

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions src/website/minified/local_main.min.js

Large diffs are not rendered by default.

0 comments on commit 668863c

Please sign in to comment.