spessasynth_lib 3.20.40 → 3.20.42

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.
@@ -42,12 +42,12 @@ export class BasicSample {
42
42
  */
43
43
  sampleType: number;
44
44
  /**
45
- * Relative to start of the sample, bytes assuming 16 bit
45
+ * Relative to start of the sample in sample points
46
46
  * @type {number}
47
47
  */
48
48
  sampleLoopStartIndex: number;
49
49
  /**
50
- * Relative to start of the sample, in bytes assuming 16 bit
50
+ * Relative to start of the sample in sample points
51
51
  * @type {number}
52
52
  */
53
53
  sampleLoopEndIndex: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spessasynth_lib",
3
- "version": "3.20.40",
3
+ "version": "3.20.42",
4
4
  "description": "MIDI and SoundFont2/DLS library with no compromises",
5
5
  "browser": "index.js",
6
6
  "types": "@types/index.d.ts",
@@ -58,12 +58,12 @@ export class BasicSample {
58
58
  */
59
59
  this.sampleType = sampleType
60
60
  /**
61
- * Relative to start of the sample, bytes assuming 16 bit
61
+ * Relative to start of the sample in sample points
62
62
  * @type {number}
63
63
  */
64
64
  this.sampleLoopStartIndex = loopStart
65
65
  /**
66
- * Relative to start of the sample, in bytes assuming 16 bit
66
+ * Relative to start of the sample in sample points
67
67
  * @type {number}
68
68
  */
69
69
  this.sampleLoopEndIndex = loopEnd;
@@ -23,8 +23,8 @@ export function getSHDR(smplStartOffsets, smplEndOffsets)
23
23
  const dwEnd = smplEndOffsets[index];
24
24
  writeDword(shdrData, dwEnd);
25
25
  // loop is stored as relative in sample points, change it to absolute sample points here
26
- let loopStart = sample.sampleLoopStartIndex / 2 + dwStart;
27
- let loopEnd = sample.sampleLoopEndIndex / 2 + dwStart;
26
+ let loopStart = sample.sampleLoopStartIndex + dwStart;
27
+ let loopEnd = sample.sampleLoopEndIndex + dwStart;
28
28
  if(sample.isCompressed)
29
29
  {
30
30
  // https://github.com/FluidSynth/fluidsynth/wiki/SoundFont3Format
@@ -30,8 +30,8 @@ export class DLSSample extends BasicSample
30
30
  pitchCorrection,
31
31
  0,
32
32
  1,
33
- loopStart * 2,
34
- (loopEnd - 1) * 2 // -1 sample because soundfont end is last sample and dls end is next sample
33
+ loopStart,
34
+ loopEnd - 1 // -1 sample because soundfont end is last sample and dls end is next sample
35
35
  );
36
36
  this.sampleData = data;
37
37
  this.sampleDbAttenuation = sampleDbAttenuation;
@@ -55,17 +55,17 @@ export class DLSZone extends BasicInstrumentZone
55
55
  }
56
56
 
57
57
  // correct loop if needed
58
- const diffStart = loop.start - (sample.sampleLoopStartIndex / 2);
59
- const diffEnd = loop.end - (sample.sampleLoopEndIndex / 2);
58
+ const diffStart = loop.start - sample.sampleLoopStartIndex;
59
+ const diffEnd = loop.end - sample.sampleLoopEndIndex;
60
60
  if(diffStart !== 0)
61
61
  {
62
62
  const fine = diffStart % 32768;
63
63
  this.generators.push(new Generator(generatorTypes.startloopAddrsOffset, fine));
64
64
  // coarse generator uses 32768 samples per step
65
- const coarse = (diffStart - fine) / 32768;
65
+ const coarse = Math.trunc(diffStart / 32768);
66
66
  if(coarse !== 0)
67
67
  {
68
- this.generators.push(new Generator(generatorTypes.startloopAddrsCoarseOffset, fine));
68
+ this.generators.push(new Generator(generatorTypes.startloopAddrsCoarseOffset, coarse));
69
69
  }
70
70
  }
71
71
  if(diffEnd !== 0)
@@ -73,10 +73,10 @@ export class DLSZone extends BasicInstrumentZone
73
73
  const fine = diffEnd % 32768;
74
74
  this.generators.push(new Generator(generatorTypes.endloopAddrsOffset, fine));
75
75
  // coarse generator uses 32768 samples per step
76
- const coarse = (diffEnd - fine) / 32768;
76
+ const coarse = Math.trunc(diffEnd / 32768);
77
77
  if(coarse !== 0)
78
78
  {
79
- this.generators.push(new Generator(generatorTypes.endloopAddrsCoarseOffset, fine));
79
+ this.generators.push(new Generator(generatorTypes.endloopAddrsCoarseOffset, coarse));
80
80
  }
81
81
  }
82
82
  // correct key if needed
@@ -47,8 +47,8 @@ export class LoadedSample extends BasicSample
47
47
  samplePitchCorrection,
48
48
  sampleLink,
49
49
  sampleType,
50
- sampleLoopStartIndex - sampleStartIndex,
51
- sampleLoopEndIndex - sampleStartIndex
50
+ sampleLoopStartIndex - (sampleStartIndex / 2),
51
+ sampleLoopEndIndex - (sampleStartIndex / 2)
52
52
  );
53
53
  this.sampleName = sampleName
54
54
  // in bytes
@@ -245,10 +245,10 @@ function readSample(index, sampleHeaderData, smplArrayData, isDataRaw) {
245
245
  let sampleEndIndex = readLittleEndian(sampleHeaderData, 4) * 2;
246
246
 
247
247
  // read the sample looping start index
248
- let sampleLoopStartIndex = readLittleEndian(sampleHeaderData, 4) * 2;
248
+ let sampleLoopStartIndex = readLittleEndian(sampleHeaderData, 4);
249
249
 
250
250
  // read the sample looping end index
251
- let sampleLoopEndIndex = readLittleEndian(sampleHeaderData, 4) * 2;
251
+ let sampleLoopEndIndex = readLittleEndian(sampleHeaderData, 4);
252
252
 
253
253
  // read the sample rate
254
254
  let sampleRate = readLittleEndian(sampleHeaderData, 4);