spessasynth_lib 3.20.1 → 3.20.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ export class SoundFont2 extends BasicSoundFont {
11
11
  constructor(arrayBuffer: ArrayBuffer, warnDeprecated?: boolean);
12
12
  dataArray: IndexedByteArray;
13
13
  sampleDataStartIndex: number;
14
- instruments: import("./read_sf2/instruments.js").Instrument[];
14
+ instruments: import("./instruments.js").Instrument[];
15
15
  /**
16
16
  * @param chunk {RiffChunk}
17
17
  * @param expected {string}
@@ -23,6 +23,6 @@ export class SoundFont2 extends BasicSoundFont {
23
23
  */
24
24
  verifyText(text: string, expected: string): void;
25
25
  }
26
- import { BasicSoundFont } from './basic_soundfont/basic_soundfont.js';
27
- import { IndexedByteArray } from '../utils/indexed_array.js';
28
- import { RiffChunk } from './basic_soundfont/riff_chunk.js';
26
+ import { BasicSoundFont } from '../basic_soundfont/basic_soundfont.js';
27
+ import { IndexedByteArray } from '../../utils/indexed_array.js';
28
+ import { RiffChunk } from '../basic_soundfont/riff_chunk.js';
@@ -123,7 +123,6 @@ class MIDI extends BasicMIDI
123
123
 
124
124
  if(DLSRMID)
125
125
  {
126
- console.log(DLSRMID)
127
126
  // assume bank offset of 0 by default. If we find any bank selects, then the offset is 1.
128
127
  this.bankOffset = 0;
129
128
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "spessasynth_lib",
3
- "version": "3.20.1",
4
- "description": "No compromise MIDI and SoundFont2 Synthesizer library",
3
+ "version": "3.20.3",
4
+ "description": "MIDI and SoundFont2 or DLS Synthesizer library with no compromises",
5
5
  "browser": "index.js",
6
6
  "types": "@types/index.d.ts",
7
7
  "type": "module",
@@ -18,7 +18,10 @@
18
18
  "synth",
19
19
  "sf2",
20
20
  "sf3",
21
+ "dls",
22
+ "dls-to-sf2",
21
23
  "midi",
24
+ "rmi",
22
25
  "midi-player",
23
26
  "web-audio-api",
24
27
  "web-midi-api",
@@ -264,10 +264,8 @@ export function play(resetTime = false)
264
264
  }
265
265
  if(!this.sendMIDIMessages)
266
266
  {
267
- const time = this.currentTime;
268
267
  this.playingNotes.forEach(n => {
269
- const timeOffset = n.startTime - time;
270
- this.synth.noteOn(n.channel, n.midiNote, n.velocity, false, true, currentTime + timeOffset);
268
+ this.synth.noteOn(n.channel, n.midiNote, n.velocity, false, true);
271
269
  });
272
270
  }
273
271
  this.setProcessHandler();
@@ -36,8 +36,7 @@ export function _processEvent(event, trackIndex)
36
36
  this.playingNotes.push({
37
37
  midiNote: event.messageData[0],
38
38
  channel: statusByteData.channel,
39
- velocity: velocity,
40
- startTime: this.currentTime
39
+ velocity: velocity
41
40
  });
42
41
  }
43
42
  else
@@ -60,8 +60,7 @@ class WorkletSequencer
60
60
  * @type {{
61
61
  * midiNote: number,
62
62
  * channel: number,
63
- * velocity: number,
64
- * startTime: number
63
+ * velocity: number
65
64
  * }[]}
66
65
  */
67
66
  this.playingNotes = [];
@@ -76,8 +76,14 @@ export function readArticulation(chunk, disableVibrato)
76
76
  const control = readLittleEndian(artData, 2);
77
77
  const destination = readLittleEndian(artData, 2);
78
78
  const transform = readLittleEndian(artData, 2);
79
- const value = readLittleEndian(artData, 4) >> 16; // convert it to 16 bit as soundfont uses that
79
+ const scale = readLittleEndian(artData, 4) | 0;
80
+ const value = scale >> 16; // convert it to 16 bit as soundfont uses that
80
81
 
82
+ // if(destination === DLSDestinations.volEnvDecay)
83
+ // {
84
+ // console.log(scale, value)
85
+ // }
86
+ //modulatorConverterDebug(source, control, destination, value, transform);
81
87
  // interpret this somehow...
82
88
  // if source and control are both zero, it's a generator
83
89
  if(source === 0 && control === 0 && transform === 0)
@@ -224,26 +230,57 @@ export function readArticulation(chunk, disableVibrato)
224
230
  // key to vol env hold
225
231
  if(source === DLSSources.keyNum && destination === DLSDestinations.volEnvHold)
226
232
  {
227
- // according to viena and another strange (with modulators) rendition of gm.dls in sf2, this is how it should be done???
228
- generators.push(new Generator(generatorTypes.keyNumToVolEnvHold, value / -127));
233
+ // according to viena and another strange (with modulators) rendition of gm.dls in sf2,
234
+ // it shall be divided by -128
235
+ // and a strange correction needs to be applied to the real value:
236
+ // real + (60 / 128) * scale
237
+ generators.push(new Generator(generatorTypes.keyNumToVolEnvHold, value / -128));
238
+ const correction = Math.round((60 / 128) * value);
239
+ generators.forEach(g => {
240
+ if(g.generatorType === generatorTypes.holdVolEnv) g.generatorValue += correction;
241
+ });
229
242
  }
230
243
  else
231
244
  // key to vol env decay
232
245
  if(source === DLSSources.keyNum && destination === DLSDestinations.volEnvDecay)
233
246
  {
234
- generators.push(new Generator(generatorTypes.keyNumToVolEnvDecay, value / -127));
247
+ // according to viena and another strange (with modulators) rendition of gm.dls in sf2,
248
+ // it shall be divided by -128
249
+ // and a strange correction needs to be applied to the real value:
250
+ // real + (60 / 128) * scale
251
+ generators.push(new Generator(generatorTypes.keyNumToVolEnvDecay, value / -128));
252
+ const correction = Math.round((60 / 128) * value);
253
+ generators.forEach(g => {
254
+ if(g.generatorType === generatorTypes.decayVolEnv) g.generatorValue += correction;
255
+ });
235
256
  }
236
257
  else
237
258
  // key to mod env hold
238
259
  if(source === DLSSources.keyNum && destination === DLSDestinations.modEnvHold)
239
260
  {
240
- generators.push(new Generator(generatorTypes.keyNumToModEnvHold, value / -127));
261
+ // according to viena and another strange (with modulators) rendition of gm.dls in sf2,
262
+ // it shall be divided by -128
263
+ // and a strange correction needs to be applied to the real value:
264
+ // real + (60 / 128) * scale
265
+ generators.push(new Generator(generatorTypes.keyNumToModEnvHold, value / -128));
266
+ const correction = Math.round((60 / 128) * value);
267
+ generators.forEach(g => {
268
+ if(g.generatorType === generatorTypes.holdModEnv) g.generatorValue += correction;
269
+ });
241
270
  }
242
271
  else
243
272
  // key to mod env decay
244
273
  if(source === DLSSources.keyNum && destination === DLSDestinations.modEnvDecay)
245
274
  {
246
- generators.push(new Generator(generatorTypes.keyNumToModEnvDecay, value / -127));
275
+ // according to viena and another strange (with modulators) rendition of gm.dls in sf2,
276
+ // it shall be divided by -128
277
+ // and a strange correction needs to be applied to the real value:
278
+ // real + (60 / 128) * scale
279
+ generators.push(new Generator(generatorTypes.keyNumToModEnvDecay, value / -128));
280
+ const correction = Math.round((60 / 128) * value);
281
+ generators.forEach(g => {
282
+ if(g.generatorType === generatorTypes.decayModEnv) g.generatorValue += correction;
283
+ });
247
284
  }
248
285
  else
249
286
  {
@@ -1,7 +1,7 @@
1
1
  import { IndexedByteArray } from '../utils/indexed_array.js'
2
2
  import { readBytesAsString } from '../utils/byte_functions/string.js'
3
3
  import { DLSSoundFont } from './dls/dls_soundfont.js'
4
- import { SoundFont2 } from './soundfont.js'
4
+ import { SoundFont2 } from './read_sf2/soundfont.js'
5
5
 
6
6
  /**
7
7
  * Loads a soundfont file
@@ -1,17 +1,17 @@
1
- import { IndexedByteArray } from '../utils/indexed_array.js'
2
- import {readSamples} from "./read_sf2/samples.js";
3
- import { readLittleEndian } from '../utils/byte_functions/little_endian.js'
4
- import { readGenerators, Generator } from './read_sf2/generators.js'
5
- import {readInstrumentZones, InstrumentZone, readPresetZones} from "./read_sf2/zones.js";
6
- import { readPresets } from "./read_sf2/presets.js";
7
- import {readInstruments} from "./read_sf2/instruments.js";
8
- import {readModulators, Modulator} from "./read_sf2/modulators.js";
9
- import { readRIFFChunk, RiffChunk } from './basic_soundfont/riff_chunk.js'
10
- import { consoleColors } from '../utils/other.js'
11
- import { SpessaSynthGroup, SpessaSynthGroupEnd, SpessaSynthInfo } from '../utils/loggin.js'
12
- import { readBytesAsString } from '../utils/byte_functions/string.js'
13
- import { stbvorbis } from "../externals/stbvorbis_sync/stbvorbis_sync.min.js";
14
- import { BasicSoundFont } from './basic_soundfont/basic_soundfont.js'
1
+ import { IndexedByteArray } from '../../utils/indexed_array.js'
2
+ import { readSamples } from "./samples.js";
3
+ import { readLittleEndian } from '../../utils/byte_functions/little_endian.js'
4
+ import { readGenerators, Generator } from './generators.js'
5
+ import { readInstrumentZones, InstrumentZone, readPresetZones } from "./zones.js";
6
+ import { readPresets } from "./presets.js";
7
+ import { readInstruments } from "./instruments.js";
8
+ import { readModulators, Modulator } from "./modulators.js";
9
+ import { readRIFFChunk, RiffChunk } from '../basic_soundfont/riff_chunk.js'
10
+ import { consoleColors } from '../../utils/other.js'
11
+ import { SpessaSynthGroup, SpessaSynthGroupEnd, SpessaSynthInfo } from '../../utils/loggin.js'
12
+ import { readBytesAsString } from '../../utils/byte_functions/string.js'
13
+ import { stbvorbis } from "../../externals/stbvorbis_sync/stbvorbis_sync.min.js";
14
+ import { BasicSoundFont } from '../basic_soundfont/basic_soundfont.js'
15
15
 
16
16
  /**
17
17
  * soundfont.js