spessasynth_lib 3.24.28 → 3.24.35

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 (74) hide show
  1. package/README.md +1 -1
  2. package/external_midi/web_midi_link.js +1 -1
  3. package/index.js +8 -52
  4. package/midi_parser/basic_midi.js +15 -30
  5. package/midi_parser/midi_builder.js +6 -6
  6. package/midi_parser/midi_data.js +2 -2
  7. package/midi_parser/midi_editor.js +15 -15
  8. package/midi_parser/midi_loader.js +3 -3
  9. package/midi_parser/midi_message.js +2 -2
  10. package/midi_parser/midi_sequence.js +32 -4
  11. package/midi_parser/midi_writer.js +8 -8
  12. package/midi_parser/rmidi_writer.js +20 -21
  13. package/midi_parser/used_keys_loaded.js +8 -6
  14. package/package.json +1 -1
  15. package/sequencer/sequencer.js +6 -6
  16. package/sequencer/worklet_sequencer/events.js +2 -1
  17. package/sequencer/worklet_sequencer/play.js +2 -3
  18. package/sequencer/worklet_sequencer/process_event.js +1 -1
  19. package/sequencer/worklet_sequencer/process_tick.js +1 -1
  20. package/sequencer/worklet_sequencer/sequencer_message.js +1 -1
  21. package/sequencer/worklet_sequencer/song_control.js +6 -7
  22. package/sequencer/worklet_sequencer/worklet_sequencer.js +2 -1
  23. package/soundfont/basic_soundfont/basic_soundfont.js +197 -13
  24. package/soundfont/basic_soundfont/generator.js +18 -16
  25. package/soundfont/basic_soundfont/modulator.js +3 -0
  26. package/soundfont/basic_soundfont/riff_chunk.js +2 -2
  27. package/soundfont/basic_soundfont/write_dls/art2.js +1 -1
  28. package/soundfont/basic_soundfont/write_dls/combine_zones.js +12 -10
  29. package/soundfont/basic_soundfont/write_dls/ins.js +2 -2
  30. package/soundfont/basic_soundfont/write_dls/lins.js +1 -1
  31. package/soundfont/basic_soundfont/write_dls/modulator_converter.js +9 -9
  32. package/soundfont/basic_soundfont/write_dls/rgn2.js +5 -5
  33. package/soundfont/basic_soundfont/write_dls/wave.js +2 -1
  34. package/soundfont/basic_soundfont/write_dls/write_dls.js +1 -1
  35. package/soundfont/basic_soundfont/write_dls/wsmp.js +2 -2
  36. package/soundfont/basic_soundfont/write_dls/wvpl.js +1 -1
  37. package/soundfont/basic_soundfont/write_sf2/ibag.js +2 -2
  38. package/soundfont/basic_soundfont/write_sf2/igen.js +20 -17
  39. package/soundfont/basic_soundfont/write_sf2/imod.js +3 -3
  40. package/soundfont/basic_soundfont/write_sf2/inst.js +2 -2
  41. package/soundfont/basic_soundfont/write_sf2/pbag.js +2 -2
  42. package/soundfont/basic_soundfont/write_sf2/pgen.js +21 -18
  43. package/soundfont/basic_soundfont/write_sf2/phdr.js +2 -2
  44. package/soundfont/basic_soundfont/write_sf2/pmod.js +2 -2
  45. package/soundfont/basic_soundfont/write_sf2/sdta.js +1 -1
  46. package/soundfont/basic_soundfont/write_sf2/shdr.js +1 -1
  47. package/soundfont/basic_soundfont/write_sf2/write.js +7 -6
  48. package/soundfont/dls/articulator_converter.js +1 -0
  49. package/soundfont/dls/dls_destinations.js +3 -3
  50. package/soundfont/dls/dls_preset.js +1 -1
  51. package/soundfont/dls/dls_soundfont.js +7 -7
  52. package/soundfont/dls/read_instrument.js +1 -1
  53. package/soundfont/dls/read_region.js +1 -0
  54. package/soundfont/dls/read_samples.js +4 -5
  55. package/soundfont/load_soundfont.js +1 -1
  56. package/soundfont/read_sf2/presets.js +1 -1
  57. package/soundfont/read_sf2/soundfont.js +5 -5
  58. package/synthetizer/audio_effects/effects_config.js +3 -3
  59. package/synthetizer/audio_effects/fancy_chorus.js +7 -7
  60. package/synthetizer/audio_effects/reverb.js +5 -5
  61. package/synthetizer/audio_effects/reverb_as_binary.js +15 -0
  62. package/synthetizer/audio_effects/reverb_buffer.min.js +1 -0
  63. package/synthetizer/synth_constants.js +14 -0
  64. package/synthetizer/synthetizer.js +1 -17
  65. package/synthetizer/worklet_processor.min.js +14 -12
  66. package/synthetizer/worklet_system/main_processor.js +2 -2
  67. package/synthetizer/worklet_system/worklet_methods/controller_control/controller_change.js +1 -1
  68. package/synthetizer/worklet_system/worklet_methods/controller_control/reset_controllers.js +1 -1
  69. package/synthetizer/worklet_system/worklet_methods/create_worklet_channel.js +2 -1
  70. package/synthetizer/worklet_system/worklet_methods/worklet_soundfont_manager/worklet_soundfont_manager.js +2 -2
  71. package/synthetizer/worklet_system/worklet_processor.js +1 -1
  72. package/soundfont/basic_soundfont/write_sf2/soundfont_trimmer.js +0 -185
  73. package/synthetizer/audio_effects/impulse_response_2.flac +0 -0
  74. package/synthetizer/worklet_system/minify_processor.sh +0 -4
@@ -1,4 +1,4 @@
1
- import { BasicSoundFont } from "../basic_soundfont/basic_soundfont.js";
1
+ import { BasicSoundBank } from "../basic_soundfont/basic_soundfont.js";
2
2
  import { IndexedByteArray } from "../../utils/indexed_array.js";
3
3
  import { SpessaSynthGroup, SpessaSynthGroupEnd, SpessaSynthInfo } from "../../utils/loggin.js";
4
4
  import { consoleColors } from "../../utils/other.js";
@@ -11,7 +11,7 @@ import { readLart } from "./read_lart.js";
11
11
  import { readRegion } from "./read_region.js";
12
12
  import { readDLSSamples } from "./read_samples.js";
13
13
 
14
- class DLSSoundFont extends BasicSoundFont
14
+ class DLSSoundFont extends BasicSoundBank
15
15
  {
16
16
  /**
17
17
  * Loads a new DLS (Downloadable sounds) soundfont
@@ -34,7 +34,7 @@ class DLSSoundFont extends BasicSoundFont
34
34
  this.verifyText(readBytesAsString(this.dataArray, 4).toLowerCase(), "dls ");
35
35
 
36
36
  /**
37
- * Read list
37
+ * Read the list
38
38
  * @type {RiffChunk[]}
39
39
  */
40
40
  const chunks = [];
@@ -95,7 +95,7 @@ class DLSSoundFont extends BasicSoundFont
95
95
  consoleColors.recognized
96
96
  );
97
97
 
98
- // read wave list
98
+ // read the wave list
99
99
  let waveListChunk = findRIFFListType(chunks, "wvpl");
100
100
  if (!waveListChunk)
101
101
  {
@@ -104,7 +104,7 @@ class DLSSoundFont extends BasicSoundFont
104
104
  }
105
105
  this.readDLSSamples(waveListChunk);
106
106
 
107
- // read instrument list
107
+ // read the instrument list
108
108
  let instrumentListChunk = findRIFFListType(chunks, "lins");
109
109
  if (!instrumentListChunk)
110
110
  {
@@ -170,9 +170,9 @@ class DLSSoundFont extends BasicSoundFont
170
170
  throw new Error(`DLS parse error: ${error} The file may be corrupted.`);
171
171
  }
172
172
 
173
- destroySoundfont()
173
+ destroySoundBank()
174
174
  {
175
- super.destroySoundfont();
175
+ super.destroySoundBank();
176
176
  delete this.dataArray;
177
177
  }
178
178
  }
@@ -82,7 +82,7 @@ export function readDLSInstrument(chunk)
82
82
  }
83
83
  // remove generators with default values
84
84
  globalZone.generators = globalZone.generators.filter(g => g.generatorValue !== generatorLimits[g.generatorType].def);
85
- // override reverb and chorus with 1000 instead of 200 (if not overriden)
85
+ // override reverb and chorus with 1000 instead of 200 (if not override)
86
86
  // reverb
87
87
  if (globalZone.modulators.find(m => m.modulatorDestination === generatorTypes.reverbEffectsSend) === undefined)
88
88
  {
@@ -129,6 +129,7 @@ export function readRegion(chunk)
129
129
  readLittleEndian(waveLinkChunk.chunkData, 4);
130
130
  // sampleID
131
131
  const sampleID = readLittleEndian(waveLinkChunk.chunkData, 4);
132
+ // noinspection JSValidateTypes
132
133
  /**
133
134
  * @type {DLSSample}
134
135
  */
@@ -35,7 +35,7 @@ function readPCM(dataChunk, bytesPerSample)
35
35
  }
36
36
  else
37
37
  {
38
- normalizationFactor = maxSampleValue; // For 16-bit normalize from -32768 to 32767
38
+ normalizationFactor = maxSampleValue; // For 16-bit normalize from -32,768 to 32,767
39
39
  }
40
40
  const sampleLength = dataChunk.size / bytesPerSample;
41
41
  const sampleData = new Float32Array(sampleLength);
@@ -167,7 +167,6 @@ export function readDLSSamples(waveListChunk)
167
167
  failed = true;
168
168
  sampleData = new Float32Array(dataChunk.size / bytesPerSample);
169
169
  break;
170
- //throw new Error(`Unsupported WAVE format. Fmt reports ${waveFormat}`);
171
170
 
172
171
  case W_FORMAT_TAG.PCM:
173
172
  sampleData = readPCM(dataChunk, bytesPerSample);
@@ -195,7 +194,7 @@ export function readDLSSamples(waveListChunk)
195
194
  }
196
195
  }
197
196
 
198
- // sane defaults
197
+ // correct defaults
199
198
  let sampleKey = 60;
200
199
  let samplePitch = 0;
201
200
  let sampleLoopStart = 0;
@@ -210,13 +209,13 @@ export function readDLSSamples(waveListChunk)
210
209
  readLittleEndian(wsmpChunk.chunkData, 4);
211
210
  sampleKey = readLittleEndian(wsmpChunk.chunkData, 2);
212
211
  // section 1.14.2: Each relative pitch unit represents 1/65536 cents.
213
- // but that doesn't seem to be true for this one: it's just cents.
212
+ // but that doesn't seem true for this one: it's just cents.
214
213
  samplePitch = signedInt16(
215
214
  wsmpChunk.chunkData[wsmpChunk.chunkData.currentIndex++],
216
215
  wsmpChunk.chunkData[wsmpChunk.chunkData.currentIndex++]
217
216
  );
218
217
 
219
- // pitch correction: convert hundreds to root key
218
+ // pitch correction: convert hundreds to the root key
220
219
  const samplePitchSemitones = Math.trunc(samplePitch / 100);
221
220
  sampleKey += samplePitchSemitones;
222
221
  samplePitch -= samplePitchSemitones * 100;
@@ -6,7 +6,7 @@ import { SoundFont2 } from "./read_sf2/soundfont.js";
6
6
  /**
7
7
  * Loads a soundfont file
8
8
  * @param buffer {ArrayBuffer}
9
- * @returns {BasicSoundFont}
9
+ * @returns {BasicSoundBank}
10
10
  */
11
11
  export function loadSoundFont(buffer)
12
12
  {
@@ -26,7 +26,7 @@ export class Preset extends BasicPreset
26
26
  this.bank = readLittleEndian(presetChunk.chunkData, 2);
27
27
  this.presetZoneStartIndex = readLittleEndian(presetChunk.chunkData, 2);
28
28
 
29
- // read the dwords
29
+ // read the dword
30
30
  this.library = readLittleEndian(presetChunk.chunkData, 4);
31
31
  this.genre = readLittleEndian(presetChunk.chunkData, 4);
32
32
  this.morphology = readLittleEndian(presetChunk.chunkData, 4);
@@ -11,7 +11,7 @@ import { consoleColors } from "../../utils/other.js";
11
11
  import { SpessaSynthGroup, SpessaSynthGroupEnd, SpessaSynthInfo } from "../../utils/loggin.js";
12
12
  import { readBytesAsString } from "../../utils/byte_functions/string.js";
13
13
  import { stbvorbis } from "../../externals/stbvorbis_sync/stbvorbis_sync.min.js";
14
- import { BasicSoundFont } from "../basic_soundfont/basic_soundfont.js";
14
+ import { BasicSoundBank } from "../basic_soundfont/basic_soundfont.js";
15
15
  import { Generator } from "../basic_soundfont/generator.js";
16
16
  import { Modulator } from "../basic_soundfont/modulator.js";
17
17
 
@@ -20,7 +20,7 @@ import { Modulator } from "../basic_soundfont/modulator.js";
20
20
  * purpose: parses a soundfont2 file
21
21
  */
22
22
 
23
- export class SoundFont2 extends BasicSoundFont
23
+ export class SoundFont2 extends BasicSoundBank
24
24
  {
25
25
  /**
26
26
  * Initializes a new SoundFont2 Parser and parses the given data array
@@ -54,7 +54,7 @@ export class SoundFont2 extends BasicSoundFont
54
54
  }
55
55
  /*
56
56
  Some SF2Pack description:
57
- this is essentially sf2, but the entire smpl chunk is compressed (we only support ogg vorbis here)
57
+ this is essentially sf2, but the entire smpl chunk is compressed (we only support Ogg Vorbis here)
58
58
  and the only other difference is that the main chunk isn't "sfbk" but rather "sfpk"
59
59
  */
60
60
  const isSF2Pack = type === "sfpk";
@@ -297,9 +297,9 @@ export class SoundFont2 extends BasicSoundFont
297
297
  }
298
298
  }
299
299
 
300
- destroySoundfont()
300
+ destroySoundBank()
301
301
  {
302
- super.destroySoundfont();
302
+ super.destroySoundBank();
303
303
  delete this.dataArray;
304
304
  }
305
305
  }
@@ -2,13 +2,13 @@ import { DEFAULT_CHORUS_CONFIG } from "./fancy_chorus.js";
2
2
 
3
3
  /**
4
4
  * @typedef {Object} SynthConfig
5
- * @property {boolean} chorusEnabled - indicates if the chorus effect is enabled.
5
+ * @property {boolean?} chorusEnabled - indicates if the chorus effect is enabled.
6
6
  * @property {ChorusConfig?} chorusConfig - the configuration for chorus. Pass undefined to use defaults
7
- * @property {boolean} reverbEnabled - indicates if the reverb effect is enabled.
7
+ * @property {boolean?} reverbEnabled - indicates if the reverb effect is enabled.
8
8
  * @property {AudioBuffer?} reverbImpulseResponse - the impulse response for the reverb. Pass undefined to use defaults
9
9
  * @property {{
10
10
  * worklet: function(context: object, name: string, options?: Object)
11
- * }} audioNodeCreators - custom audio node creation functions for Web Audio wrappers.
11
+ * }?} audioNodeCreators - custom audio node creation functions for Web Audio wrappers.
12
12
  */
13
13
 
14
14
 
@@ -13,13 +13,13 @@
13
13
 
14
14
  /**
15
15
  * @typedef {Object} ChorusConfig
16
- * @property {number} nodesAmount - the amount of delay nodes (for each channel) and the corresponding oscillators
17
- * @property {number} defaultDelay - the initial delay, in seconds
18
- * @property {number} delayVariation - the difference between delays in the delay nodes
19
- * @property {number} stereoDifference - the difference of delays between two channels (added to the left channel and subtracted from the right)
20
- * @property {number} oscillatorFrequency - the initial delay time oscillator frequency, in Hz.
21
- * @property {number} oscillatorFrequencyVariation - the difference between frequencies of oscillators, in Hz
22
- * @property {number} oscillatorGain - how much will oscillator alter the delay in delay nodes, in seconds
16
+ * @property {number?} nodesAmount - the amount of delay nodes (for each channel) and the corresponding oscillators
17
+ * @property {number?} defaultDelay - the initial delay, in seconds
18
+ * @property {number?} delayVariation - the difference between delays in the delay nodes
19
+ * @property {number?} stereoDifference - the difference of delays between two channels (added to the left channel and subtracted from the right)
20
+ * @property {number?} oscillatorFrequency - the initial delay time oscillator frequency, in Hz.
21
+ * @property {number?} oscillatorFrequencyVariation - the difference between frequencies of oscillators, in Hz
22
+ * @property {number?} oscillatorGain - how much will oscillator alter the delay in delay nodes, in seconds
23
23
  */
24
24
 
25
25
  const NODES_AMOUNT = 4;
@@ -1,3 +1,5 @@
1
+ import { reverbBufferBinary } from "./reverb_as_binary.js";
2
+
1
3
  /**
2
4
  * Creates a reverb processor
3
5
  * @param context {BaseAudioContext}
@@ -13,12 +15,10 @@ export function getReverbProcessor(context, reverbBuffer = undefined)
13
15
  }
14
16
  else
15
17
  {
16
- // resolve relative url
17
- const impulseURL = new URL("impulse_response_2.flac", import.meta.url);
18
- fetch(impulseURL).then(async response =>
18
+ // decode
19
+ context.decodeAudioData(reverbBufferBinary.buffer).then(b =>
19
20
  {
20
- const data = await response.arrayBuffer();
21
- convolver.buffer = await context.decodeAudioData(data);
21
+ convolver.buffer = b;
22
22
  });
23
23
  }
24
24
  return convolver;
@@ -0,0 +1,15 @@
1
+ import { rb } from "./reverb_buffer.min.js";
2
+
3
+ const binaryString = atob(rb);
4
+ const binary = new Uint8Array(binaryString.length);
5
+ for (let i = 0; i < binaryString.length; i++)
6
+ {
7
+ binary[i] = binaryString.charCodeAt(i);
8
+ }
9
+
10
+
11
+ /**
12
+ * @type {ArrayBuffer}
13
+ */
14
+ const reverbBufferBinary = binary.buffer;
15
+ export { reverbBufferBinary };