spessasynth_lib 3.21.13 → 3.22.1

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.
@@ -81,6 +81,10 @@ export class BasicSoundFont {
81
81
  * @returns {BasicPreset}
82
82
  */
83
83
  getPresetByName(presetName: string): BasicPreset;
84
+ /**
85
+ * @param error {string}
86
+ */
87
+ parsingError(error: string): void;
84
88
  write: typeof write;
85
89
  }
86
90
  import { Modulator } from "./modulator.js";
@@ -72,6 +72,10 @@ export class Synthetizer {
72
72
  * @type {boolean}
73
73
  */
74
74
  _highPerformanceMode: boolean;
75
+ /**
76
+ * @type {EffectsConfig}
77
+ */
78
+ effectsConfig: EffectsConfig;
75
79
  worklet: AudioWorkletNode;
76
80
  /**
77
81
  * The synth's soundfont manager
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spessasynth_lib",
3
- "version": "3.21.13",
3
+ "version": "3.22.1",
4
4
  "description": "MIDI and SoundFont2/DLS library with no compromises",
5
5
  "browser": "index.js",
6
6
  "types": "@types/index.d.ts",
@@ -459,7 +459,7 @@ export class Sequencer
459
459
  }
460
460
  else
461
461
  {
462
- throw new Error(messageData);
462
+ throw new Error("Sequencer error: " + messageData);
463
463
  }
464
464
  return;
465
465
 
@@ -49,7 +49,7 @@ export function loadNewSequence(parsedMidi, autoPlay = true)
49
49
  this.stop();
50
50
  if (!parsedMidi.tracks)
51
51
  {
52
- throw "No tracks supplied!";
52
+ throw new Error("This MIDI has no tracks!");
53
53
  }
54
54
 
55
55
  this.oneTickToSeconds = 60 / (120 * parsedMidi.timeDivision);
@@ -225,6 +225,14 @@ class BasicSoundFont
225
225
  }
226
226
  return preset;
227
227
  }
228
+
229
+ /**
230
+ * @param error {string}
231
+ */
232
+ parsingError(error)
233
+ {
234
+ throw new Error(`SF parsing error: ${error} The file may be corrupted.`);
235
+ }
228
236
  }
229
237
 
230
238
  BasicSoundFont.prototype.write = write;
@@ -71,7 +71,7 @@ function getSF2SourceFromDLS(source)
71
71
  }
72
72
  if (sourceEnum === undefined)
73
73
  {
74
- throw `not known?? ${source}`;
74
+ throw new Error(`Unknown DLS Source: ${source}`);
75
75
  }
76
76
  return { enum: sourceEnum, isCC: isCC };
77
77
  }
@@ -58,7 +58,7 @@ export class DLSSample extends BasicSample
58
58
  {
59
59
  if (!this.compressedData)
60
60
  {
61
- throw new Error("Compressed but no data??");
61
+ throw new Error("Compressed but no data?? This shouldn't happen!!");
62
62
  }
63
63
  return this.compressedData;
64
64
  }
@@ -25,7 +25,7 @@ class DLSSoundFont extends BasicSoundFont
25
25
  if (!this.dataArray)
26
26
  {
27
27
  SpessaSynthGroupEnd();
28
- throw new TypeError("No data!");
28
+ this.parsingError("No data provided!");
29
29
  }
30
30
 
31
31
  // read the main chunk
@@ -85,7 +85,7 @@ class DLSSoundFont extends BasicSoundFont
85
85
  if (!colhChunk)
86
86
  {
87
87
  SpessaSynthGroupEnd();
88
- throw new Error("No colh chunk!");
88
+ this.parsingError("No colh chunk!");
89
89
  }
90
90
  this.instrumentAmount = readLittleEndian(colhChunk.chunkData, 4);
91
91
  SpessaSynthInfo(
@@ -96,6 +96,11 @@ class DLSSoundFont extends BasicSoundFont
96
96
 
97
97
  // read wave list
98
98
  let waveListChunk = findRIFFListType(chunks, "wvpl");
99
+ if (!waveListChunk)
100
+ {
101
+ SpessaSynthGroupEnd();
102
+ this.parsingError("No wvpl chunk!");
103
+ }
99
104
  this.readDLSSamples(waveListChunk);
100
105
 
101
106
  // read instrument list
@@ -103,7 +108,7 @@ class DLSSoundFont extends BasicSoundFont
103
108
  if (!instrumentListChunk)
104
109
  {
105
110
  SpessaSynthGroupEnd();
106
- throw new Error("No lins chunk!");
111
+ this.parsingError("No lins chunk!");
107
112
  }
108
113
  this.readDLSInstrumentList(instrumentListChunk);
109
114
 
@@ -135,7 +140,7 @@ class DLSSoundFont extends BasicSoundFont
135
140
  if (chunk.header.toLowerCase() !== expected.toLowerCase())
136
141
  {
137
142
  SpessaSynthGroupEnd();
138
- throw new SyntaxError(`Invalid DLS chunk header! Expected "${expected.toLowerCase()}" got "${chunk.header.toLowerCase()}"`);
143
+ this.parsingError(`Invalid DLS chunk header! Expected "${expected.toLowerCase()}" got "${chunk.header.toLowerCase()}"`);
139
144
  }
140
145
  }
141
146
 
@@ -148,9 +153,17 @@ class DLSSoundFont extends BasicSoundFont
148
153
  if (text.toLowerCase() !== expected.toLowerCase())
149
154
  {
150
155
  SpessaSynthGroupEnd();
151
- throw new SyntaxError(`Invalid DLS soundfont! Expected "${expected.toLowerCase()}" got "${text.toLowerCase()}"`);
156
+ this.parsingError(`FourCC error: Expected "${expected.toLowerCase()}" got "${text.toLowerCase()}"`);
152
157
  }
153
158
  }
159
+
160
+ /**
161
+ * @param error {string}
162
+ */
163
+ parsingError(error)
164
+ {
165
+ throw new Error(`DLS parse error: ${error} The file may be corrupted.`);
166
+ }
154
167
  }
155
168
 
156
169
  DLSSoundFont.prototype.readDLSInstrumentList = readDLSInstrumentList;
@@ -85,7 +85,7 @@ export function readDLSInstrument(chunk)
85
85
  if (type !== "rgn " && type !== "rgn2")
86
86
  {
87
87
  SpessaSynthGroupEnd();
88
- throw new SyntaxError(`Invalid DLS region! Expected "rgn " or "rgn2" got "${type}"`);
88
+ this.parsingError(`Invalid DLS region! Expected "rgn " or "rgn2" got "${type}"`);
89
89
  }
90
90
 
91
91
 
@@ -41,15 +41,16 @@ export function readDLSSamples(waveListChunk)
41
41
  {
42
42
  throw new Error("No fmt chunk in the wave file!");
43
43
  }
44
+ // https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.14393.0/shared/mmreg.h#L2108
44
45
  const waveFormat = readLittleEndian(fmtChunk.chunkData, 2);
45
46
  if (waveFormat !== 1)
46
47
  {
47
- throw new Error("Only PCM format in WAVE is supported.");
48
+ throw new Error(`Only PCM format in WAVE is supported. Fmt reports ${waveFormat}`);
48
49
  }
49
50
  const channelsAmount = readLittleEndian(fmtChunk.chunkData, 2);
50
51
  if (channelsAmount !== 1)
51
52
  {
52
- throw new Error("Only mono samples are supported.");
53
+ throw new Error(`Only mono samples are supported. Fmt reports ${channelsAmount} channels`);
53
54
  }
54
55
  const sampleRate = readLittleEndian(fmtChunk.chunkData, 4);
55
56
  // skip avg bytes
@@ -79,7 +80,7 @@ export function readDLSSamples(waveListChunk)
79
80
  const dataChunk = waveChunks.find(c => c.header === "data");
80
81
  if (!dataChunk)
81
82
  {
82
- throw new Error("No data chunk in the wave chunk!");
83
+ this.parsingError("No data chunk in the WAVE chunk!");
83
84
  }
84
85
  const sampleLength = dataChunk.size / bytesPerSample;
85
86
  const sampleData = new Float32Array(sampleLength);
@@ -113,11 +113,18 @@ export class LoadedSample extends BasicSample
113
113
  const buff = smplArr.slice(this.sampleStartIndex / 2 + smplStart, this.sampleEndIndex / 2 + smplStart);
114
114
  // reset array and being decoding
115
115
  this.sampleData = new Float32Array(0);
116
- /**
117
- * @type {{data: Float32Array[], error: (string|null), sampleRate: number, eof: boolean}}
118
- */
119
- const vorbis = stbvorbis.decode(buff.buffer);
120
- this.sampleData = vorbis.data[0];
116
+ try
117
+ {
118
+ /**
119
+ * @type {{data: Float32Array[], error: (string|null), sampleRate: number, eof: boolean}}
120
+ */
121
+ const vorbis = stbvorbis.decode(buff.buffer);
122
+ this.sampleData = vorbis.data[0];
123
+ }
124
+ catch (e)
125
+ {
126
+ throw new Error(`Ogg Vorbis decode error: ${e}`);
127
+ }
121
128
  }
122
129
 
123
130
  /**
@@ -39,7 +39,7 @@ export class SoundFont2 extends BasicSoundFont
39
39
  if (!this.dataArray)
40
40
  {
41
41
  SpessaSynthGroupEnd();
42
- throw new TypeError("No data!");
42
+ this.parsingError("No data provided!");
43
43
  }
44
44
 
45
45
  // read the main read
@@ -280,7 +280,7 @@ export class SoundFont2 extends BasicSoundFont
280
280
  if (chunk.header.toLowerCase() !== expected.toLowerCase())
281
281
  {
282
282
  SpessaSynthGroupEnd();
283
- throw new SyntaxError(`Invalid chunk header! Expected "${expected.toLowerCase()}" got "${chunk.header.toLowerCase()}"`);
283
+ this.parsingError(`Invalid chunk header! Expected "${expected.toLowerCase()}" got "${chunk.header.toLowerCase()}"`);
284
284
  }
285
285
  }
286
286
 
@@ -293,7 +293,7 @@ export class SoundFont2 extends BasicSoundFont
293
293
  if (text.toLowerCase() !== expected.toLowerCase())
294
294
  {
295
295
  SpessaSynthGroupEnd();
296
- throw new SyntaxError(`Invalid soundFont! Expected "${expected.toLowerCase()}" got "${text.toLowerCase()}"`);
296
+ this.parsingError(`Invalid FourCC: Expected "${expected.toLowerCase()}" got "${text.toLowerCase()}"\``);
297
297
  }
298
298
  }
299
299
  }
@@ -127,6 +127,24 @@ export class Synthetizer
127
127
  processorChannelCount = [32];
128
128
  }
129
129
 
130
+ // check for config data in snapshot
131
+ if (startRenderingData?.snapshot?.effectsConfig !== undefined)
132
+ {
133
+ /**
134
+ * @type {EffectsConfig}
135
+ */
136
+ this.effectsConfig = startRenderingData.snapshot.effectsConfig;
137
+ // remove from config as it can't be cloned
138
+ delete startRenderingData.snapshot.effectsConfig;
139
+ }
140
+ else
141
+ {
142
+ /**
143
+ * @type {EffectsConfig}
144
+ */
145
+ this.effectsConfig = effectsConfig;
146
+ }
147
+
130
148
  // first two outputs: reverb, chorsu, the others are the channel outputs
131
149
  try
132
150
  {
@@ -143,6 +161,7 @@ export class Synthetizer
143
161
  }
144
162
  catch (e)
145
163
  {
164
+ console.error(e);
146
165
  throw new Error("Could not create the audioWorklet. Did you forget to addModule()?");
147
166
  }
148
167
 
@@ -175,18 +194,17 @@ export class Synthetizer
175
194
  * @type {function(WorkletSequencerReturnMessageType, any)}
176
195
  */
177
196
  this.sequencerCallbackFunction = undefined;
178
-
179
197
  // add reverb
180
- if (effectsConfig.reverbEnabled && !oneOutputMode)
198
+ if (this.effectsConfig.reverbEnabled && !oneOutputMode)
181
199
  {
182
- this.reverbProcessor = getReverbProcessor(this.context, effectsConfig.reverbImpulseResponse);
200
+ this.reverbProcessor = getReverbProcessor(this.context, this.effectsConfig.reverbImpulseResponse);
183
201
  this.reverbProcessor.connect(targetNode);
184
202
  this.worklet.connect(this.reverbProcessor, 0);
185
203
  }
186
204
 
187
- if (effectsConfig.chorusEnabled && !oneOutputMode)
205
+ if (this.effectsConfig.chorusEnabled && !oneOutputMode)
188
206
  {
189
- this.chorusProcessor = new FancyChorus(targetNode, effectsConfig.chorusConfig);
207
+ this.chorusProcessor = new FancyChorus(targetNode, this.effectsConfig.chorusConfig);
190
208
  this.worklet.connect(this.chorusProcessor.input, 1);
191
209
  }
192
210
 
@@ -361,6 +379,7 @@ export class Synthetizer
361
379
  this._snapshotCallback = s =>
362
380
  {
363
381
  this._snapshotCallback = undefined;
382
+ s.effectsConfig = this.effectsConfig;
364
383
  resolve(s);
365
384
  };
366
385
  this.post({
@@ -821,6 +840,7 @@ export class Synthetizer
821
840
  setReverbResponse(buffer)
822
841
  {
823
842
  this.reverbProcessor.buffer = buffer;
843
+ this.effectsConfig.reverbImpulseResponse = buffer;
824
844
  }
825
845
 
826
846
  /**
@@ -829,12 +849,12 @@ export class Synthetizer
829
849
  */
830
850
  setChorusConfig(config)
831
851
  {
832
- console.log(config);
833
852
  this.worklet.disconnect(this.chorusProcessor.input);
834
853
  this.chorusProcessor.delete();
835
854
  delete this.chorusProcessor;
836
855
  this.chorusProcessor = new FancyChorus(this.targetNode, config);
837
856
  this.worklet.connect(this.chorusProcessor.input, 1);
857
+ this.effectsConfig.chorusConfig = config;
838
858
  }
839
859
 
840
860
  reverbateEverythingBecauseWhyNot()