spessasynth_core 3.27.8 → 4.0.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.
Files changed (157) hide show
  1. package/README.md +85 -51
  2. package/dist/index.d.ts +4057 -0
  3. package/dist/index.js +17178 -0
  4. package/dist/index.js.map +1 -0
  5. package/package.json +24 -6
  6. package/index.js +0 -132
  7. package/src/externals/README.md +0 -6
  8. package/src/externals/fflate/LICENSE +0 -21
  9. package/src/externals/fflate/fflate.min.js +0 -1
  10. package/src/externals/stbvorbis_sync/@types/stbvorbis_sync.d.ts +0 -12
  11. package/src/externals/stbvorbis_sync/LICENSE +0 -202
  12. package/src/externals/stbvorbis_sync/NOTICE +0 -6
  13. package/src/externals/stbvorbis_sync/stbvorbis_sync.min.js +0 -1
  14. package/src/midi/README.md +0 -32
  15. package/src/midi/basic_midi.js +0 -587
  16. package/src/midi/midi_builder.js +0 -203
  17. package/src/midi/midi_loader.js +0 -321
  18. package/src/midi/midi_message.js +0 -254
  19. package/src/midi/midi_sequence.js +0 -230
  20. package/src/midi/midi_tools/get_note_times.js +0 -154
  21. package/src/midi/midi_tools/midi_editor.js +0 -611
  22. package/src/midi/midi_tools/midi_writer.js +0 -105
  23. package/src/midi/midi_tools/rmidi_writer.js +0 -566
  24. package/src/midi/midi_tools/used_keys_loaded.js +0 -256
  25. package/src/midi/xmf_loader.js +0 -454
  26. package/src/sequencer/README.md +0 -9
  27. package/src/sequencer/events.js +0 -81
  28. package/src/sequencer/play.js +0 -362
  29. package/src/sequencer/process_event.js +0 -165
  30. package/src/sequencer/process_tick.js +0 -104
  31. package/src/sequencer/sequencer_engine.js +0 -372
  32. package/src/sequencer/song_control.js +0 -196
  33. package/src/soundfont/README.md +0 -11
  34. package/src/soundfont/basic_soundfont/basic_global_zone.js +0 -6
  35. package/src/soundfont/basic_soundfont/basic_instrument.js +0 -115
  36. package/src/soundfont/basic_soundfont/basic_instrument_zone.js +0 -45
  37. package/src/soundfont/basic_soundfont/basic_preset.js +0 -313
  38. package/src/soundfont/basic_soundfont/basic_preset_zone.js +0 -39
  39. package/src/soundfont/basic_soundfont/basic_sample.js +0 -477
  40. package/src/soundfont/basic_soundfont/basic_soundbank.js +0 -740
  41. package/src/soundfont/basic_soundfont/basic_zone.js +0 -145
  42. package/src/soundfont/basic_soundfont/generator.js +0 -76
  43. package/src/soundfont/basic_soundfont/generator_types.js +0 -151
  44. package/src/soundfont/basic_soundfont/modulator.js +0 -581
  45. package/src/soundfont/basic_soundfont/riff_chunk.js +0 -195
  46. package/src/soundfont/basic_soundfont/write_dls/art2.js +0 -174
  47. package/src/soundfont/basic_soundfont/write_dls/articulator.js +0 -49
  48. package/src/soundfont/basic_soundfont/write_dls/combine_zones.js +0 -374
  49. package/src/soundfont/basic_soundfont/write_dls/ins.js +0 -85
  50. package/src/soundfont/basic_soundfont/write_dls/lins.js +0 -15
  51. package/src/soundfont/basic_soundfont/write_dls/modulator_converter.js +0 -330
  52. package/src/soundfont/basic_soundfont/write_dls/rgn2.js +0 -120
  53. package/src/soundfont/basic_soundfont/write_dls/wave.js +0 -71
  54. package/src/soundfont/basic_soundfont/write_dls/write_dls.js +0 -124
  55. package/src/soundfont/basic_soundfont/write_dls/wsmp.js +0 -78
  56. package/src/soundfont/basic_soundfont/write_dls/wvpl.js +0 -35
  57. package/src/soundfont/basic_soundfont/write_sf2/ibag.js +0 -60
  58. package/src/soundfont/basic_soundfont/write_sf2/igen.js +0 -91
  59. package/src/soundfont/basic_soundfont/write_sf2/imod.js +0 -62
  60. package/src/soundfont/basic_soundfont/write_sf2/inst.js +0 -42
  61. package/src/soundfont/basic_soundfont/write_sf2/pbag.js +0 -57
  62. package/src/soundfont/basic_soundfont/write_sf2/pgen.js +0 -92
  63. package/src/soundfont/basic_soundfont/write_sf2/phdr.js +0 -61
  64. package/src/soundfont/basic_soundfont/write_sf2/pmod.js +0 -62
  65. package/src/soundfont/basic_soundfont/write_sf2/sdta.js +0 -131
  66. package/src/soundfont/basic_soundfont/write_sf2/shdr.js +0 -77
  67. package/src/soundfont/basic_soundfont/write_sf2/write.js +0 -287
  68. package/src/soundfont/dls/articulator_converter.js +0 -402
  69. package/src/soundfont/dls/dls_destinations.js +0 -38
  70. package/src/soundfont/dls/dls_instrument.js +0 -20
  71. package/src/soundfont/dls/dls_preset.js +0 -43
  72. package/src/soundfont/dls/dls_sample.js +0 -238
  73. package/src/soundfont/dls/dls_soundfont.js +0 -183
  74. package/src/soundfont/dls/dls_sources.js +0 -63
  75. package/src/soundfont/dls/dls_zone.js +0 -89
  76. package/src/soundfont/dls/read_articulation.js +0 -300
  77. package/src/soundfont/dls/read_instrument.js +0 -118
  78. package/src/soundfont/dls/read_instrument_list.js +0 -17
  79. package/src/soundfont/dls/read_lart.js +0 -35
  80. package/src/soundfont/dls/read_region.js +0 -157
  81. package/src/soundfont/dls/read_samples.js +0 -154
  82. package/src/soundfont/load_soundfont.js +0 -21
  83. package/src/soundfont/read_sf2/generators.js +0 -43
  84. package/src/soundfont/read_sf2/instrument_zones.js +0 -75
  85. package/src/soundfont/read_sf2/instruments.js +0 -71
  86. package/src/soundfont/read_sf2/modulators.js +0 -25
  87. package/src/soundfont/read_sf2/preset_zones.js +0 -79
  88. package/src/soundfont/read_sf2/presets.js +0 -80
  89. package/src/soundfont/read_sf2/samples.js +0 -317
  90. package/src/soundfont/read_sf2/soundfont.js +0 -452
  91. package/src/soundfont/read_sf2/zones.js +0 -28
  92. package/src/synthetizer/README.md +0 -7
  93. package/src/synthetizer/audio_engine/README.md +0 -9
  94. package/src/synthetizer/audio_engine/engine_components/compute_modulator.js +0 -289
  95. package/src/synthetizer/audio_engine/engine_components/controller_tables.js +0 -90
  96. package/src/synthetizer/audio_engine/engine_components/dynamic_modulator_system.js +0 -95
  97. package/src/synthetizer/audio_engine/engine_components/enums.js +0 -18
  98. package/src/synthetizer/audio_engine/engine_components/key_modifier_manager.js +0 -151
  99. package/src/synthetizer/audio_engine/engine_components/lfo.js +0 -26
  100. package/src/synthetizer/audio_engine/engine_components/lowpass_filter.js +0 -282
  101. package/src/synthetizer/audio_engine/engine_components/midi_audio_channel.js +0 -551
  102. package/src/synthetizer/audio_engine/engine_components/modulation_envelope.js +0 -181
  103. package/src/synthetizer/audio_engine/engine_components/modulator_curves.js +0 -89
  104. package/src/synthetizer/audio_engine/engine_components/soundfont_manager.js +0 -265
  105. package/src/synthetizer/audio_engine/engine_components/stereo_panner.js +0 -124
  106. package/src/synthetizer/audio_engine/engine_components/unit_converter.js +0 -73
  107. package/src/synthetizer/audio_engine/engine_components/voice.js +0 -525
  108. package/src/synthetizer/audio_engine/engine_components/volume_envelope.js +0 -402
  109. package/src/synthetizer/audio_engine/engine_components/wavetable_oscillator.js +0 -274
  110. package/src/synthetizer/audio_engine/engine_methods/controller_control/controller_change.js +0 -159
  111. package/src/synthetizer/audio_engine/engine_methods/controller_control/master_parameters.js +0 -53
  112. package/src/synthetizer/audio_engine/engine_methods/controller_control/reset_controllers.js +0 -254
  113. package/src/synthetizer/audio_engine/engine_methods/create_midi_channel.js +0 -20
  114. package/src/synthetizer/audio_engine/engine_methods/data_entry/awe32.js +0 -198
  115. package/src/synthetizer/audio_engine/engine_methods/data_entry/data_entry_coarse.js +0 -281
  116. package/src/synthetizer/audio_engine/engine_methods/data_entry/data_entry_fine.js +0 -109
  117. package/src/synthetizer/audio_engine/engine_methods/mute_channel.js +0 -17
  118. package/src/synthetizer/audio_engine/engine_methods/note_on.js +0 -220
  119. package/src/synthetizer/audio_engine/engine_methods/portamento_time.js +0 -92
  120. package/src/synthetizer/audio_engine/engine_methods/program_change.js +0 -35
  121. package/src/synthetizer/audio_engine/engine_methods/render_voice.js +0 -214
  122. package/src/synthetizer/audio_engine/engine_methods/soundfont_management/embedded_sound_bank.js +0 -42
  123. package/src/synthetizer/audio_engine/engine_methods/soundfont_management/get_preset.js +0 -0
  124. package/src/synthetizer/audio_engine/engine_methods/soundfont_management/update_preset_list.js +0 -19
  125. package/src/synthetizer/audio_engine/engine_methods/stopping_notes/kill_note.js +0 -23
  126. package/src/synthetizer/audio_engine/engine_methods/stopping_notes/note_off.js +0 -56
  127. package/src/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_channels.js +0 -16
  128. package/src/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_notes.js +0 -30
  129. package/src/synthetizer/audio_engine/engine_methods/stopping_notes/voice_killing.js +0 -63
  130. package/src/synthetizer/audio_engine/engine_methods/system_exclusive.js +0 -1058
  131. package/src/synthetizer/audio_engine/engine_methods/tuning_control/channel_pressure.js +0 -23
  132. package/src/synthetizer/audio_engine/engine_methods/tuning_control/pitch_wheel.js +0 -31
  133. package/src/synthetizer/audio_engine/engine_methods/tuning_control/poly_pressure.js +0 -29
  134. package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_master_tuning.js +0 -15
  135. package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_modulation_depth.js +0 -26
  136. package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_octave_tuning.js +0 -19
  137. package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_tuning.js +0 -27
  138. package/src/synthetizer/audio_engine/engine_methods/tuning_control/transpose_all_channels.js +0 -15
  139. package/src/synthetizer/audio_engine/engine_methods/tuning_control/transpose_channel.js +0 -34
  140. package/src/synthetizer/audio_engine/main_processor.js +0 -817
  141. package/src/synthetizer/audio_engine/snapshot/apply_synthesizer_snapshot.js +0 -16
  142. package/src/synthetizer/audio_engine/snapshot/channel_snapshot.js +0 -175
  143. package/src/synthetizer/audio_engine/snapshot/synthesizer_snapshot.js +0 -116
  144. package/src/synthetizer/audio_engine/synth_processor_options.js +0 -18
  145. package/src/synthetizer/synth_constants.js +0 -26
  146. package/src/utils/README.md +0 -8
  147. package/src/utils/buffer_to_wav.js +0 -197
  148. package/src/utils/byte_functions/big_endian.js +0 -32
  149. package/src/utils/byte_functions/little_endian.js +0 -77
  150. package/src/utils/byte_functions/string.js +0 -92
  151. package/src/utils/byte_functions/variable_length_quantity.js +0 -42
  152. package/src/utils/fill_with_defaults.js +0 -21
  153. package/src/utils/indexed_array.js +0 -34
  154. package/src/utils/loggin.js +0 -71
  155. package/src/utils/other.js +0 -92
  156. package/src/utils/sysex_detector.js +0 -58
  157. package/src/utils/xg_hacks.js +0 -193
@@ -1,317 +0,0 @@
1
- import { RiffChunk } from "../basic_soundfont/riff_chunk.js";
2
- import { IndexedByteArray } from "../../utils/indexed_array.js";
3
- import { readLittleEndian, signedInt8 } from "../../utils/byte_functions/little_endian.js";
4
- import { SpessaSynthInfo, SpessaSynthWarn } from "../../utils/loggin.js";
5
- import { readBytesAsString } from "../../utils/byte_functions/string.js";
6
- import { BasicSample } from "../basic_soundfont/basic_sample.js";
7
- import { consoleColors } from "../../utils/other.js";
8
-
9
- /**
10
- * samples.js
11
- * purpose: parses soundfont samples
12
- */
13
-
14
- export const SF3_BIT_FLIT = 0x10;
15
-
16
- export class SoundFontSample extends BasicSample
17
- {
18
- /**
19
- * Linked sample index for retrieving linked samples in sf2
20
- * @type {number}
21
- */
22
- linkedSampleIndex;
23
-
24
- /**
25
- * The sliced sample from the smpl chunk
26
- * @type {Uint8Array}
27
- */
28
- s16leData;
29
-
30
- /**
31
- * Creates a sample
32
- * @param sampleName {string}
33
- * @param sampleStartIndex {number}
34
- * @param sampleEndIndex {number}
35
- * @param sampleLoopStartIndex {number}
36
- * @param sampleLoopEndIndex {number}
37
- * @param sampleRate {number}
38
- * @param samplePitch {number}
39
- * @param samplePitchCorrection {number}
40
- * @param linkedSampleIndex {number}
41
- * @param sampleType {number}
42
- * @param sampleDataArray {IndexedByteArray|Float32Array}
43
- * @param sampleIndex {number} initial sample index when loading the sfont
44
- * Used for SF2Pack support
45
- */
46
- constructor(
47
- sampleName,
48
- sampleStartIndex,
49
- sampleEndIndex,
50
- sampleLoopStartIndex,
51
- sampleLoopEndIndex,
52
- sampleRate,
53
- samplePitch,
54
- samplePitchCorrection,
55
- linkedSampleIndex,
56
- sampleType,
57
- sampleDataArray,
58
- sampleIndex
59
- )
60
- {
61
- // read sf3
62
- // https://github.com/FluidSynth/fluidsynth/wiki/SoundFont3Format
63
- const compressed = (sampleType & SF3_BIT_FLIT) > 0;
64
- // remove the compression flag
65
- sampleType &= ~SF3_BIT_FLIT;
66
- super(
67
- sampleName,
68
- sampleRate,
69
- samplePitch,
70
- samplePitchCorrection,
71
- sampleType,
72
- sampleLoopStartIndex - (sampleStartIndex / 2),
73
- sampleLoopEndIndex - (sampleStartIndex / 2)
74
- );
75
- this.dataOverriden = false;
76
- this.isCompressed = compressed;
77
- this.sampleName = sampleName;
78
- // in bytes
79
- this.startByteOffset = sampleStartIndex;
80
- this.endByteOffset = sampleEndIndex;
81
- this.sampleID = sampleIndex;
82
- const smplStart = sampleDataArray.currentIndex;
83
-
84
- // three data types in:
85
- // SF2 (s16le)
86
- // SF3 (vorbis)
87
- // SF2Pack (
88
- if (this.isCompressed)
89
- {
90
- // correct loop points
91
- this.sampleLoopStartIndex += this.startByteOffset / 2;
92
- this.sampleLoopEndIndex += this.startByteOffset / 2;
93
-
94
- // copy the compressed data, it can be preserved during writing
95
- this.compressedData = sampleDataArray.slice(
96
- this.startByteOffset / 2 + smplStart,
97
- this.endByteOffset / 2 + smplStart
98
- );
99
- }
100
- else
101
- {
102
- if (sampleDataArray instanceof Float32Array)
103
- {
104
- // float32 array from SF2pack, copy directly
105
- this.sampleData = sampleDataArray.slice(
106
- this.startByteOffset / 2,
107
- this.endByteOffset / 2
108
- );
109
- this.dataOverriden = true;
110
- }
111
- else
112
- {
113
- // regular sf2 s16le
114
- this.s16leData = sampleDataArray.slice(
115
- smplStart + this.startByteOffset,
116
- smplStart + this.endByteOffset
117
- );
118
- }
119
-
120
- }
121
- this.linkedSampleIndex = linkedSampleIndex;
122
- }
123
-
124
- /**
125
- * @param samplesArray {BasicSample[]}
126
- */
127
- getLinkedSample(samplesArray)
128
- {
129
- if (this.linkedSample || !this.isLinked)
130
- {
131
- return;
132
- }
133
- const linked = samplesArray[this.linkedSampleIndex];
134
- if (!linked)
135
- {
136
- // log as info because it's common and not really dangerous
137
- SpessaSynthInfo(`%cInvalid linked sample for ${this.sampleName}. Setting to mono.`, consoleColors.warn);
138
- this.unlinkSample();
139
- }
140
- else
141
- {
142
- // check for corrupted files (like FluidR3_GM.sf2 that link EVERYTHING to a single sample)
143
- if (linked.linkedSample)
144
- {
145
- SpessaSynthInfo(
146
- `%cInvalid linked sample for ${this.sampleName}: Already linked to ${linked.linkedSample.sampleName}`,
147
- consoleColors.warn
148
- );
149
- this.unlinkSample();
150
- }
151
- else
152
- {
153
- this.setLinkedSample(linked, this.sampleType);
154
- }
155
- }
156
- }
157
-
158
- /**
159
- * @param audioData {Float32Array}
160
- */
161
- setAudioData(audioData)
162
- {
163
- super.setAudioData(audioData);
164
- }
165
-
166
- /**
167
- * Loads the audio data and stores it for reuse
168
- * @returns {Float32Array} The audioData
169
- */
170
- getAudioData()
171
- {
172
- if (this.sampleData)
173
- {
174
- return this.sampleData;
175
- }
176
- // SF2Pack is decoded during load time
177
- // SF3 is decoded in BasicSample
178
- if (this.isCompressed)
179
- {
180
- return super.getAudioData();
181
- }
182
-
183
- // start loading data if it is not loaded
184
- const byteLength = this.endByteOffset - this.startByteOffset;
185
- if (byteLength < 1)
186
- {
187
- SpessaSynthWarn(`Invalid sample ${this.sampleName}! Invalid length: ${byteLength}`);
188
- return new Float32Array(1);
189
- }
190
-
191
-
192
- // SF2
193
- // read the sample data
194
- let audioData = new Float32Array(byteLength / 2);
195
- let convertedSigned16 = new Int16Array(
196
- this.s16leData.buffer
197
- );
198
-
199
- // convert to float
200
- for (let i = 0; i < convertedSigned16.length; i++)
201
- {
202
- audioData[i] = convertedSigned16[i] / 32768;
203
- }
204
-
205
- this.sampleData = audioData;
206
- return audioData;
207
-
208
- }
209
-
210
- /**
211
- * @param allowVorbis
212
- * @returns {Uint8Array}
213
- */
214
- getRawData(allowVorbis)
215
- {
216
- if (this.dataOverriden || this.compressedData)
217
- {
218
- // return vorbis or encode manually
219
- return super.getRawData(allowVorbis);
220
- }
221
- // copy the smpl directly
222
- return this.s16leData;
223
- }
224
- }
225
-
226
- /**
227
- * Reads the generatorTranslator from the shdr read
228
- * @param sampleHeadersChunk {RiffChunk}
229
- * @param smplChunkData {IndexedByteArray|Float32Array}
230
- * @param linkSamples {boolean}
231
- * @returns {SoundFontSample[]}
232
- */
233
- export function readSamples(sampleHeadersChunk, smplChunkData, linkSamples = true)
234
- {
235
- /**
236
- * @type {SoundFontSample[]}
237
- */
238
- let samples = [];
239
- let index = 0;
240
- while (sampleHeadersChunk.chunkData.length > sampleHeadersChunk.chunkData.currentIndex)
241
- {
242
- const sample = readSample(index, sampleHeadersChunk.chunkData, smplChunkData);
243
- samples.push(sample);
244
- index++;
245
- }
246
- // remove EOS
247
- samples.pop();
248
-
249
- // link samples
250
- if (linkSamples)
251
- {
252
- samples.forEach(s => s.getLinkedSample(samples));
253
- }
254
-
255
- return samples;
256
- }
257
-
258
- /**
259
- * Reads it into a sample
260
- * @param index {number}
261
- * @param sampleHeaderData {IndexedByteArray}
262
- * @param smplArrayData {IndexedByteArray|Float32Array}
263
- * @returns {SoundFontSample}
264
- */
265
- function readSample(index, sampleHeaderData, smplArrayData)
266
- {
267
-
268
- // read the sample name
269
- let sampleName = readBytesAsString(sampleHeaderData, 20);
270
-
271
- // read the sample start index
272
- let sampleStartIndex = readLittleEndian(sampleHeaderData, 4) * 2;
273
-
274
- // read the sample end index
275
- let sampleEndIndex = readLittleEndian(sampleHeaderData, 4) * 2;
276
-
277
- // read the sample looping start index
278
- let sampleLoopStartIndex = readLittleEndian(sampleHeaderData, 4);
279
-
280
- // read the sample looping end index
281
- let sampleLoopEndIndex = readLittleEndian(sampleHeaderData, 4);
282
-
283
- // read the sample rate
284
- let sampleRate = readLittleEndian(sampleHeaderData, 4);
285
-
286
- // read the original sample pitch
287
- let samplePitch = sampleHeaderData[sampleHeaderData.currentIndex++];
288
- if (samplePitch > 127)
289
- {
290
- // if it's out of range, then default to 60
291
- samplePitch = 60;
292
- }
293
-
294
- // read the sample pitch correction
295
- let samplePitchCorrection = signedInt8(sampleHeaderData[sampleHeaderData.currentIndex++]);
296
-
297
-
298
- // read the link to the other channel
299
- let sampleLink = readLittleEndian(sampleHeaderData, 2);
300
- let sampleType = readLittleEndian(sampleHeaderData, 2);
301
-
302
-
303
- return new SoundFontSample(
304
- sampleName,
305
- sampleStartIndex,
306
- sampleEndIndex,
307
- sampleLoopStartIndex,
308
- sampleLoopEndIndex,
309
- sampleRate,
310
- samplePitch,
311
- samplePitchCorrection,
312
- sampleLink,
313
- sampleType,
314
- smplArrayData,
315
- index
316
- );
317
- }