spessasynth_lib 3.16.5 → 3.20.0

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 (87) hide show
  1. package/@types/index.d.ts +5 -4
  2. package/@types/midi_parser/basic_midi.d.ts +125 -0
  3. package/@types/midi_parser/midi_builder.d.ts +69 -0
  4. package/@types/midi_parser/midi_data.d.ts +2 -2
  5. package/@types/midi_parser/midi_editor.d.ts +4 -4
  6. package/@types/midi_parser/midi_loader.d.ts +3 -100
  7. package/@types/midi_parser/midi_writer.d.ts +2 -2
  8. package/@types/midi_parser/rmidi_writer.d.ts +3 -3
  9. package/@types/midi_parser/used_keys_loaded.d.ts +2 -2
  10. package/@types/sequencer/sequencer.d.ts +1 -1
  11. package/@types/soundfont/basic_soundfont/basic_sample.d.ts +2 -2
  12. package/@types/soundfont/basic_soundfont/basic_zone.d.ts +12 -12
  13. package/@types/soundfont/basic_soundfont/basic_zones.d.ts +4 -0
  14. package/@types/soundfont/basic_soundfont/riff_chunk.d.ts +6 -0
  15. package/@types/soundfont/basic_soundfont/write_sf2/soundfont_trimmer.d.ts +2 -2
  16. package/@types/soundfont/dls/articulator_converter.d.ts +10 -0
  17. package/@types/soundfont/dls/dls_destinations.d.ts +29 -0
  18. package/@types/soundfont/dls/dls_preset.d.ts +13 -0
  19. package/@types/soundfont/dls/dls_sample.d.ts +18 -0
  20. package/@types/soundfont/dls/dls_soundfont.d.ts +31 -0
  21. package/@types/soundfont/dls/dls_sources.d.ts +22 -0
  22. package/@types/soundfont/dls/dls_zone.d.ts +22 -0
  23. package/@types/soundfont/dls/read_articulation.d.ts +12 -0
  24. package/@types/soundfont/dls/read_instrument.d.ts +5 -0
  25. package/@types/soundfont/dls/read_instrument_list.d.ts +5 -0
  26. package/@types/soundfont/dls/read_lart.d.ts +7 -0
  27. package/@types/soundfont/dls/read_region.d.ts +7 -0
  28. package/@types/soundfont/dls/read_samples.d.ts +5 -0
  29. package/@types/soundfont/load_soundfont.d.ts +6 -0
  30. package/@types/soundfont/read_sf2/generators.d.ts +18 -5
  31. package/@types/soundfont/read_sf2/modulators.d.ts +1 -0
  32. package/@types/soundfont/soundfont.d.ts +2 -1
  33. package/@types/synthetizer/synthetizer.d.ts +2 -2
  34. package/@types/utils/byte_functions/little_endian.d.ts +1 -1
  35. package/README.md +27 -15
  36. package/index.js +6 -4
  37. package/midi_parser/basic_midi.js +146 -0
  38. package/midi_parser/midi_builder.js +281 -0
  39. package/midi_parser/midi_data.js +1 -1
  40. package/midi_parser/midi_editor.js +2 -2
  41. package/midi_parser/midi_loader.js +38 -56
  42. package/midi_parser/midi_writer.js +1 -1
  43. package/midi_parser/rmidi_writer.js +2 -2
  44. package/midi_parser/used_keys_loaded.js +1 -1
  45. package/package.json +1 -1
  46. package/sequencer/sequencer.js +1 -1
  47. package/sequencer/worklet_sequencer/song_control.js +3 -3
  48. package/sequencer/worklet_sequencer/worklet_sequencer.js +1 -1
  49. package/soundfont/README.md +6 -2
  50. package/soundfont/basic_soundfont/basic_sample.js +3 -3
  51. package/soundfont/basic_soundfont/basic_zone.js +28 -28
  52. package/soundfont/basic_soundfont/basic_zones.js +15 -19
  53. package/soundfont/basic_soundfont/riff_chunk.js +20 -4
  54. package/soundfont/basic_soundfont/write_sf2/soundfont_trimmer.js +1 -1
  55. package/soundfont/dls/articulator_converter.js +311 -0
  56. package/soundfont/dls/dls_destinations.js +38 -0
  57. package/soundfont/dls/dls_preset.js +32 -0
  58. package/soundfont/dls/dls_sample.js +58 -0
  59. package/soundfont/dls/dls_soundfont.js +150 -0
  60. package/soundfont/dls/dls_sources.js +26 -0
  61. package/soundfont/dls/dls_zone.js +75 -0
  62. package/soundfont/dls/read_articulation.js +327 -0
  63. package/soundfont/dls/read_instrument.js +100 -0
  64. package/soundfont/dls/read_instrument_list.js +17 -0
  65. package/soundfont/dls/read_lart.js +35 -0
  66. package/soundfont/dls/read_region.js +129 -0
  67. package/soundfont/dls/read_samples.js +174 -0
  68. package/soundfont/load_soundfont.js +21 -0
  69. package/soundfont/read_sf2/generators.js +41 -6
  70. package/soundfont/read_sf2/instruments.js +2 -2
  71. package/soundfont/read_sf2/modulators.js +8 -8
  72. package/soundfont/read_sf2/presets.js +7 -7
  73. package/soundfont/read_sf2/samples.js +8 -8
  74. package/soundfont/read_sf2/zones.js +5 -5
  75. package/soundfont/soundfont.js +8 -3
  76. package/synthetizer/synthetizer.js +1 -1
  77. package/synthetizer/worklet_processor.min.js +10 -7
  78. package/synthetizer/worklet_system/main_processor.js +1 -2
  79. package/synthetizer/worklet_system/worklet_methods/program_control.js +6 -3
  80. package/synthetizer/worklet_system/worklet_methods/worklet_soundfont_manager/worklet_soundfont_manager.js +5 -5
  81. package/utils/buffer_to_wav.js +5 -26
  82. package/utils/byte_functions/little_endian.js +1 -1
  83. /package/@types/{midi_handler → external_midi}/midi_handler.d.ts +0 -0
  84. /package/@types/{midi_handler → external_midi}/web_midi_link.d.ts +0 -0
  85. /package/{midi_handler → external_midi}/README.md +0 -0
  86. /package/{midi_handler → external_midi}/midi_handler.js +0 -0
  87. /package/{midi_handler → external_midi}/web_midi_link.js +0 -0
@@ -1,5 +1,4 @@
1
1
  import { DEFAULT_PERCUSSION, DEFAULT_SYNTH_MODE, VOICE_CAP } from '../synthetizer.js'
2
- import { SoundFont2 } from '../../soundfont/soundfont.js'
3
2
  import { WorkletSequencer } from '../../sequencer/worklet_sequencer/worklet_sequencer.js'
4
3
  import { SpessaSynthInfo } from '../../utils/loggin.js'
5
4
  import { consoleColors } from '../../utils/other.js'
@@ -134,7 +133,7 @@ class SpessaSynthProcessor extends AudioWorkletProcessor
134
133
 
135
134
  /**
136
135
  * Overrides the main soundfont (embedded for example
137
- * @type {SoundFont2}
136
+ * @type {BasicSoundFont}
138
137
  */
139
138
  this.overrideSoundfont = undefined;
140
139
 
@@ -1,10 +1,10 @@
1
1
  import { midiControllers } from '../../../midi_parser/midi_message.js'
2
- import { SoundFont2 } from '../../../soundfont/soundfont.js'
3
2
  import { clearSamplesList } from '../worklet_utilities/worklet_voice.js'
4
3
  import { generatorTypes } from '../../../soundfont/read_sf2/generators.js'
5
4
  import { returnMessageType } from '../message_protocol/worklet_message.js'
6
5
  import { SpessaSynthInfo } from '../../../utils/loggin.js'
7
6
  import { consoleColors } from '../../../utils/other.js'
7
+ import { loadSoundFont } from '../../../soundfont/load_soundfont.js'
8
8
 
9
9
  /**
10
10
  * executes a program change
@@ -196,7 +196,10 @@ export function clearSoundFont(sendPresets = true, clearOverride = true)
196
196
  {
197
197
  channelObject.cachedVoices.push([]);
198
198
  }
199
- channelObject.lockPreset = false;
199
+ if(!clearOverride)
200
+ {
201
+ channelObject.lockPreset = false;
202
+ }
200
203
  this.programChange(i, channelObject.preset.program);
201
204
  }
202
205
  if(sendPresets)
@@ -217,7 +220,7 @@ export function reloadSoundFont(buffer, isOverride = false)
217
220
  {
218
221
  if(isOverride)
219
222
  {
220
- this.overrideSoundfont = new SoundFont2(buffer);
223
+ this.overrideSoundfont = loadSoundFont(buffer);
221
224
  // assign sample offset
222
225
  this.overrideSoundfont.setSampleIDOffset(this.soundfontManager.totalSoundfontOffset)
223
226
  }
@@ -1,11 +1,11 @@
1
- import { SoundFont2 } from '../../../../soundfont/soundfont.js'
2
1
  import { SpessaSynthWarn } from '../../../../utils/loggin.js'
3
2
  import { WorkletSoundfontManagerMessageType } from './sfman_message.js'
3
+ import { loadSoundFont } from '../../../../soundfont/load_soundfont.js'
4
4
 
5
5
  /**
6
6
  * @typedef {Object} SoundFontType
7
7
  * @property {string} id - unique id for the soundfont
8
- * @property {SoundFont2} soundfont - the soundfont itself
8
+ * @property {BasicSoundFont} soundfont - the soundfont itself
9
9
  * @property {number} bankOffset - the soundfont's bank offset
10
10
  */
11
11
 
@@ -110,7 +110,7 @@ export class WorkletSoundfontManager
110
110
  */
111
111
  reloadManager(soundFontArrayBuffer)
112
112
  {
113
- const font = new SoundFont2(soundFontArrayBuffer);
113
+ const font = loadSoundFont(soundFontArrayBuffer);
114
114
  /**
115
115
  * All the soundfonts, ordered from the most important to the least.
116
116
  * @type {SoundFontType[]}
@@ -159,7 +159,7 @@ export class WorkletSoundfontManager
159
159
  }
160
160
  this.soundfontList.push({
161
161
  id: id,
162
- soundfont: new SoundFont2(buffer),
162
+ soundfont: loadSoundFont(buffer),
163
163
  bankOffset: bankOffset
164
164
  });
165
165
  this.generatePresetList();
@@ -182,7 +182,7 @@ export class WorkletSoundfontManager
182
182
  * Gets a given preset from the soundfont stack
183
183
  * @param bankNumber {number}
184
184
  * @param programNumber {number}
185
- * @returns {Preset} the preset
185
+ * @returns {BasicPreset} the preset
186
186
  */
187
187
  getPreset(bankNumber, programNumber)
188
188
  {
@@ -113,39 +113,18 @@ export function audioBufferToWav(audioBuffer, normalizeAudio = true, channelOffs
113
113
  wavData.set(header, 0);
114
114
 
115
115
  // Interleave audio data (combine channels)
116
- let multiplier;
116
+ let multiplier = 32767;
117
117
  if(normalizeAudio)
118
118
  {
119
119
  // find min and max values to prevent clipping when converting to 16 bits
120
- const initialMultiplier = 32767;
121
-
122
- const max = Math.max(
123
- channel1Data.reduce((max, value) => (value > max ? value : max), -Infinity),
124
- channel2Data.reduce((max, value) => (value > max ? value : max), -Infinity)
125
- );
126
-
127
- const min = Math.min(
128
- channel1Data.reduce((min, value) => (value < min ? value : min), Infinity),
129
- channel2Data.reduce((min, value) => (value < min ? value : min), Infinity)
130
- );
131
- const maxAbsValue = Math.max(max, Math.abs(min));
132
- multiplier = initialMultiplier / maxAbsValue;
133
- }
134
- else
135
- {
136
- multiplier = 32767;
137
- // clip audio
138
- for(let i = 0; i < length; i++)
139
- {
140
- channel1Data[i] = Math.min(1, Math.max(-1, channel1Data[i]));
141
- channel2Data[i] = Math.min(1, Math.max(-1, channel2Data[i]));
142
- }
120
+ const maxAbsValue = channel1Data.map((v, i) => Math.max(Math.abs(v), Math.abs(channel2Data[i]))).reduce( (a,b) => Math.max(a,b))
121
+ multiplier = maxAbsValue > 0 ? (32767 / maxAbsValue) : 1;
143
122
  }
144
123
  for (let i = 0; i < length; i++)
145
124
  {
146
125
  // interleave both channels
147
- const sample1 = channel1Data[i] * multiplier;
148
- const sample2 = channel2Data[i] * multiplier;
126
+ const sample1 = Math.min(1, Math.max(-1, channel1Data[i])) * multiplier;
127
+ const sample2 = Math.min(1, Math.max(-1,channel2Data[i])) * multiplier;
149
128
 
150
129
  // convert to 16-bit
151
130
  wavData[offset++] = sample1 & 0xff;
@@ -4,7 +4,7 @@
4
4
  * @param bytesAmount {number}
5
5
  * @returns {number}
6
6
  */
7
- export function readBytesAsUintLittleEndian(dataArray, bytesAmount){
7
+ export function readLittleEndian(dataArray, bytesAmount){
8
8
  let out = 0;
9
9
  for(let i = 0; i < bytesAmount; i++)
10
10
  {
File without changes
File without changes