spessasynth_core 3.26.25 → 3.26.27

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spessasynth_core",
3
- "version": "3.26.25",
3
+ "version": "3.26.27",
4
4
  "description": "MIDI and SoundFont2/DLS library with no compromises",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -350,7 +350,7 @@ class XMFNode
350
350
  }
351
351
 
352
352
  /**
353
- * @param midi {MIDI}
353
+ * @param midi {BasicMIDI}
354
354
  * @param binaryData {IndexedByteArray}
355
355
  * @returns {IndexedByteArray} the file byte array
356
356
  */
@@ -66,8 +66,8 @@ export class BasicSample
66
66
  linkedSample;
67
67
 
68
68
  /**
69
- * The type of the sample, it can indicate an SF3 sample
70
- * @type {sampleTypes|number}
69
+ * The type of the sample
70
+ * @type {sampleTypes}
71
71
  */
72
72
  sampleType;
73
73
 
@@ -84,7 +84,7 @@ export class BasicSample
84
84
  sampleLoopEndIndex;
85
85
 
86
86
  /**
87
- * Indicates if the sample is compressed
87
+ * Indicates if the sample is compressed using vorbis SF3
88
88
  * @type {boolean}
89
89
  */
90
90
  isCompressed;
@@ -132,7 +132,7 @@ export class BasicSample
132
132
  this.samplePitchCorrection = samplePitchCorrection;
133
133
  this.sampleLoopStartIndex = loopStart;
134
134
  this.sampleLoopEndIndex = loopEnd;
135
- this.setSampleType(sampleType);
135
+ this.sampleType = sampleType;
136
136
  }
137
137
 
138
138
  /**
@@ -141,10 +141,9 @@ export class BasicSample
141
141
  */
142
142
  get isLinked()
143
143
  {
144
- return !this.isCompressed &&
145
- (this.sampleType === sampleTypes.rightSample ||
146
- this.sampleType === sampleTypes.leftSample ||
147
- this.sampleType === sampleTypes.linkedSample);
144
+ return this.sampleType === sampleTypes.rightSample ||
145
+ this.sampleType === sampleTypes.leftSample ||
146
+ this.sampleType === sampleTypes.linkedSample;
148
147
  }
149
148
 
150
149
  /**
@@ -229,8 +228,6 @@ export class BasicSample
229
228
  setSampleType(type)
230
229
  {
231
230
  this.sampleType = type;
232
- // https://github.com/FluidSynth/fluidsynth/wiki/SoundFont3Format
233
- this.isCompressed = (type & 0x10) > 0;
234
231
  if (!this.isLinked)
235
232
  {
236
233
  // unlink the other sample
@@ -242,9 +239,9 @@ export class BasicSample
242
239
 
243
240
  this.linkedSample = undefined;
244
241
  }
245
- if ((type & 0x8000) > 0 && this.linkedSample)
242
+ if ((type & 0x8000) > 0)
246
243
  {
247
- throw new Error("ROM samples cannot be linked.");
244
+ throw new Error("ROM samples are not supported.");
248
245
  }
249
246
 
250
247
  }
@@ -261,15 +258,11 @@ export class BasicSample
261
258
  // noinspection JSUnusedGlobalSymbols
262
259
  /**
263
260
  * Links a stereo sample
264
- * @param sample {BasicSample}
265
- * @param type {sampleTypes}
261
+ * @param sample {BasicSample} the sample to link to
262
+ * @param type {sampleTypes} either left, right or linked
266
263
  */
267
264
  setLinkedSample(sample, type)
268
265
  {
269
- if (this.isCompressed)
270
- {
271
- throw new Error("Cannot link a compressed sample.");
272
- }
273
266
  this.linkedSample = sample;
274
267
  sample.linkedSample = this;
275
268
  if (type === sampleTypes.leftSample)
@@ -149,7 +149,6 @@ class BasicSoundBank
149
149
  20,
150
150
  0,
151
151
  0,
152
- 0,
153
152
  127
154
153
  );
155
154
  sample.sampleData = new Float32Array(128);
@@ -2,6 +2,7 @@ import { IndexedByteArray } from "../../../utils/indexed_array.js";
2
2
  import { writeStringAsBytes } from "../../../utils/byte_functions/string.js";
3
3
  import { writeDword, writeWord } from "../../../utils/byte_functions/little_endian.js";
4
4
  import { RiffChunk, writeRIFFChunk } from "../riff_chunk.js";
5
+ import { SF3_BIT_FLIT } from "../../read_sf2/samples.js";
5
6
 
6
7
  /**
7
8
  * @this {BasicSoundBank}
@@ -42,8 +43,13 @@ export function getSHDR(smplStartOffsets, smplEndOffsets)
42
43
  // sample link
43
44
  const sampleLinkIndex = this.samples.indexOf(sample.linkedSample);
44
45
  writeWord(shdrData, Math.max(0, sampleLinkIndex));
45
- // sample type: write raw because we simply copy compressed samples
46
- writeWord(shdrData, sample.sampleType);
46
+ // sample type: add byte if compressed
47
+ let type = sample.sampleType;
48
+ if (sample.isCompressed)
49
+ {
50
+ type |= SF3_BIT_FLIT;
51
+ }
52
+ writeWord(shdrData, type);
47
53
  });
48
54
 
49
55
  // write EOS and zero everything else
@@ -1,4 +1,4 @@
1
- import { BasicSample } from "../basic_soundfont/basic_sample.js";
1
+ import { BasicSample, sampleTypes } from "../basic_soundfont/basic_sample.js";
2
2
 
3
3
  export class DLSSample extends BasicSample
4
4
  {
@@ -38,12 +38,11 @@ export class DLSSample extends BasicSample
38
38
  rate,
39
39
  pitch,
40
40
  pitchCorrection,
41
- 0,
42
- 1,
41
+ sampleTypes.monoSample,
43
42
  loopStart,
44
43
  loopEnd
45
44
  );
46
- this.sampleData = data;
45
+ this.setAudioData(data);
47
46
  this.sampleDbAttenuation = sampleDbAttenuation;
48
47
  }
49
48
 
@@ -6,6 +6,8 @@ import { SpessaSynthWarn } from "../../utils/loggin.js";
6
6
  import { readBytesAsString } from "../../utils/byte_functions/string.js";
7
7
  import { BasicSample } from "../basic_soundfont/basic_sample.js";
8
8
 
9
+ export const SF3_BIT_FLIT = 0x10;
10
+
9
11
  export class SoundFontSample extends BasicSample
10
12
  {
11
13
  /**
@@ -47,6 +49,11 @@ export class SoundFontSample extends BasicSample
47
49
  isDataRaw
48
50
  )
49
51
  {
52
+ // read sf3
53
+ // https://github.com/FluidSynth/fluidsynth/wiki/SoundFont3Format
54
+ const compressed = (sampleType & SF3_BIT_FLIT) > 0;
55
+ // remove the compression flag
56
+ sampleType &= ~SF3_BIT_FLIT;
50
57
  super(
51
58
  sampleName,
52
59
  sampleRate,
@@ -56,6 +63,7 @@ export class SoundFontSample extends BasicSample
56
63
  sampleLoopStartIndex - (sampleStartIndex / 2),
57
64
  sampleLoopEndIndex - (sampleStartIndex / 2)
58
65
  );
66
+ this.isCompressed = compressed;
59
67
  this.sampleName = sampleName;
60
68
  // in bytes
61
69
  this.sampleStartIndex = sampleStartIndex;
@@ -82,7 +90,7 @@ export class SoundFontSample extends BasicSample
82
90
  */
83
91
  getLinkedSample(samplesArray)
84
92
  {
85
- if (this.isCompressed || this.linkedSample || !this.isLinked)
93
+ if (this.linkedSample || !this.isLinked)
86
94
  {
87
95
  return;
88
96
  }
@@ -27,7 +27,7 @@ export class IndexedByteArray extends Uint8Array
27
27
  */
28
28
  slice(start, end)
29
29
  {
30
- const a = super.slice(start, end);
30
+ const a = /** @type {IndexedByteArray} */ super.slice(start, end);
31
31
  a.currentIndex = 0;
32
32
  return a;
33
33
  }