spessasynth_lib 3.25.22 → 3.26.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 (168) hide show
  1. package/README.md +29 -114
  2. package/index.js +33 -33
  3. package/package.json +16 -6
  4. package/external_midi/README.md +0 -4
  5. package/external_midi/midi_handler.js +0 -130
  6. package/external_midi/web_midi_link.js +0 -43
  7. package/externals/fflate/LICENSE +0 -21
  8. package/externals/fflate/fflate.min.js +0 -1
  9. package/externals/stbvorbis_sync/@types/stbvorbis_sync.d.ts +0 -12
  10. package/externals/stbvorbis_sync/LICENSE +0 -202
  11. package/externals/stbvorbis_sync/NOTICE +0 -6
  12. package/externals/stbvorbis_sync/stbvorbis_sync.min.js +0 -1
  13. package/midi/README.md +0 -32
  14. package/midi/basic_midi.js +0 -565
  15. package/midi/midi_builder.js +0 -202
  16. package/midi/midi_data.js +0 -63
  17. package/midi/midi_loader.js +0 -324
  18. package/midi/midi_message.js +0 -254
  19. package/midi/midi_sequence.js +0 -225
  20. package/midi/midi_tools/get_note_times.js +0 -154
  21. package/midi/midi_tools/midi_editor.js +0 -611
  22. package/midi/midi_tools/midi_writer.js +0 -99
  23. package/midi/midi_tools/rmidi_writer.js +0 -567
  24. package/midi/midi_tools/used_keys_loaded.js +0 -238
  25. package/midi/xmf_loader.js +0 -454
  26. package/sequencer/README.md +0 -32
  27. package/sequencer/sequencer_engine/events.js +0 -207
  28. package/sequencer/sequencer_engine/play.js +0 -353
  29. package/sequencer/sequencer_engine/process_event.js +0 -169
  30. package/sequencer/sequencer_engine/process_tick.js +0 -106
  31. package/sequencer/sequencer_engine/sequencer_engine.js +0 -337
  32. package/sequencer/sequencer_engine/song_control.js +0 -229
  33. package/sequencer/worklet_wrapper/default_sequencer_options.js +0 -8
  34. package/sequencer/worklet_wrapper/sequencer.js +0 -807
  35. package/sequencer/worklet_wrapper/sequencer_message.js +0 -53
  36. package/soundfont/README.md +0 -13
  37. package/soundfont/basic_soundfont/basic_instrument.js +0 -77
  38. package/soundfont/basic_soundfont/basic_preset.js +0 -336
  39. package/soundfont/basic_soundfont/basic_sample.js +0 -197
  40. package/soundfont/basic_soundfont/basic_soundfont.js +0 -565
  41. package/soundfont/basic_soundfont/basic_zone.js +0 -64
  42. package/soundfont/basic_soundfont/basic_zones.js +0 -43
  43. package/soundfont/basic_soundfont/generator.js +0 -220
  44. package/soundfont/basic_soundfont/modulator.js +0 -378
  45. package/soundfont/basic_soundfont/riff_chunk.js +0 -149
  46. package/soundfont/basic_soundfont/write_dls/art2.js +0 -173
  47. package/soundfont/basic_soundfont/write_dls/articulator.js +0 -49
  48. package/soundfont/basic_soundfont/write_dls/combine_zones.js +0 -400
  49. package/soundfont/basic_soundfont/write_dls/ins.js +0 -103
  50. package/soundfont/basic_soundfont/write_dls/lins.js +0 -18
  51. package/soundfont/basic_soundfont/write_dls/modulator_converter.js +0 -330
  52. package/soundfont/basic_soundfont/write_dls/rgn2.js +0 -121
  53. package/soundfont/basic_soundfont/write_dls/wave.js +0 -94
  54. package/soundfont/basic_soundfont/write_dls/write_dls.js +0 -119
  55. package/soundfont/basic_soundfont/write_dls/wsmp.js +0 -78
  56. package/soundfont/basic_soundfont/write_dls/wvpl.js +0 -32
  57. package/soundfont/basic_soundfont/write_sf2/ibag.js +0 -39
  58. package/soundfont/basic_soundfont/write_sf2/igen.js +0 -80
  59. package/soundfont/basic_soundfont/write_sf2/imod.js +0 -46
  60. package/soundfont/basic_soundfont/write_sf2/inst.js +0 -34
  61. package/soundfont/basic_soundfont/write_sf2/pbag.js +0 -39
  62. package/soundfont/basic_soundfont/write_sf2/pgen.js +0 -82
  63. package/soundfont/basic_soundfont/write_sf2/phdr.js +0 -42
  64. package/soundfont/basic_soundfont/write_sf2/pmod.js +0 -46
  65. package/soundfont/basic_soundfont/write_sf2/sdta.js +0 -80
  66. package/soundfont/basic_soundfont/write_sf2/shdr.js +0 -55
  67. package/soundfont/basic_soundfont/write_sf2/write.js +0 -222
  68. package/soundfont/dls/articulator_converter.js +0 -396
  69. package/soundfont/dls/dls_destinations.js +0 -38
  70. package/soundfont/dls/dls_preset.js +0 -44
  71. package/soundfont/dls/dls_sample.js +0 -75
  72. package/soundfont/dls/dls_soundfont.js +0 -186
  73. package/soundfont/dls/dls_sources.js +0 -62
  74. package/soundfont/dls/dls_zone.js +0 -95
  75. package/soundfont/dls/read_articulation.js +0 -299
  76. package/soundfont/dls/read_instrument.js +0 -121
  77. package/soundfont/dls/read_instrument_list.js +0 -17
  78. package/soundfont/dls/read_lart.js +0 -35
  79. package/soundfont/dls/read_region.js +0 -152
  80. package/soundfont/dls/read_samples.js +0 -270
  81. package/soundfont/load_soundfont.js +0 -21
  82. package/soundfont/read_sf2/generators.js +0 -46
  83. package/soundfont/read_sf2/instruments.js +0 -66
  84. package/soundfont/read_sf2/modulators.js +0 -36
  85. package/soundfont/read_sf2/presets.js +0 -80
  86. package/soundfont/read_sf2/samples.js +0 -304
  87. package/soundfont/read_sf2/soundfont.js +0 -305
  88. package/soundfont/read_sf2/zones.js +0 -263
  89. package/synthetizer/README.md +0 -10
  90. package/synthetizer/audio_effects/effects_config.js +0 -25
  91. package/synthetizer/audio_effects/fancy_chorus.js +0 -162
  92. package/synthetizer/audio_effects/rb_compressed.min.js +0 -1
  93. package/synthetizer/audio_effects/reverb.js +0 -35
  94. package/synthetizer/audio_effects/reverb_as_binary.js +0 -18
  95. package/synthetizer/audio_engine/README.md +0 -25
  96. package/synthetizer/audio_engine/engine_components/compute_modulator.js +0 -266
  97. package/synthetizer/audio_engine/engine_components/controller_tables.js +0 -88
  98. package/synthetizer/audio_engine/engine_components/key_modifier_manager.js +0 -149
  99. package/synthetizer/audio_engine/engine_components/lfo.js +0 -26
  100. package/synthetizer/audio_engine/engine_components/lowpass_filter.js +0 -282
  101. package/synthetizer/audio_engine/engine_components/midi_audio_channel.js +0 -471
  102. package/synthetizer/audio_engine/engine_components/modulation_envelope.js +0 -181
  103. package/synthetizer/audio_engine/engine_components/modulator_curves.js +0 -89
  104. package/synthetizer/audio_engine/engine_components/soundfont_manager/sfman_message.js +0 -9
  105. package/synthetizer/audio_engine/engine_components/soundfont_manager/soundfont_manager.js +0 -254
  106. package/synthetizer/audio_engine/engine_components/stereo_panner.js +0 -120
  107. package/synthetizer/audio_engine/engine_components/unit_converter.js +0 -73
  108. package/synthetizer/audio_engine/engine_components/voice.js +0 -519
  109. package/synthetizer/audio_engine/engine_components/volume_envelope.js +0 -401
  110. package/synthetizer/audio_engine/engine_components/wavetable_oscillator.js +0 -263
  111. package/synthetizer/audio_engine/engine_methods/controller_control/controller_change.js +0 -132
  112. package/synthetizer/audio_engine/engine_methods/controller_control/master_parameters.js +0 -48
  113. package/synthetizer/audio_engine/engine_methods/controller_control/reset_controllers.js +0 -241
  114. package/synthetizer/audio_engine/engine_methods/create_midi_channel.js +0 -27
  115. package/synthetizer/audio_engine/engine_methods/data_entry/data_entry_coarse.js +0 -253
  116. package/synthetizer/audio_engine/engine_methods/data_entry/data_entry_fine.js +0 -66
  117. package/synthetizer/audio_engine/engine_methods/mute_channel.js +0 -17
  118. package/synthetizer/audio_engine/engine_methods/note_on.js +0 -174
  119. package/synthetizer/audio_engine/engine_methods/portamento_time.js +0 -92
  120. package/synthetizer/audio_engine/engine_methods/program_change.js +0 -61
  121. package/synthetizer/audio_engine/engine_methods/render_voice.js +0 -196
  122. package/synthetizer/audio_engine/engine_methods/soundfont_management/clear_sound_font.js +0 -30
  123. package/synthetizer/audio_engine/engine_methods/soundfont_management/get_preset.js +0 -22
  124. package/synthetizer/audio_engine/engine_methods/soundfont_management/reload_sound_font.js +0 -40
  125. package/synthetizer/audio_engine/engine_methods/soundfont_management/send_preset_list.js +0 -34
  126. package/synthetizer/audio_engine/engine_methods/soundfont_management/set_embedded_sound_font.js +0 -21
  127. package/synthetizer/audio_engine/engine_methods/stopping_notes/kill_note.js +0 -20
  128. package/synthetizer/audio_engine/engine_methods/stopping_notes/note_off.js +0 -55
  129. package/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_channels.js +0 -16
  130. package/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_notes.js +0 -30
  131. package/synthetizer/audio_engine/engine_methods/stopping_notes/voice_killing.js +0 -63
  132. package/synthetizer/audio_engine/engine_methods/system_exclusive.js +0 -744
  133. package/synthetizer/audio_engine/engine_methods/tuning_control/channel_pressure.js +0 -24
  134. package/synthetizer/audio_engine/engine_methods/tuning_control/pitch_wheel.js +0 -33
  135. package/synthetizer/audio_engine/engine_methods/tuning_control/poly_pressure.js +0 -31
  136. package/synthetizer/audio_engine/engine_methods/tuning_control/set_master_tuning.js +0 -15
  137. package/synthetizer/audio_engine/engine_methods/tuning_control/set_modulation_depth.js +0 -27
  138. package/synthetizer/audio_engine/engine_methods/tuning_control/set_octave_tuning.js +0 -19
  139. package/synthetizer/audio_engine/engine_methods/tuning_control/set_tuning.js +0 -27
  140. package/synthetizer/audio_engine/engine_methods/tuning_control/transpose_all_channels.js +0 -15
  141. package/synthetizer/audio_engine/engine_methods/tuning_control/transpose_channel.js +0 -34
  142. package/synthetizer/audio_engine/main_processor.js +0 -765
  143. package/synthetizer/audio_engine/message_protocol/README.md +0 -13
  144. package/synthetizer/audio_engine/message_protocol/message_sending.js +0 -22
  145. package/synthetizer/audio_engine/message_protocol/worklet_message.js +0 -107
  146. package/synthetizer/audio_engine/snapshot/apply_synthesizer_snapshot.js +0 -14
  147. package/synthetizer/audio_engine/snapshot/channel_snapshot.js +0 -175
  148. package/synthetizer/audio_engine/snapshot/synthesizer_snapshot.js +0 -122
  149. package/synthetizer/synth_constants.js +0 -20
  150. package/synthetizer/worklet_processor.min.js +0 -21
  151. package/synthetizer/worklet_wrapper/key_modifier_manager.js +0 -104
  152. package/synthetizer/worklet_wrapper/synth_event_handler.js +0 -214
  153. package/synthetizer/worklet_wrapper/synth_soundfont_manager.js +0 -111
  154. package/synthetizer/worklet_wrapper/synthetizer.js +0 -1027
  155. package/synthetizer/worklet_wrapper/worklet_processor.js +0 -340
  156. package/synthetizer/worklet_wrapper/worklet_url.js +0 -16
  157. package/utils/README.md +0 -5
  158. package/utils/buffer_to_wav.js +0 -186
  159. package/utils/byte_functions/big_endian.js +0 -32
  160. package/utils/byte_functions/little_endian.js +0 -77
  161. package/utils/byte_functions/string.js +0 -107
  162. package/utils/byte_functions/variable_length_quantity.js +0 -42
  163. package/utils/fill_with_defaults.js +0 -21
  164. package/utils/indexed_array.js +0 -52
  165. package/utils/loggin.js +0 -79
  166. package/utils/other.js +0 -92
  167. package/utils/sysex_detector.js +0 -58
  168. package/utils/xg_hacks.js +0 -193
@@ -1,270 +0,0 @@
1
- import { findRIFFListType, readRIFFChunk } from "../basic_soundfont/riff_chunk.js";
2
- import { readBytesAsString } from "../../utils/byte_functions/string.js";
3
- import {
4
- SpessaSynthGroupCollapsed,
5
- SpessaSynthGroupEnd,
6
- SpessaSynthInfo,
7
- SpessaSynthWarn
8
- } from "../../utils/loggin.js";
9
- import { consoleColors } from "../../utils/other.js";
10
- import { readLittleEndian, signedInt16 } from "../../utils/byte_functions/little_endian.js";
11
- import { DLSSample } from "./dls_sample.js";
12
-
13
- const W_FORMAT_TAG = {
14
- PCM: 0x01,
15
- ALAW: 0x6
16
- };
17
-
18
- /**
19
- * @param dataChunk {RiffChunk}
20
- * @param bytesPerSample {number}
21
- * @returns {Float32Array}
22
- */
23
- function readPCM(dataChunk, bytesPerSample)
24
- {
25
- const maxSampleValue = Math.pow(2, bytesPerSample * 8 - 1); // Max value for the sample
26
- const maxUnsigned = Math.pow(2, bytesPerSample * 8);
27
-
28
- let normalizationFactor;
29
- let isUnsigned = false;
30
-
31
- if (bytesPerSample === 1)
32
- {
33
- normalizationFactor = 255; // For 8-bit normalize from 0-255
34
- isUnsigned = true;
35
- }
36
- else
37
- {
38
- normalizationFactor = maxSampleValue; // For 16-bit normalize from -32,768 to 32,767
39
- }
40
- const sampleLength = dataChunk.size / bytesPerSample;
41
- const sampleData = new Float32Array(sampleLength);
42
- for (let i = 0; i < sampleData.length; i++)
43
- {
44
- // read
45
- let sample = readLittleEndian(dataChunk.chunkData, bytesPerSample);
46
- // turn into signed
47
- if (isUnsigned)
48
- {
49
- // normalize unsigned 8-bit sample
50
- sampleData[i] = (sample / normalizationFactor) - 0.5;
51
- }
52
- else
53
- {
54
- // normalize signed 16-bit sample
55
- if (sample >= maxSampleValue)
56
- {
57
- sample -= maxUnsigned;
58
- }
59
- sampleData[i] = sample / normalizationFactor;
60
- }
61
- }
62
- return sampleData;
63
- }
64
-
65
- /**
66
- * @param dataChunk {RiffChunk}
67
- * @param bytesPerSample {number}
68
- * @returns {Float32Array}
69
- */
70
- function readALAW(dataChunk, bytesPerSample)
71
- {
72
- const sampleLength = dataChunk.size / bytesPerSample;
73
- const sampleData = new Float32Array(sampleLength);
74
- for (let i = 0; i < sampleData.length; i++)
75
- {
76
- // read
77
- const input = readLittleEndian(dataChunk.chunkData, bytesPerSample);
78
-
79
- // https://en.wikipedia.org/wiki/G.711#A-law
80
- // re-toggle toggled bits
81
- let sample = input ^ 0x55;
82
-
83
- // remove sign bit
84
- sample &= 0x7F;
85
-
86
- // extract exponent
87
- let exponent = sample >> 4;
88
- // extract mantissa
89
- let mantissa = sample & 0xF;
90
- if (exponent > 0)
91
- {
92
- mantissa += 16; // add leading '1', if exponent > 0
93
- }
94
-
95
- mantissa = (mantissa << 4) + 0x8;
96
- if (exponent > 1)
97
- {
98
- mantissa = mantissa << (exponent - 1);
99
- }
100
-
101
- const s16sample = input > 127 ? mantissa : -mantissa;
102
-
103
- // convert to float
104
- sampleData[i] = s16sample / 32678;
105
- }
106
- return sampleData;
107
- }
108
-
109
- /**
110
- * @this {DLSSoundFont}
111
- * @param waveListChunk {RiffChunk}
112
- */
113
- export function readDLSSamples(waveListChunk)
114
- {
115
- SpessaSynthGroupCollapsed(
116
- "%cLoading Wave samples...",
117
- consoleColors.recognized
118
- );
119
- let sampleID = 0;
120
- while (waveListChunk.chunkData.currentIndex < waveListChunk.chunkData.length)
121
- {
122
- const waveChunk = readRIFFChunk(waveListChunk.chunkData);
123
- this.verifyHeader(waveChunk, "LIST");
124
- this.verifyText(readBytesAsString(waveChunk.chunkData, 4), "wave");
125
-
126
- /**
127
- * @type {RiffChunk[]}
128
- */
129
- const waveChunks = [];
130
- while (waveChunk.chunkData.currentIndex < waveChunk.chunkData.length)
131
- {
132
- waveChunks.push(readRIFFChunk(waveChunk.chunkData));
133
- }
134
-
135
- const fmtChunk = waveChunks.find(c => c.header === "fmt ");
136
- if (!fmtChunk)
137
- {
138
- throw new Error("No fmt chunk in the wave file!");
139
- }
140
- // https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.14393.0/shared/mmreg.h#L2108
141
- const waveFormat = readLittleEndian(fmtChunk.chunkData, 2);
142
- const channelsAmount = readLittleEndian(fmtChunk.chunkData, 2);
143
- if (channelsAmount !== 1)
144
- {
145
- throw new Error(`Only mono samples are supported. Fmt reports ${channelsAmount} channels`);
146
- }
147
- const sampleRate = readLittleEndian(fmtChunk.chunkData, 4);
148
- // skip avg bytes
149
- readLittleEndian(fmtChunk.chunkData, 4);
150
- // blockAlign
151
- readLittleEndian(fmtChunk.chunkData, 2);
152
- // it's bits per sample because one channel
153
- const wBitsPerSample = readLittleEndian(fmtChunk.chunkData, 2);
154
- const bytesPerSample = wBitsPerSample / 8;
155
-
156
- // read the data
157
- let failed = false;
158
- const dataChunk = waveChunks.find(c => c.header === "data");
159
- if (!dataChunk)
160
- {
161
- this.parsingError("No data chunk in the WAVE chunk!");
162
- }
163
- let sampleData;
164
- switch (waveFormat)
165
- {
166
- default:
167
- failed = true;
168
- sampleData = new Float32Array(dataChunk.size / bytesPerSample);
169
- break;
170
-
171
- case W_FORMAT_TAG.PCM:
172
- sampleData = readPCM(dataChunk, bytesPerSample);
173
- break;
174
-
175
- case W_FORMAT_TAG.ALAW:
176
- sampleData = readALAW(dataChunk, bytesPerSample);
177
- break;
178
-
179
- }
180
-
181
- // read sample name
182
- const waveInfo = findRIFFListType(waveChunks, "INFO");
183
- let sampleName = `Unnamed ${sampleID}`;
184
- if (waveInfo)
185
- {
186
- let infoChunk = readRIFFChunk(waveInfo.chunkData);
187
- while (infoChunk.header !== "INAM" && waveInfo.chunkData.currentIndex < waveInfo.chunkData.length)
188
- {
189
- infoChunk = readRIFFChunk(waveInfo.chunkData);
190
- }
191
- if (infoChunk.header === "INAM")
192
- {
193
- sampleName = readBytesAsString(infoChunk.chunkData, infoChunk.size).trim();
194
- }
195
- }
196
-
197
- // correct defaults
198
- let sampleKey = 60;
199
- let samplePitch = 0;
200
- let sampleLoopStart = 0;
201
- let sampleLoopEnd = sampleData.length - 1;
202
- let sampleDbAttenuation = 0;
203
-
204
- // read wsmp
205
- const wsmpChunk = waveChunks.find(c => c.header === "wsmp");
206
- if (wsmpChunk)
207
- {
208
- // skip cbsize
209
- readLittleEndian(wsmpChunk.chunkData, 4);
210
- sampleKey = readLittleEndian(wsmpChunk.chunkData, 2);
211
- // section 1.14.2: Each relative pitch unit represents 1/65536 cents.
212
- // but that doesn't seem true for this one: it's just cents.
213
- samplePitch = signedInt16(
214
- wsmpChunk.chunkData[wsmpChunk.chunkData.currentIndex++],
215
- wsmpChunk.chunkData[wsmpChunk.chunkData.currentIndex++]
216
- );
217
-
218
- // pitch correction: convert hundreds to the root key
219
- const samplePitchSemitones = Math.trunc(samplePitch / 100);
220
- sampleKey += samplePitchSemitones;
221
- samplePitch -= samplePitchSemitones * 100;
222
-
223
-
224
- // gain is applied it manually here (literally multiplying the samples)
225
- const gainCorrection = readLittleEndian(wsmpChunk.chunkData, 4);
226
- // convert to signed and turn into decibels
227
- sampleDbAttenuation = (gainCorrection | 0) / -655360;
228
- // no idea about ful options
229
- readLittleEndian(wsmpChunk.chunkData, 4);
230
- const loopsAmount = readLittleEndian(wsmpChunk.chunkData, 4);
231
- if (loopsAmount === 1)
232
- {
233
- // skip size and type
234
- readLittleEndian(wsmpChunk.chunkData, 8);
235
- sampleLoopStart = readLittleEndian(wsmpChunk.chunkData, 4);
236
- const loopSize = readLittleEndian(wsmpChunk.chunkData, 4);
237
- sampleLoopEnd = sampleLoopStart + loopSize;
238
- }
239
- }
240
- else
241
- {
242
- SpessaSynthWarn("No wsmp chunk in wave... using sane defaults.");
243
- }
244
-
245
- if (failed)
246
- {
247
- console.error(`Failed to load '${sampleName}': Unsupported format: (${waveFormat})`);
248
- }
249
-
250
- this.samples.push(new DLSSample(
251
- sampleName,
252
- sampleRate,
253
- sampleKey,
254
- samplePitch,
255
- sampleLoopStart,
256
- sampleLoopEnd,
257
- sampleData,
258
- sampleDbAttenuation
259
- ));
260
-
261
-
262
- sampleID++;
263
- SpessaSynthInfo(
264
- `%cLoaded sample %c${sampleName}`,
265
- consoleColors.info,
266
- consoleColors.recognized
267
- );
268
- }
269
- SpessaSynthGroupEnd();
270
- }
@@ -1,21 +0,0 @@
1
- import { IndexedByteArray } from "../utils/indexed_array.js";
2
- import { readBytesAsString } from "../utils/byte_functions/string.js";
3
- import { DLSSoundFont } from "./dls/dls_soundfont.js";
4
- import { SoundFont2 } from "./read_sf2/soundfont.js";
5
-
6
- /**
7
- * Loads a soundfont file
8
- * @param buffer {ArrayBuffer}
9
- * @returns {BasicSoundBank}
10
- */
11
- export function loadSoundFont(buffer)
12
- {
13
- const check = buffer.slice(8, 12);
14
- const a = new IndexedByteArray(check);
15
- const id = readBytesAsString(a, 4, undefined, false).toLowerCase();
16
- if (id === "dls ")
17
- {
18
- return new DLSSoundFont(buffer);
19
- }
20
- return new SoundFont2(buffer, false);
21
- }
@@ -1,46 +0,0 @@
1
- import { IndexedByteArray } from "../../utils/indexed_array.js";
2
- import { RiffChunk } from "../basic_soundfont/riff_chunk.js";
3
- import { signedInt16 } from "../../utils/byte_functions/little_endian.js";
4
- import { Generator } from "../basic_soundfont/generator.js";
5
-
6
-
7
- export class ReadGenerator extends Generator
8
- {
9
- /**
10
- * Creates a generator
11
- * @param dataArray {IndexedByteArray}
12
- */
13
- constructor(dataArray)
14
- {
15
- super();
16
- // 4 bytes:
17
- // type, type, type, value
18
- const i = dataArray.currentIndex;
19
- /**
20
- * @type {generatorTypes|number}
21
- */
22
- this.generatorType = (dataArray[i + 1] << 8) | dataArray[i];
23
- this.generatorValue = signedInt16(dataArray[i + 2], dataArray[i + 3]);
24
- dataArray.currentIndex += 4;
25
- }
26
- }
27
-
28
- /**
29
- * Reads the generator read
30
- * @param generatorChunk {RiffChunk}
31
- * @returns {Generator[]}
32
- */
33
- export function readGenerators(generatorChunk)
34
- {
35
- let gens = [];
36
- while (generatorChunk.chunkData.length > generatorChunk.chunkData.currentIndex)
37
- {
38
- gens.push(new ReadGenerator(generatorChunk.chunkData));
39
- }
40
- if (gens.length > 1)
41
- {
42
- // remove terminal
43
- gens.pop();
44
- }
45
- return gens;
46
- }
@@ -1,66 +0,0 @@
1
- import { RiffChunk } from "../basic_soundfont/riff_chunk.js";
2
- import { InstrumentZone } from "./zones.js";
3
- import { readLittleEndian } from "../../utils/byte_functions/little_endian.js";
4
- import { readBytesAsString } from "../../utils/byte_functions/string.js";
5
- import { BasicInstrument } from "../basic_soundfont/basic_instrument.js";
6
-
7
- /**
8
- * instrument.js
9
- * purpose: parses soundfont instrument and stores them as a class
10
- */
11
-
12
- export class Instrument extends BasicInstrument
13
- {
14
- /**
15
- * Creates an instrument
16
- * @param instrumentChunk {RiffChunk}
17
- */
18
- constructor(instrumentChunk)
19
- {
20
- super();
21
- this.instrumentName = readBytesAsString(instrumentChunk.chunkData, 20).trim();
22
- this.instrumentZoneIndex = readLittleEndian(instrumentChunk.chunkData, 2);
23
- this.instrumentZonesAmount = 0;
24
- }
25
-
26
- /**
27
- * Loads all the instrument zones, given the amount
28
- * @param amount {number}
29
- * @param zones {InstrumentZone[]}
30
- */
31
- getInstrumentZones(amount, zones)
32
- {
33
- this.instrumentZonesAmount = amount;
34
- for (let i = this.instrumentZoneIndex; i < this.instrumentZonesAmount + this.instrumentZoneIndex; i++)
35
- {
36
- this.instrumentZones.push(zones[i]);
37
- }
38
- }
39
- }
40
-
41
- /**
42
- * Reads the instruments
43
- * @param instrumentChunk {RiffChunk}
44
- * @param instrumentZones {InstrumentZone[]}
45
- * @returns {Instrument[]}
46
- */
47
- export function readInstruments(instrumentChunk, instrumentZones)
48
- {
49
- let instruments = [];
50
- while (instrumentChunk.chunkData.length > instrumentChunk.chunkData.currentIndex)
51
- {
52
- let instrument = new Instrument(instrumentChunk);
53
- if (instruments.length > 0)
54
- {
55
- let instrumentsAmount = instrument.instrumentZoneIndex - instruments[instruments.length - 1].instrumentZoneIndex;
56
- instruments[instruments.length - 1].getInstrumentZones(instrumentsAmount, instrumentZones);
57
- }
58
- instruments.push(instrument);
59
- }
60
- if (instruments.length > 1)
61
- {
62
- // remove EOI
63
- instruments.pop();
64
- }
65
- return instruments;
66
- }
@@ -1,36 +0,0 @@
1
- import { readLittleEndian, signedInt16 } from "../../utils/byte_functions/little_endian.js";
2
- import { IndexedByteArray } from "../../utils/indexed_array.js";
3
- import { Modulator } from "../basic_soundfont/modulator.js";
4
-
5
-
6
- export class ReadModulator extends Modulator
7
- {
8
- /**
9
- * Creates a modulator
10
- * @param dataArray {IndexedByteArray}
11
- */
12
- constructor(dataArray)
13
- {
14
- const srcEnum = readLittleEndian(dataArray, 2);
15
- const destination = readLittleEndian(dataArray, 2);
16
- const amount = signedInt16(dataArray[dataArray.currentIndex++], dataArray[dataArray.currentIndex++]);
17
- const secSrcEnum = readLittleEndian(dataArray, 2);
18
- const transformType = readLittleEndian(dataArray, 2);
19
- super(srcEnum, secSrcEnum, destination, amount, transformType);
20
- }
21
- }
22
-
23
- /**
24
- * Reads the modulator read
25
- * @param modulatorChunk {RiffChunk}
26
- * @returns {Modulator[]}
27
- */
28
- export function readModulators(modulatorChunk)
29
- {
30
- let gens = [];
31
- while (modulatorChunk.chunkData.length > modulatorChunk.chunkData.currentIndex)
32
- {
33
- gens.push(new ReadModulator(modulatorChunk.chunkData));
34
- }
35
- return gens;
36
- }
@@ -1,80 +0,0 @@
1
- import { RiffChunk } from "../basic_soundfont/riff_chunk.js";
2
- import { PresetZone } from "./zones.js";
3
- import { readLittleEndian } from "../../utils/byte_functions/little_endian.js";
4
- import { readBytesAsString } from "../../utils/byte_functions/string.js";
5
- import { BasicPreset } from "../basic_soundfont/basic_preset.js";
6
-
7
- /**
8
- * parses soundfont presets, also includes function for getting the generators and samples from midi note and velocity
9
- */
10
-
11
- export class Preset extends BasicPreset
12
- {
13
- /**
14
- * Creates a preset
15
- * @param presetChunk {RiffChunk}
16
- * @param sf2 {BasicSoundBank}
17
- */
18
- constructor(presetChunk, sf2)
19
- {
20
- super(sf2);
21
- this.presetName = readBytesAsString(presetChunk.chunkData, 20)
22
- .trim()
23
- .replace(/\d{3}:\d{3}/, ""); // remove those pesky "000:001"
24
-
25
- this.program = readLittleEndian(presetChunk.chunkData, 2);
26
- this.bank = readLittleEndian(presetChunk.chunkData, 2);
27
- this.presetZoneStartIndex = readLittleEndian(presetChunk.chunkData, 2);
28
-
29
- // read the dword
30
- this.library = readLittleEndian(presetChunk.chunkData, 4);
31
- this.genre = readLittleEndian(presetChunk.chunkData, 4);
32
- this.morphology = readLittleEndian(presetChunk.chunkData, 4);
33
- this.presetZonesAmount = 0;
34
- }
35
-
36
- /**
37
- * Loads all the preset zones, given the amount
38
- * @param amount {number}
39
- * @param zones {PresetZone[]}
40
- */
41
- getPresetZones(amount, zones)
42
- {
43
- this.presetZonesAmount = amount;
44
- for (let i = this.presetZoneStartIndex; i < this.presetZonesAmount + this.presetZoneStartIndex; i++)
45
- {
46
- this.presetZones.push(zones[i]);
47
- }
48
- }
49
- }
50
-
51
- /**
52
- * Reads the presets
53
- * @param presetChunk {RiffChunk}
54
- * @param presetZones {PresetZone[]}
55
- * @param sf2 {BasicSoundBank}
56
- * @returns {Preset[]}
57
- */
58
- export function readPresets(presetChunk, presetZones, sf2)
59
- {
60
- /**
61
- * @type {Preset[]}
62
- */
63
- let presets = [];
64
- while (presetChunk.chunkData.length > presetChunk.chunkData.currentIndex)
65
- {
66
- let preset = new Preset(presetChunk, sf2);
67
- if (presets.length > 0)
68
- {
69
- let presetZonesAmount = preset.presetZoneStartIndex - presets[presets.length - 1].presetZoneStartIndex;
70
- presets[presets.length - 1].getPresetZones(presetZonesAmount, presetZones);
71
- }
72
- presets.push(preset);
73
- }
74
- // remove EOP
75
- if (presets.length > 1)
76
- {
77
- presets.pop();
78
- }
79
- return presets;
80
- }