spessasynth_lib 3.23.3 → 3.23.8

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.
Files changed (40) hide show
  1. package/@types/midi_parser/basic_midi.d.ts +41 -21
  2. package/@types/midi_parser/midi_builder.d.ts +0 -4
  3. package/@types/midi_parser/midi_data.d.ts +38 -20
  4. package/@types/sequencer/sequencer.d.ts +2 -1
  5. package/@types/soundfont/basic_soundfont/basic_sample.d.ts +5 -0
  6. package/@types/soundfont/basic_soundfont/basic_soundfont.d.ts +8 -0
  7. package/@types/soundfont/basic_soundfont/modulator.d.ts +2 -1
  8. package/@types/soundfont/dls/articulator_converter.d.ts +9 -0
  9. package/@types/soundfont/dls/dls_sample.d.ts +0 -5
  10. package/@types/soundfont/dls/dls_sources.d.ts +5 -0
  11. package/@types/soundfont/read_sf2/samples.d.ts +0 -1
  12. package/@types/synthetizer/synth_event_handler.d.ts +5 -0
  13. package/@types/utils/byte_functions/string.d.ts +5 -0
  14. package/midi_parser/basic_midi.js +269 -109
  15. package/midi_parser/midi_builder.js +1 -106
  16. package/midi_parser/midi_data.js +140 -90
  17. package/midi_parser/midi_loader.js +2 -0
  18. package/midi_parser/rmidi_writer.js +4 -4
  19. package/package.json +1 -1
  20. package/sequencer/sequencer.js +3 -2
  21. package/soundfont/basic_soundfont/basic_sample.js +15 -6
  22. package/soundfont/basic_soundfont/basic_soundfont.js +64 -0
  23. package/soundfont/basic_soundfont/modulator.js +4 -2
  24. package/soundfont/basic_soundfont/riff_chunk.js +1 -1
  25. package/soundfont/basic_soundfont/write_dls/art2.js +17 -0
  26. package/soundfont/basic_soundfont/write_dls/ins.js +2 -2
  27. package/soundfont/basic_soundfont/write_dls/modulator_converter.js +12 -6
  28. package/soundfont/basic_soundfont/write_dls/rgn2.js +30 -25
  29. package/soundfont/basic_soundfont/write_dls/wave.js +8 -3
  30. package/soundfont/basic_soundfont/write_dls/write_dls.js +3 -2
  31. package/soundfont/basic_soundfont/write_dls/wsmp.js +2 -2
  32. package/soundfont/dls/articulator_converter.js +12 -10
  33. package/soundfont/dls/dls_sample.js +9 -8
  34. package/soundfont/dls/dls_sources.js +36 -1
  35. package/soundfont/dls/read_articulation.js +3 -15
  36. package/soundfont/dls/read_instrument.js +3 -14
  37. package/synthetizer/synth_event_handler.js +38 -1
  38. package/synthetizer/synth_soundfont_manager.js +0 -0
  39. package/synthetizer/worklet_processor.min.js +10 -10
  40. package/utils/byte_functions/string.js +9 -0
@@ -2,7 +2,7 @@ import { combineArrays, IndexedByteArray } from "../../../utils/indexed_array.js
2
2
  import { writeDword, writeWord } from "../../../utils/byte_functions/little_endian.js";
3
3
  import { writeRIFFOddSize } from "../riff_chunk.js";
4
4
  import { writeWavesample } from "./wsmp.js";
5
- import { getStringBytes } from "../../../utils/byte_functions/string.js";
5
+ import { getStringBytesZero } from "../../../utils/byte_functions/string.js";
6
6
  import { SpessaSynthInfo } from "../../../utils/loggin.js";
7
7
  import { consoleColors } from "../../../utils/other.js";
8
8
 
@@ -23,6 +23,11 @@ export function writeDLSSample(sample)
23
23
  "fmt ",
24
24
  fmtData
25
25
  );
26
+ let loop = 1;
27
+ if (sample.sampleLoopStartIndex + Math.abs(sample.getAudioData().length - sample.sampleLoopEndIndex) < 2)
28
+ {
29
+ loop = 0;
30
+ }
26
31
  const wsmp = writeWavesample(
27
32
  sample,
28
33
  sample.samplePitch,
@@ -30,7 +35,7 @@ export function writeDLSSample(sample)
30
35
  0,
31
36
  sample.sampleLoopStartIndex,
32
37
  sample.sampleLoopEndIndex,
33
- 1
38
+ loop
34
39
  );
35
40
  const audio = sample.getAudioData();
36
41
  let data;
@@ -60,7 +65,7 @@ export function writeDLSSample(sample)
60
65
 
61
66
  const inam = writeRIFFOddSize(
62
67
  "INAM",
63
- getStringBytes(sample.sampleName)
68
+ getStringBytesZero(sample.sampleName)
64
69
  );
65
70
  const info = writeRIFFOddSize(
66
71
  "INFO",
@@ -2,7 +2,7 @@ import { writeRIFFOddSize } from "../riff_chunk.js";
2
2
  import { writeDword } from "../../../utils/byte_functions/little_endian.js";
3
3
  import { combineArrays, IndexedByteArray } from "../../../utils/indexed_array.js";
4
4
  import { writeLins } from "./lins.js";
5
- import { getStringBytes, writeStringAsBytes } from "../../../utils/byte_functions/string.js";
5
+ import { getStringBytesZero, writeStringAsBytes } from "../../../utils/byte_functions/string.js";
6
6
  import { writeWavePool } from "./wvpl.js";
7
7
  import { SpessaSynthGroupCollapsed, SpessaSynthGroupEnd, SpessaSynthInfo } from "../../../utils/loggin.js";
8
8
  import { consoleColors } from "../../../utils/other.js";
@@ -80,7 +80,8 @@ export function writeDLS()
80
80
  infos.push(
81
81
  writeRIFFOddSize(
82
82
  info,
83
- getStringBytes(data)
83
+ getStringBytesZero(data),
84
+ true
84
85
  )
85
86
  );
86
87
  }
@@ -37,8 +37,8 @@ export function writeWavesample(
37
37
  // gain correction: Each unit of gain represents 1/655360 dB
38
38
  const lGain = Math.floor(attenuationCb * -65536);
39
39
  writeDword(wsmpData, lGain);
40
- // fulOptions
41
- writeDword(wsmpData, 0);
40
+ // fulOptions: has to be 2 according to all DLS files I have
41
+ writeDword(wsmpData, 2);
42
42
 
43
43
  const loopSize = loopEnd - loopStart;
44
44
  let ulLoopType = 0;
@@ -188,13 +188,15 @@ function checkForSpecialDLSCombo(source, destination)
188
188
  * @param destination {number}
189
189
  * @param value {number}
190
190
  * @param transform {number}
191
+ * @param msg {string}
191
192
  */
192
- function modulatorConverterDebug(
193
+ export function modulatorConverterDebug(
193
194
  source,
194
195
  control,
195
196
  destination,
196
197
  value,
197
- transform
198
+ transform,
199
+ msg = "Attempting to convert the following DLS Articulator to SF2 Modulator:"
198
200
  )
199
201
  {
200
202
  const type = Object.keys(DLSDestinations).find(k => DLSDestinations[k] === destination);
@@ -204,7 +206,7 @@ function modulatorConverterDebug(
204
206
  const srcString = srcType ? srcType : source.toString(16);
205
207
  const ctrlString = ctrlType ? ctrlType : control.toString(16);
206
208
  console.debug(
207
- `%cAttempting to convert the following DLS Articulator to SF2 Modulator:
209
+ `%c${msg}
208
210
  Source: %c${srcString}%c
209
211
  Control: %c${ctrlString}%c
210
212
  Destination: %c${typeString}%c
@@ -240,6 +242,13 @@ export function getSF2ModulatorFromArticulator(
240
242
  value
241
243
  )
242
244
  {
245
+ // modulatorConverterDebug(
246
+ // source,
247
+ // control,
248
+ // destination,
249
+ // value,
250
+ // transform
251
+ // );
243
252
  // check for special combinations
244
253
  const specialDestination = checkForSpecialDLSCombo(source, destination);
245
254
  /**
@@ -320,13 +329,6 @@ export function getSF2ModulatorFromArticulator(
320
329
  // special case: for attenuation, invert source (dls gain is the opposite of sf2 attenuation)
321
330
  if (destinationGenerator === generatorTypes.initialAttenuation)
322
331
  {
323
- // modulatorConverterDebug(
324
- // source,
325
- // control,
326
- // destination,
327
- // value,
328
- // transform
329
- // );
330
332
  // if the value is negative, the source shall be negative!
331
333
  // why?
332
334
  // Idk, it makes it work with ROCK.RMI and NOKIA_S30.dls
@@ -62,13 +62,14 @@ export class DLSSample extends BasicSample
62
62
  }
63
63
  return this.compressedData;
64
64
  }
65
- const uint8 = new Uint8Array(this.sampleData.length * 2);
66
- for (let i = 0; i < this.sampleData.length; i++)
67
- {
68
- const sample = Math.floor(this.sampleData[i] * 32768);
69
- uint8[i * 2] = sample & 0xFF; // lower byte
70
- uint8[i * 2 + 1] = (sample >> 8) & 0xFF; // upper byte
71
- }
72
- return uint8;
65
+ return super.getRawData();
66
+ // const uint8 = new Uint8Array(this.sampleData.length * 2);
67
+ // for (let i = 0; i < this.sampleData.length; i++)
68
+ // {
69
+ // const sample = Math.floor(this.sampleData[i] * 32768);
70
+ // uint8[i * 2] = sample & 0xFF; // lower byte
71
+ // uint8[i * 2 + 1] = (sample >> 8) & 0xFF; // upper byte
72
+ // }
73
+ // return uint8;
73
74
  }
74
75
  }
@@ -1,3 +1,6 @@
1
+ import { Modulator } from "../basic_soundfont/modulator.js";
2
+ import { generatorTypes } from "../basic_soundfont/generator.js";
3
+
1
4
  /**
2
5
  * @enum {number}
3
6
  */
@@ -23,4 +26,36 @@ export const DLSSources = {
23
26
  pitchWheelRange: 0x100,
24
27
  fineTune: 0x101,
25
28
  coarseTune: 0x102
26
- };
29
+ };
30
+
31
+ export const DEFAULT_DLS_REVERB = new Modulator({
32
+ srcEnum: 0x00DB,
33
+ dest: generatorTypes.reverbEffectsSend,
34
+ amt: 1000,
35
+ secSrcEnum: 0x0,
36
+ transform: 0
37
+ });
38
+
39
+ export const DEFAULT_DLS_CHORUS = new Modulator({
40
+ srcEnum: 0x00DD,
41
+ dest: generatorTypes.chorusEffectsSend,
42
+ amt: 1000,
43
+ secSrcEnum: 0x0,
44
+ transform: 0
45
+ });
46
+
47
+ export const DLS_1_NO_VIBRATO_MOD = new Modulator({
48
+ srcEnum: 0x0081,
49
+ dest: generatorTypes.vibLfoToPitch,
50
+ amt: 0,
51
+ secSrcEnum: 0x0,
52
+ transform: 0
53
+ });
54
+
55
+ export const DLS_1_NO_VIBRATO_PRESSURE = new Modulator({
56
+ srcEnum: 0x000D,
57
+ dest: generatorTypes.vibLfoToPitch,
58
+ amt: 0,
59
+ secSrcEnum: 0x0,
60
+ transform: 0
61
+ });
@@ -1,6 +1,6 @@
1
1
  import { readLittleEndian } from "../../utils/byte_functions/little_endian.js";
2
2
  import { DLSDestinations } from "./dls_destinations.js";
3
- import { DLSSources } from "./dls_sources.js";
3
+ import { DLS_1_NO_VIBRATO_MOD, DLS_1_NO_VIBRATO_PRESSURE, DLSSources } from "./dls_sources.js";
4
4
  import { getSF2ModulatorFromArticulator } from "./articulator_converter.js";
5
5
  import { SpessaSynthInfo, SpessaSynthWarn } from "../../utils/loggin.js";
6
6
  import { consoleColors } from "../../utils/other.js";
@@ -306,21 +306,9 @@ export function readArticulation(chunk, disableVibrato)
306
306
  {
307
307
  modulators.push(
308
308
  // mod to vib
309
- new Modulator({
310
- srcEnum: 0x0081,
311
- dest: generatorTypes.vibLfoToPitch,
312
- amt: 0,
313
- secSrcEnum: 0x0,
314
- transform: 0
315
- }),
309
+ Modulator.copy(DLS_1_NO_VIBRATO_MOD),
316
310
  // press to vib
317
- new Modulator({
318
- srcEnum: 0x000D,
319
- dest: generatorTypes.vibLfoToPitch,
320
- amt: 0,
321
- secSrcEnum: 0x0,
322
- transform: 0
323
- })
311
+ Modulator.copy(DLS_1_NO_VIBRATO_PRESSURE)
324
312
  );
325
313
  }
326
314
 
@@ -7,6 +7,7 @@ import { BasicInstrumentZone } from "../basic_soundfont/basic_zones.js";
7
7
  import { consoleColors } from "../../utils/other.js";
8
8
  import { generatorLimits, generatorTypes } from "../basic_soundfont/generator.js";
9
9
  import { Modulator } from "../basic_soundfont/modulator.js";
10
+ import { DEFAULT_DLS_CHORUS, DEFAULT_DLS_REVERB } from "./dls_sources.js";
10
11
 
11
12
  /**
12
13
  * @this {DLSSoundFont}
@@ -85,24 +86,12 @@ export function readDLSInstrument(chunk)
85
86
  // reverb
86
87
  if (globalZone.modulators.find(m => m.modulatorDestination === generatorTypes.reverbEffectsSend) === undefined)
87
88
  {
88
- globalZone.modulators.push(new Modulator({
89
- srcEnum: 0x00DB,
90
- dest: generatorTypes.reverbEffectsSend,
91
- amt: 1000,
92
- secSrcEnum: 0x0,
93
- transform: 0
94
- }));
89
+ globalZone.modulators.push(Modulator.copy(DEFAULT_DLS_REVERB));
95
90
  }
96
91
  // chorus
97
92
  if (globalZone.modulators.find(m => m.modulatorDestination === generatorTypes.chorusEffectsSend) === undefined)
98
93
  {
99
- globalZone.modulators.push(new Modulator({
100
- srcEnum: 0x00DD,
101
- dest: generatorTypes.chorusEffectsSend,
102
- amt: 1000,
103
- secSrcEnum: 0x0,
104
- transform: 0
105
- }));
94
+ globalZone.modulators.push(Modulator.copy(DEFAULT_DLS_CHORUS));
106
95
  }
107
96
  preset.DLSInstrument.instrumentZones.push(globalZone);
108
97
 
@@ -119,6 +119,12 @@ export class EventHandler
119
119
  "allcontrollerreset": {},
120
120
  "soundfonterror": {}
121
121
  };
122
+
123
+ /**
124
+ * Set to 0 to disabled, otherwise in seconds
125
+ * @type {number}
126
+ */
127
+ this.timeDelay = 0;
122
128
  }
123
129
 
124
130
  /**
@@ -151,7 +157,38 @@ export class EventHandler
151
157
  {
152
158
  if (this.events[name])
153
159
  {
154
- Object.values(this.events[name]).forEach(ev => ev(eventData));
160
+ if (this.timeDelay > 0)
161
+ {
162
+ setTimeout(() =>
163
+ {
164
+ Object.values(this.events[name]).forEach(ev =>
165
+ {
166
+ try
167
+ {
168
+ ev(eventData);
169
+ }
170
+ catch (e)
171
+ {
172
+ console.error(`Error while executing an event callback for ${name}:`, e);
173
+ }
174
+ });
175
+ }, this.timeDelay * 1000);
176
+ }
177
+ else
178
+ {
179
+ Object.values(this.events[name]).forEach(ev =>
180
+ {
181
+ try
182
+ {
183
+ ev(eventData);
184
+ }
185
+ catch (e)
186
+ {
187
+ console.error(`Error while executing an event callback for ${name}:`, e);
188
+ }
189
+ }
190
+ );
191
+ }
155
192
  }
156
193
  }
157
194
  }
File without changes