Skip to content

Commit

Permalink
Fix DLS Loops and disable logging by default
Browse files Browse the repository at this point in the history
and finally set loop count in basic_sample.js to samples and not bytes
  • Loading branch information
spessasus committed Oct 6, 2024
1 parent 0d769f6 commit c2899c7
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 76 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.41",
"version": "3.20.42",
"type": "module",
"scripts": {
"start": "node src/website/server/server.js"
Expand Down
4 changes: 2 additions & 2 deletions src/spessasynth_lib/soundfont/basic_soundfont/basic_sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ export class BasicSample {
*/
this.sampleType = sampleType
/**
* Relative to start of the sample, bytes assuming 16 bit
* Relative to start of the sample in sample points
* @type {number}
*/
this.sampleLoopStartIndex = loopStart
/**
* Relative to start of the sample, in bytes assuming 16 bit
* Relative to start of the sample in sample points
* @type {number}
*/
this.sampleLoopEndIndex = loopEnd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export function getSHDR(smplStartOffsets, smplEndOffsets)
const dwEnd = smplEndOffsets[index];
writeDword(shdrData, dwEnd);
// loop is stored as relative in sample points, change it to absolute sample points here
let loopStart = sample.sampleLoopStartIndex / 2 + dwStart;
let loopEnd = sample.sampleLoopEndIndex / 2 + dwStart;
let loopStart = sample.sampleLoopStartIndex + dwStart;
let loopEnd = sample.sampleLoopEndIndex + dwStart;
if(sample.isCompressed)
{
// https://github.com/FluidSynth/fluidsynth/wiki/SoundFont3Format
Expand Down
4 changes: 2 additions & 2 deletions src/spessasynth_lib/soundfont/dls/dls_sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export class DLSSample extends BasicSample
pitchCorrection,
0,
1,
loopStart * 2,
(loopEnd - 1) * 2 // -1 sample because soundfont end is last sample and dls end is next sample
loopStart,
loopEnd - 1 // -1 sample because soundfont end is last sample and dls end is next sample
);
this.sampleData = data;
this.sampleDbAttenuation = sampleDbAttenuation;
Expand Down
12 changes: 6 additions & 6 deletions src/spessasynth_lib/soundfont/dls/dls_zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,28 @@ export class DLSZone extends BasicInstrumentZone
}

// correct loop if needed
const diffStart = loop.start - (sample.sampleLoopStartIndex / 2);
const diffEnd = loop.end - (sample.sampleLoopEndIndex / 2);
const diffStart = loop.start - sample.sampleLoopStartIndex;
const diffEnd = loop.end - sample.sampleLoopEndIndex;
if(diffStart !== 0)
{
const fine = diffStart % 32768;
this.generators.push(new Generator(generatorTypes.startloopAddrsOffset, fine));
// coarse generator uses 32768 samples per step
const coarse = (diffStart - fine) / 32768;
const coarse = Math.trunc(diffStart / 32768);
if(coarse !== 0)
{
this.generators.push(new Generator(generatorTypes.startloopAddrsCoarseOffset, fine));
this.generators.push(new Generator(generatorTypes.startloopAddrsCoarseOffset, coarse));
}
}
if(diffEnd !== 0)
{
const fine = diffEnd % 32768;
this.generators.push(new Generator(generatorTypes.endloopAddrsOffset, fine));
// coarse generator uses 32768 samples per step
const coarse = (diffEnd - fine) / 32768;
const coarse = Math.trunc(diffEnd / 32768);
if(coarse !== 0)
{
this.generators.push(new Generator(generatorTypes.endloopAddrsCoarseOffset, fine));
this.generators.push(new Generator(generatorTypes.endloopAddrsCoarseOffset, coarse));
}
}
// correct key if needed
Expand Down
8 changes: 4 additions & 4 deletions src/spessasynth_lib/soundfont/read_sf2/samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export class LoadedSample extends BasicSample
samplePitchCorrection,
sampleLink,
sampleType,
sampleLoopStartIndex - sampleStartIndex,
sampleLoopEndIndex - sampleStartIndex
sampleLoopStartIndex - (sampleStartIndex / 2),
sampleLoopEndIndex - (sampleStartIndex / 2)
);
this.sampleName = sampleName
// in bytes
Expand Down Expand Up @@ -245,10 +245,10 @@ function readSample(index, sampleHeaderData, smplArrayData, isDataRaw) {
let sampleEndIndex = readLittleEndian(sampleHeaderData, 4) * 2;

// read the sample looping start index
let sampleLoopStartIndex = readLittleEndian(sampleHeaderData, 4) * 2;
let sampleLoopStartIndex = readLittleEndian(sampleHeaderData, 4);

// read the sample looping end index
let sampleLoopEndIndex = readLittleEndian(sampleHeaderData, 4) * 2;
let sampleLoopEndIndex = readLittleEndian(sampleHeaderData, 4);

// read the sample rate
let sampleRate = readLittleEndian(sampleHeaderData, 4);
Expand Down
16 changes: 8 additions & 8 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
Expand Up @@ -22,6 +22,7 @@
* @property {Int8Array} channelOctaveTuning - the channel's octave tuning in cents
* @property {Int16Array} keyCentTuning - tuning of individual keys in cents
* @property {boolean} isMuted - indicates whether the channel is muted
* @property {number} velocityOverride - overrides velocity if > 0 otherwise disabled
* @property {boolean} drumChannel - indicates whether the channel is a drum channel
*/
/**
Expand Down Expand Up @@ -65,6 +66,7 @@ export function sendSynthesizerSnapshot()
channelTransposeKeyShift: channel.channelTransposeKeyShift,
channelOctaveTuning: channel.channelOctaveTuning,
keyCentTuning: channel.keyCentTuning,
velocityOverride: channel.velocityOverride,
isMuted: channel.isMuted,
drumChannel: channel.drumChannel
}
Expand Down Expand Up @@ -126,6 +128,7 @@ export function applySynthesizerSnapshot(snapshot)
channelObject.lockGSNRPNParams = channelSnapshot.lockVibrato;
channelObject.channelTransposeKeyShift = channelSnapshot.channelTransposeKeyShift;
channelObject.channelOctaveTuning = channelSnapshot.channelOctaveTuning;
channelObject.velocityOverride = channelSnapshot.velocityOverride;

// restore preset and lock
channelObject.lockPreset = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ export function getWorkletVoices(channel,
}

// determine looping mode now. if the loop is too small, disable
let loopStart = (sampleAndGenerators.sample.sampleLoopStartIndex / 2);
let loopEnd = (sampleAndGenerators.sample.sampleLoopEndIndex / 2);
let loopStart = sampleAndGenerators.sample.sampleLoopStartIndex;
let loopEnd = sampleAndGenerators.sample.sampleLoopEndIndex;
let loopingMode = generators[generatorTypes.sampleModes];
/**
* create the worklet sample
Expand Down
4 changes: 2 additions & 2 deletions src/spessasynth_lib/utils/loggin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let ENABLE_INFO = true;
let ENABLE_INFO = false;
let ENABLE_WARN = true;
let ENABLE_GROUP = true;
let ENABLE_GROUP = false;
let ENABLE_TABLE = true;

/**
Expand Down
5 changes: 5 additions & 0 deletions src/website/js/main/local_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import {Manager} from "../manager/manager.js";
import { showNotification } from '../notification/notification.js'
import { LocaleManager } from '../locale/locale_manager.js'
import { SpessaSynthLogging } from '../../../spessasynth_lib/utils/loggin.js'

/**
* local_main.js
* purpose: main script for the local edition, loads the soundfont and passes it to the manager.js, reloads soundfonts when needed and saves the settings
*/
const SAMPLE_RATE = 44100;

SpessaSynthLogging(true, true, true, true);

/**
* @type {HTMLHeadingElement}
*/
Expand Down Expand Up @@ -161,6 +164,7 @@ async function replaceFont(fontName)
window.TITLE = window.manager.localeManager.getLocaleString("locale.titleMessage");
titleMessage.innerText = "Initializing...";
await manager.ready;
manager.synth.setLogLevel(true, true, true, true);
}
else
{
Expand Down Expand Up @@ -215,6 +219,7 @@ document.body.onclick = async () =>
window.TITLE = window.manager.localeManager.getLocaleString("locale.titleMessage")
titleMessage.innerText = "Initializing..."
await manager.ready;
manager.synth.setLogLevel(true, true, true, true);
synthReady = true;
}
}
Expand Down
Loading

0 comments on commit c2899c7

Please sign in to comment.