spessasynth_lib 3.25.23 → 3.26.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 (162) hide show
  1. package/README.md +29 -114
  2. package/external_midi/midi_handler.js +14 -14
  3. package/external_midi/web_midi_link.js +3 -3
  4. package/index.js +33 -33
  5. package/package.json +19 -6
  6. package/{midi → sequencer}/midi_data.js +1 -1
  7. package/sequencer/{worklet_wrapper/sequencer.js → sequencer.js} +13 -12
  8. package/sequencer/{worklet_wrapper/sequencer_message.js → sequencer_message.js} +1 -1
  9. package/synthetizer/README.md +29 -1
  10. package/synthetizer/audio_effects/reverb_as_binary.js +2 -2
  11. package/synthetizer/{worklet_wrapper/key_modifier_manager.js → key_modifier_manager.js} +11 -2
  12. package/synthetizer/{worklet_wrapper/synth_event_handler.js → synth_event_handler.js} +16 -13
  13. package/synthetizer/{worklet_wrapper/synth_soundfont_manager.js → synth_soundfont_manager.js} +8 -5
  14. package/synthetizer/{worklet_wrapper/synthetizer.js → synthetizer.js} +29 -23
  15. package/synthetizer/{audio_engine/message_protocol/worklet_message.js → worklet_message.js} +15 -2
  16. package/synthetizer/{worklet_wrapper/worklet_processor.js → worklet_processor.js} +214 -31
  17. package/synthetizer/worklet_processor.min.js +13 -12
  18. package/synthetizer/worklet_processor.min.js.map +7 -0
  19. package/synthetizer/{worklet_wrapper/worklet_url.js → worklet_url.js} +2 -0
  20. package/utils/buffer_to_wav.js +7 -165
  21. package/utils/other.js +3 -84
  22. package/externals/fflate/LICENSE +0 -21
  23. package/externals/fflate/fflate.min.js +0 -1
  24. package/externals/stbvorbis_sync/@types/stbvorbis_sync.d.ts +0 -12
  25. package/externals/stbvorbis_sync/LICENSE +0 -202
  26. package/externals/stbvorbis_sync/NOTICE +0 -6
  27. package/externals/stbvorbis_sync/stbvorbis_sync.min.js +0 -1
  28. package/midi/README.md +0 -32
  29. package/midi/basic_midi.js +0 -565
  30. package/midi/midi_builder.js +0 -202
  31. package/midi/midi_loader.js +0 -324
  32. package/midi/midi_message.js +0 -254
  33. package/midi/midi_sequence.js +0 -225
  34. package/midi/midi_tools/get_note_times.js +0 -154
  35. package/midi/midi_tools/midi_editor.js +0 -611
  36. package/midi/midi_tools/midi_writer.js +0 -99
  37. package/midi/midi_tools/rmidi_writer.js +0 -567
  38. package/midi/midi_tools/used_keys_loaded.js +0 -238
  39. package/midi/xmf_loader.js +0 -454
  40. package/sequencer/sequencer_engine/events.js +0 -104
  41. package/sequencer/sequencer_engine/play.js +0 -353
  42. package/sequencer/sequencer_engine/process_event.js +0 -169
  43. package/sequencer/sequencer_engine/process_tick.js +0 -106
  44. package/sequencer/sequencer_engine/sequencer_engine.js +0 -335
  45. package/sequencer/sequencer_engine/song_control.js +0 -229
  46. package/soundfont/README.md +0 -13
  47. package/soundfont/basic_soundfont/basic_instrument.js +0 -77
  48. package/soundfont/basic_soundfont/basic_preset.js +0 -336
  49. package/soundfont/basic_soundfont/basic_sample.js +0 -197
  50. package/soundfont/basic_soundfont/basic_soundfont.js +0 -565
  51. package/soundfont/basic_soundfont/basic_zone.js +0 -64
  52. package/soundfont/basic_soundfont/basic_zones.js +0 -43
  53. package/soundfont/basic_soundfont/generator.js +0 -220
  54. package/soundfont/basic_soundfont/modulator.js +0 -378
  55. package/soundfont/basic_soundfont/riff_chunk.js +0 -149
  56. package/soundfont/basic_soundfont/write_dls/art2.js +0 -173
  57. package/soundfont/basic_soundfont/write_dls/articulator.js +0 -49
  58. package/soundfont/basic_soundfont/write_dls/combine_zones.js +0 -400
  59. package/soundfont/basic_soundfont/write_dls/ins.js +0 -103
  60. package/soundfont/basic_soundfont/write_dls/lins.js +0 -18
  61. package/soundfont/basic_soundfont/write_dls/modulator_converter.js +0 -330
  62. package/soundfont/basic_soundfont/write_dls/rgn2.js +0 -121
  63. package/soundfont/basic_soundfont/write_dls/wave.js +0 -94
  64. package/soundfont/basic_soundfont/write_dls/write_dls.js +0 -119
  65. package/soundfont/basic_soundfont/write_dls/wsmp.js +0 -78
  66. package/soundfont/basic_soundfont/write_dls/wvpl.js +0 -32
  67. package/soundfont/basic_soundfont/write_sf2/ibag.js +0 -39
  68. package/soundfont/basic_soundfont/write_sf2/igen.js +0 -80
  69. package/soundfont/basic_soundfont/write_sf2/imod.js +0 -46
  70. package/soundfont/basic_soundfont/write_sf2/inst.js +0 -34
  71. package/soundfont/basic_soundfont/write_sf2/pbag.js +0 -39
  72. package/soundfont/basic_soundfont/write_sf2/pgen.js +0 -82
  73. package/soundfont/basic_soundfont/write_sf2/phdr.js +0 -42
  74. package/soundfont/basic_soundfont/write_sf2/pmod.js +0 -46
  75. package/soundfont/basic_soundfont/write_sf2/sdta.js +0 -80
  76. package/soundfont/basic_soundfont/write_sf2/shdr.js +0 -55
  77. package/soundfont/basic_soundfont/write_sf2/write.js +0 -222
  78. package/soundfont/dls/articulator_converter.js +0 -396
  79. package/soundfont/dls/dls_destinations.js +0 -38
  80. package/soundfont/dls/dls_preset.js +0 -44
  81. package/soundfont/dls/dls_sample.js +0 -75
  82. package/soundfont/dls/dls_soundfont.js +0 -186
  83. package/soundfont/dls/dls_sources.js +0 -62
  84. package/soundfont/dls/dls_zone.js +0 -95
  85. package/soundfont/dls/read_articulation.js +0 -299
  86. package/soundfont/dls/read_instrument.js +0 -121
  87. package/soundfont/dls/read_instrument_list.js +0 -17
  88. package/soundfont/dls/read_lart.js +0 -35
  89. package/soundfont/dls/read_region.js +0 -152
  90. package/soundfont/dls/read_samples.js +0 -270
  91. package/soundfont/load_soundfont.js +0 -21
  92. package/soundfont/read_sf2/generators.js +0 -46
  93. package/soundfont/read_sf2/instruments.js +0 -66
  94. package/soundfont/read_sf2/modulators.js +0 -36
  95. package/soundfont/read_sf2/presets.js +0 -80
  96. package/soundfont/read_sf2/samples.js +0 -304
  97. package/soundfont/read_sf2/soundfont.js +0 -305
  98. package/soundfont/read_sf2/zones.js +0 -263
  99. package/synthetizer/audio_engine/README.md +0 -25
  100. package/synthetizer/audio_engine/engine_components/compute_modulator.js +0 -266
  101. package/synthetizer/audio_engine/engine_components/controller_tables.js +0 -88
  102. package/synthetizer/audio_engine/engine_components/key_modifier_manager.js +0 -149
  103. package/synthetizer/audio_engine/engine_components/lfo.js +0 -26
  104. package/synthetizer/audio_engine/engine_components/lowpass_filter.js +0 -282
  105. package/synthetizer/audio_engine/engine_components/midi_audio_channel.js +0 -471
  106. package/synthetizer/audio_engine/engine_components/modulation_envelope.js +0 -181
  107. package/synthetizer/audio_engine/engine_components/modulator_curves.js +0 -89
  108. package/synthetizer/audio_engine/engine_components/soundfont_manager.js +0 -228
  109. package/synthetizer/audio_engine/engine_components/stereo_panner.js +0 -120
  110. package/synthetizer/audio_engine/engine_components/unit_converter.js +0 -73
  111. package/synthetizer/audio_engine/engine_components/voice.js +0 -519
  112. package/synthetizer/audio_engine/engine_components/volume_envelope.js +0 -401
  113. package/synthetizer/audio_engine/engine_components/wavetable_oscillator.js +0 -263
  114. package/synthetizer/audio_engine/engine_methods/controller_control/controller_change.js +0 -132
  115. package/synthetizer/audio_engine/engine_methods/controller_control/master_parameters.js +0 -48
  116. package/synthetizer/audio_engine/engine_methods/controller_control/reset_controllers.js +0 -241
  117. package/synthetizer/audio_engine/engine_methods/create_midi_channel.js +0 -27
  118. package/synthetizer/audio_engine/engine_methods/data_entry/data_entry_coarse.js +0 -253
  119. package/synthetizer/audio_engine/engine_methods/data_entry/data_entry_fine.js +0 -66
  120. package/synthetizer/audio_engine/engine_methods/mute_channel.js +0 -17
  121. package/synthetizer/audio_engine/engine_methods/note_on.js +0 -175
  122. package/synthetizer/audio_engine/engine_methods/portamento_time.js +0 -92
  123. package/synthetizer/audio_engine/engine_methods/program_change.js +0 -61
  124. package/synthetizer/audio_engine/engine_methods/render_voice.js +0 -196
  125. package/synthetizer/audio_engine/engine_methods/soundfont_management/clear_sound_font.js +0 -30
  126. package/synthetizer/audio_engine/engine_methods/soundfont_management/get_preset.js +0 -22
  127. package/synthetizer/audio_engine/engine_methods/soundfont_management/reload_sound_font.js +0 -40
  128. package/synthetizer/audio_engine/engine_methods/soundfont_management/send_preset_list.js +0 -34
  129. package/synthetizer/audio_engine/engine_methods/soundfont_management/set_embedded_sound_font.js +0 -21
  130. package/synthetizer/audio_engine/engine_methods/stopping_notes/kill_note.js +0 -20
  131. package/synthetizer/audio_engine/engine_methods/stopping_notes/note_off.js +0 -55
  132. package/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_channels.js +0 -16
  133. package/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_notes.js +0 -30
  134. package/synthetizer/audio_engine/engine_methods/stopping_notes/voice_killing.js +0 -63
  135. package/synthetizer/audio_engine/engine_methods/system_exclusive.js +0 -776
  136. package/synthetizer/audio_engine/engine_methods/tuning_control/channel_pressure.js +0 -24
  137. package/synthetizer/audio_engine/engine_methods/tuning_control/pitch_wheel.js +0 -33
  138. package/synthetizer/audio_engine/engine_methods/tuning_control/poly_pressure.js +0 -31
  139. package/synthetizer/audio_engine/engine_methods/tuning_control/set_master_tuning.js +0 -15
  140. package/synthetizer/audio_engine/engine_methods/tuning_control/set_modulation_depth.js +0 -27
  141. package/synthetizer/audio_engine/engine_methods/tuning_control/set_octave_tuning.js +0 -19
  142. package/synthetizer/audio_engine/engine_methods/tuning_control/set_tuning.js +0 -27
  143. package/synthetizer/audio_engine/engine_methods/tuning_control/transpose_all_channels.js +0 -15
  144. package/synthetizer/audio_engine/engine_methods/tuning_control/transpose_channel.js +0 -34
  145. package/synthetizer/audio_engine/main_processor.js +0 -765
  146. package/synthetizer/audio_engine/message_protocol/README.md +0 -13
  147. package/synthetizer/audio_engine/message_protocol/message_sending.js +0 -22
  148. package/synthetizer/audio_engine/snapshot/apply_synthesizer_snapshot.js +0 -14
  149. package/synthetizer/audio_engine/snapshot/channel_snapshot.js +0 -175
  150. package/synthetizer/audio_engine/snapshot/synthesizer_snapshot.js +0 -122
  151. package/synthetizer/synth_constants.js +0 -20
  152. package/utils/README.md +0 -5
  153. package/utils/byte_functions/big_endian.js +0 -32
  154. package/utils/byte_functions/little_endian.js +0 -77
  155. package/utils/byte_functions/string.js +0 -107
  156. package/utils/byte_functions/variable_length_quantity.js +0 -42
  157. package/utils/indexed_array.js +0 -52
  158. package/utils/loggin.js +0 -79
  159. package/utils/sysex_detector.js +0 -58
  160. package/utils/xg_hacks.js +0 -193
  161. /package/sequencer/{worklet_wrapper/default_sequencer_options.js → default_sequencer_options.js} +0 -0
  162. /package/synthetizer/{worklet_wrapper/sfman_message.js → sfman_message.js} +0 -0
@@ -1,330 +0,0 @@
1
- import { midiControllers } from "../../../midi/midi_message.js";
2
- import { DLSSources } from "../../dls/dls_sources.js";
3
- import { modulatorCurveTypes, modulatorSources } from "../modulator.js";
4
- import { generatorTypes } from "../generator.js";
5
- import { DLSDestinations } from "../../dls/dls_destinations.js";
6
- import { Articulator } from "./articulator.js";
7
- import { SpessaSynthWarn } from "../../../utils/loggin.js";
8
-
9
-
10
- /**
11
- * @param cc {boolean}
12
- * @param index {number}
13
- * @returns {number|undefined}
14
- */
15
- function getDLSSourceFromSf2Source(cc, index)
16
- {
17
- if (cc)
18
- {
19
- switch (index)
20
- {
21
- default:
22
- // DLS supports limited controllers
23
- return undefined;
24
-
25
- case midiControllers.modulationWheel:
26
- return DLSSources.modulationWheel;
27
- case midiControllers.mainVolume:
28
- return DLSSources.volume;
29
- case midiControllers.pan:
30
- return DLSSources.pan;
31
- case midiControllers.expressionController:
32
- return DLSSources.expression;
33
- case midiControllers.chorusDepth:
34
- return DLSSources.chorus;
35
- case midiControllers.reverbDepth:
36
- return DLSSources.reverb;
37
- }
38
- }
39
- else
40
- {
41
- switch (index)
42
- {
43
- default:
44
- // cannot be a DLS articulator
45
- return undefined;
46
-
47
- case modulatorSources.noteOnKeyNum:
48
- return DLSSources.keyNum;
49
- case modulatorSources.noteOnVelocity:
50
- return DLSSources.velocity;
51
- case modulatorSources.noController:
52
- return DLSSources.none;
53
- case modulatorSources.polyPressure:
54
- return DLSSources.polyPressure;
55
- case modulatorSources.channelPressure:
56
- return DLSSources.channelPressure;
57
- case modulatorSources.pitchWheel:
58
- return DLSSources.pitchWheel;
59
- case modulatorSources.pitchWheelRange:
60
- return DLSSources.pitchWheelRange;
61
- }
62
- }
63
- }
64
-
65
- /**
66
- * @param dest {number}
67
- * @param amount {number}
68
- * @returns {number|undefined|{dest: number, amount: number}}
69
- */
70
- function getDLSDestinationFromSf2(dest, amount)
71
- {
72
- switch (dest)
73
- {
74
- default:
75
- return undefined;
76
-
77
- case generatorTypes.initialAttenuation:
78
- // the amount does not get EMU corrected here, as this only applies to modulator attenuation
79
- // the generator (affected) attenuation is handled in wsmp.
80
- return { dest: DLSDestinations.gain, amount: -amount };
81
- case generatorTypes.fineTune:
82
- return DLSDestinations.pitch;
83
- case generatorTypes.pan:
84
- return DLSDestinations.pan;
85
- case generatorTypes.keyNum:
86
- return DLSDestinations.keyNum;
87
-
88
- case generatorTypes.reverbEffectsSend:
89
- return DLSDestinations.reverbSend;
90
- case generatorTypes.chorusEffectsSend:
91
- return DLSDestinations.chorusSend;
92
-
93
- case generatorTypes.freqModLFO:
94
- return DLSDestinations.modLfoFreq;
95
- case generatorTypes.delayModLFO:
96
- return DLSDestinations.modLfoDelay;
97
-
98
- case generatorTypes.delayVibLFO:
99
- return DLSDestinations.vibLfoDelay;
100
- case generatorTypes.freqVibLFO:
101
- return DLSDestinations.vibLfoFreq;
102
-
103
- case generatorTypes.delayVolEnv:
104
- return DLSDestinations.volEnvDelay;
105
- case generatorTypes.attackVolEnv:
106
- return DLSDestinations.volEnvAttack;
107
- case generatorTypes.holdVolEnv:
108
- return DLSDestinations.volEnvHold;
109
- case generatorTypes.decayVolEnv:
110
- return DLSDestinations.volEnvDecay;
111
- case generatorTypes.sustainVolEnv:
112
- return { dest: DLSDestinations.volEnvSustain, amount: 1000 - amount };
113
- case generatorTypes.releaseVolEnv:
114
- return DLSDestinations.volEnvRelease;
115
-
116
- case generatorTypes.delayModEnv:
117
- return DLSDestinations.modEnvDelay;
118
- case generatorTypes.attackModEnv:
119
- return DLSDestinations.modEnvAttack;
120
- case generatorTypes.holdModEnv:
121
- return DLSDestinations.modEnvHold;
122
- case generatorTypes.decayModEnv:
123
- return DLSDestinations.modEnvDecay;
124
- case generatorTypes.sustainModEnv:
125
- return { dest: DLSDestinations.modEnvSustain, amount: 1000 - amount };
126
- case generatorTypes.releaseModEnv:
127
- return DLSDestinations.modEnvRelease;
128
-
129
- case generatorTypes.initialFilterFc:
130
- return DLSDestinations.filterCutoff;
131
- case generatorTypes.initialFilterQ:
132
- return DLSDestinations.filterQ;
133
- }
134
- }
135
-
136
- /**
137
- * @param dest {number}
138
- * @param amt {number}
139
- * @returns {{source: DLSSources, dest: DLSDestinations, amt: number, isBipolar: boolean}|undefined}
140
- */
141
- function checkSF2SpecialCombos(dest, amt)
142
- {
143
-
144
- switch (dest)
145
- {
146
- default:
147
- return undefined;
148
- // mod env
149
- case generatorTypes.modEnvToFilterFc:
150
- return { source: DLSSources.modEnv, dest: DLSDestinations.filterCutoff, amt: amt, isBipolar: false };
151
- case generatorTypes.modEnvToPitch:
152
- return { source: DLSSources.modEnv, dest: DLSDestinations.pitch, amt: amt, isBipolar: false };
153
-
154
- // mod lfo
155
- case generatorTypes.modLfoToFilterFc:
156
- return { source: DLSSources.modLfo, dest: DLSDestinations.filterCutoff, amt: amt, isBipolar: true };
157
- case generatorTypes.modLfoToVolume:
158
- return { source: DLSSources.modLfo, dest: DLSDestinations.gain, amt: amt, isBipolar: true };
159
- case generatorTypes.modLfoToPitch:
160
- return { source: DLSSources.modLfo, dest: DLSDestinations.pitch, amt: amt, isBipolar: true };
161
-
162
- // vib lfo
163
- case generatorTypes.vibLfoToPitch:
164
- return { source: DLSSources.vibratoLfo, dest: DLSDestinations.pitch, amt: amt, isBipolar: true };
165
-
166
- // key to something
167
- case generatorTypes.keyNumToVolEnvHold:
168
- return {
169
- source: DLSSources.keyNum,
170
- dest: DLSDestinations.volEnvHold,
171
- amt: amt,
172
- isBipolar: true
173
- };
174
- case generatorTypes.keyNumToVolEnvDecay:
175
- return {
176
- source: DLSSources.keyNum,
177
- dest: DLSDestinations.volEnvDecay,
178
- amt: amt,
179
- isBipolar: true
180
- };
181
- case generatorTypes.keyNumToModEnvHold:
182
- return {
183
- source: DLSSources.keyNum,
184
- dest: DLSDestinations.modEnvHold,
185
- amt: amt,
186
- isBipolar: true
187
- };
188
- case generatorTypes.keyNumToModEnvDecay:
189
- return {
190
- source: DLSSources.keyNum,
191
- dest: DLSDestinations.modEnvDecay,
192
- amt: amt,
193
- isBipolar: true
194
- };
195
-
196
- // Scale tuning is implemented in DLS via an articulator:
197
- // keyNum to relative pitch at 12,800 cents.
198
- // Change that to scale tuning * 128.
199
- // Therefore, a regular scale is still 12,800, half is 6400, etc.
200
- case generatorTypes.scaleTuning:
201
- return {
202
- source: DLSSources.keyNum,
203
- dest: DLSDestinations.pitch,
204
- amt: amt * 128,
205
- isBipolar: false // according to table 4, this should be false.
206
- };
207
- }
208
- }
209
-
210
- /**
211
- * @param gen {Generator}
212
- * @returns {Articulator|undefined}
213
- */
214
- export function getDLSArticulatorFromSf2Generator(gen)
215
- {
216
- const dest = getDLSDestinationFromSf2(gen.generatorType, gen.generatorValue);
217
- let destination = dest;
218
- let source = 0;
219
- let amount = gen.generatorValue;
220
- if (dest?.amount !== undefined)
221
- {
222
- amount = dest.amount;
223
- destination = dest.dest;
224
- }
225
- // check for special combo
226
- const combo = checkSF2SpecialCombos(gen.generatorType, gen.generatorValue);
227
- if (combo !== undefined)
228
- {
229
- amount = combo.amt;
230
- destination = combo.dest;
231
- source = combo.source;
232
- }
233
- else if (destination === undefined)
234
- {
235
- SpessaSynthWarn(`Invalid generator type: ${gen.generatorType}`);
236
- return undefined;
237
- }
238
- return new Articulator(
239
- source,
240
- 0,
241
- destination,
242
- amount,
243
- 0
244
- );
245
- }
246
-
247
-
248
- /**
249
- * @param mod {Modulator}
250
- * @returns {Articulator|undefined}
251
- */
252
- export function getDLSArticulatorFromSf2Modulator(mod)
253
- {
254
- if (mod.transformType !== 0)
255
- {
256
- SpessaSynthWarn("Other transform types are not supported.");
257
- return undefined;
258
- }
259
- let source = getDLSSourceFromSf2Source(mod.sourceUsesCC, mod.sourceIndex);
260
- let sourceTransformType = mod.sourceCurveType;
261
- let sourceBipolar = mod.sourcePolarity;
262
- let sourceDirection = mod.sourceDirection;
263
- if (source === undefined)
264
- {
265
- SpessaSynthWarn(`Invalid source: ${mod.sourceIndex}, CC: ${mod.sourceUsesCC}`);
266
- return undefined;
267
- }
268
- // Attenuation is the opposite of gain. Invert.
269
- if (mod.modulatorDestination === generatorTypes.initialAttenuation)
270
- {
271
- sourceDirection = sourceDirection === 1 ? 0 : 1;
272
- }
273
- let control = getDLSSourceFromSf2Source(mod.secSrcUsesCC, mod.secSrcIndex);
274
- let controlTransformType = mod.secSrcCurveType;
275
- let controlBipolar = mod.secSrcPolarity;
276
- let controlDirection = mod.secSrcDirection;
277
- if (control === undefined)
278
- {
279
- SpessaSynthWarn(`Invalid secondary source: ${mod.secSrcIndex}, CC: ${mod.secSrcUsesCC}`);
280
- return undefined;
281
- }
282
- let dlsDestinationFromSf2 = getDLSDestinationFromSf2(mod.modulatorDestination, mod.transformAmount);
283
- let destination = dlsDestinationFromSf2;
284
- let amt = mod.transformAmount;
285
- if (dlsDestinationFromSf2?.dest !== undefined)
286
- {
287
- destination = dlsDestinationFromSf2.dest;
288
- amt = dlsDestinationFromSf2.amount;
289
- }
290
- const specialCombo = checkSF2SpecialCombos(mod.modulatorDestination, mod.transformAmount);
291
- if (specialCombo !== undefined)
292
- {
293
- amt = specialCombo.amt;
294
- // move the source to control
295
- control = source;
296
- controlTransformType = sourceTransformType;
297
- controlBipolar = sourceBipolar;
298
- controlDirection = sourceDirection;
299
-
300
- // set source as static as it's either: env, lfo or key num
301
- sourceTransformType = modulatorCurveTypes.linear;
302
- sourceBipolar = specialCombo.isBipolar ? 1 : 0;
303
- sourceDirection = 0;
304
- source = specialCombo.source;
305
- destination = specialCombo.dest;
306
- }
307
- else if (destination === undefined)
308
- {
309
- SpessaSynthWarn(`Invalid destination: ${mod.modulatorDestination}`);
310
- return undefined;
311
- }
312
-
313
- // source curve type maps to a desfont curve type in section 2.10, table 9
314
- let transform = 0;
315
- transform |= controlTransformType << 4;
316
- transform |= controlBipolar << 8;
317
- transform |= controlDirection << 9;
318
-
319
- // use the source curve in output transform
320
- transform |= sourceTransformType;
321
- transform |= sourceBipolar << 14;
322
- transform |= sourceDirection << 15;
323
- return new Articulator(
324
- source,
325
- control,
326
- destination,
327
- amt,
328
- transform
329
- );
330
- }
@@ -1,121 +0,0 @@
1
- import { combineArrays, IndexedByteArray } from "../../../utils/indexed_array.js";
2
- import { writeDword, writeWord } from "../../../utils/byte_functions/little_endian.js";
3
- import { generatorTypes } from "../generator.js";
4
- import { writeRIFFOddSize } from "../riff_chunk.js";
5
- import { writeWavesample } from "./wsmp.js";
6
- import { writeArticulator } from "./art2.js";
7
-
8
- /**
9
- * @param zone {BasicInstrumentZone}
10
- * @param globalZone {BasicInstrumentZone}
11
- * @this {BasicSoundBank}
12
- * @returns {IndexedByteArray}
13
- */
14
- export function writeDLSRegion(zone, globalZone)
15
- {
16
- // region header
17
- const rgnhData = new IndexedByteArray(12);
18
- // keyRange
19
- writeWord(rgnhData, Math.max(zone.keyRange.min, 0));
20
- writeWord(rgnhData, zone.keyRange.max);
21
- // velRange
22
- writeWord(rgnhData, Math.max(zone.velRange.min, 0));
23
- writeWord(rgnhData, zone.velRange.max);
24
- // fusOptions: 0 it seems
25
- writeWord(rgnhData, 0);
26
- // keyGroup (exclusive class)
27
- const exclusive = zone.getGeneratorValue(generatorTypes.exclusiveClass, 0);
28
- writeWord(rgnhData, exclusive);
29
- // usLayer
30
- writeWord(rgnhData, 0);
31
- const rgnh = writeRIFFOddSize(
32
- "rgnh",
33
- rgnhData
34
- );
35
-
36
- let rootKey = zone.getGeneratorValue(generatorTypes.overridingRootKey, zone.sample.samplePitch);
37
-
38
- // a lot of soundfonts like to set scale tuning to 0 in drums and keep the key at 60
39
- // since we implement scale tuning via a dls articulator and fluid doesn't support these,
40
- // change the root key here
41
- const scaleTuning = zone.getGeneratorValue(
42
- generatorTypes.scaleTuning,
43
- globalZone.getGeneratorValue(generatorTypes.scaleTuning, 100)
44
- );
45
- if (scaleTuning === 0 && zone.keyRange.max - zone.keyRange.min === 0)
46
- {
47
- rootKey = zone.keyRange.min;
48
- }
49
-
50
- // wave sample (Wsmp)
51
- const wsmp = writeWavesample(
52
- zone.sample,
53
- rootKey,
54
- zone.getGeneratorValue(
55
- generatorTypes.fineTune,
56
- 0
57
- ) + zone.getGeneratorValue(generatorTypes.coarseTune, 0) * 100
58
- + zone.sample.samplePitchCorrection,
59
- zone.getGeneratorValue(generatorTypes.initialAttenuation, 0),
60
- // calculate loop with offsets
61
- zone.sample.sampleLoopStartIndex
62
- + zone.getGeneratorValue(generatorTypes.startloopAddrsOffset, 0)
63
- + zone.getGeneratorValue(generatorTypes.startloopAddrsCoarseOffset, 0) * 32768,
64
- zone.sample.sampleLoopEndIndex
65
- + zone.getGeneratorValue(generatorTypes.endloopAddrsOffset, 0)
66
- + zone.getGeneratorValue(generatorTypes.endloopAddrsCoarseOffset, 0) * 32768,
67
- zone.getGeneratorValue(generatorTypes.sampleModes, 0)
68
- );
69
-
70
- // wave link (wlnk)
71
- const wlnkData = new IndexedByteArray(12);
72
- writeWord(wlnkData, 0); // fusOptions
73
- writeWord(wlnkData, 0); // usPhaseGroup
74
- // let sampleType = 0;
75
- // switch (zone.sample.sampleType)
76
- // {
77
- // default:
78
- // case 1:
79
- // case 4:
80
- // // mono/left
81
- // sampleType = 0;
82
- // break;
83
- //
84
- // case 2:
85
- // // right
86
- // sampleType = 1;
87
- // }
88
- // 1 means that the first bit is on so mono/left
89
- writeDword(wlnkData, 1); // ulChannel
90
- writeDword(wlnkData, this.samples.indexOf(zone.sample)); // ulTableIndex
91
- const wlnk = writeRIFFOddSize(
92
- "wlnk",
93
- wlnkData
94
- );
95
-
96
- // art
97
- let lar2 = new IndexedByteArray(0);
98
- if (zone.modulators.length + zone.generators.length > 0)
99
- {
100
- const art2 = writeArticulator(zone);
101
-
102
- lar2 = writeRIFFOddSize(
103
- "lar2",
104
- art2,
105
- false,
106
- true
107
- );
108
- }
109
-
110
- return writeRIFFOddSize(
111
- "rgn2",
112
- combineArrays([
113
- rgnh,
114
- wsmp,
115
- wlnk,
116
- lar2
117
- ]),
118
- false,
119
- true
120
- );
121
- }
@@ -1,94 +0,0 @@
1
- import { combineArrays, IndexedByteArray } from "../../../utils/indexed_array.js";
2
- import { writeDword, writeWord } from "../../../utils/byte_functions/little_endian.js";
3
- import { writeRIFFOddSize } from "../riff_chunk.js";
4
- import { writeWavesample } from "./wsmp.js";
5
- import { getStringBytesZero } from "../../../utils/byte_functions/string.js";
6
- import { SpessaSynthInfo } from "../../../utils/loggin.js";
7
- import { consoleColors } from "../../../utils/other.js";
8
-
9
- /**
10
- * @param sample {BasicSample}
11
- * @returns {IndexedByteArray}
12
- */
13
- export function writeDLSSample(sample)
14
- {
15
- const fmtData = new IndexedByteArray(18);
16
- writeWord(fmtData, 1); // wFormatTag
17
- writeWord(fmtData, 1); // wChannels
18
- writeDword(fmtData, sample.sampleRate);
19
- writeDword(fmtData, sample.sampleRate * 2); // 16-bit samples
20
- writeWord(fmtData, 2); // wBlockAlign
21
- writeWord(fmtData, 16); // wBitsPerSample
22
- const fmt = writeRIFFOddSize(
23
- "fmt ",
24
- fmtData
25
- );
26
- let loop = 1;
27
- if (sample.sampleLoopStartIndex + Math.abs(sample.getAudioData().length - sample.sampleLoopEndIndex) < 2)
28
- {
29
- loop = 0;
30
- }
31
- const wsmp = writeWavesample(
32
- sample,
33
- sample.samplePitch,
34
- sample.samplePitchCorrection,
35
- 0,
36
- sample.sampleLoopStartIndex,
37
- sample.sampleLoopEndIndex,
38
- loop
39
- );
40
- const audio = sample.getAudioData();
41
- let data;
42
- // if sample is compressed, getRawData cannot be used
43
- if (sample.isCompressed)
44
- {
45
- const data16 = new Int16Array(audio.length);
46
-
47
- for (let i = 0; i < audio.length; i++)
48
- {
49
- // 32,767, as 32,768 may cause overflow (because vorbis can go above 1 sometimes)
50
- data16[i] = audio[i] * 32767;
51
- }
52
-
53
-
54
- data = writeRIFFOddSize(
55
- "data",
56
- new IndexedByteArray(data16.buffer)
57
- );
58
- }
59
- else
60
- {
61
- data = writeRIFFOddSize(
62
- "data",
63
- sample.getRawData()
64
- );
65
- }
66
-
67
- const inam = writeRIFFOddSize(
68
- "INAM",
69
- getStringBytesZero(sample.sampleName)
70
- );
71
- const info = writeRIFFOddSize(
72
- "INFO",
73
- inam,
74
- false,
75
- true
76
- );
77
- SpessaSynthInfo(
78
- `%cSaved %c${sample.sampleName}%c succesfully!`,
79
- consoleColors.recognized,
80
- consoleColors.value,
81
- consoleColors.recognized
82
- );
83
- return writeRIFFOddSize(
84
- "wave",
85
- combineArrays([
86
- fmt,
87
- wsmp,
88
- data,
89
- info
90
- ]),
91
- false,
92
- true
93
- );
94
- }
@@ -1,119 +0,0 @@
1
- import { writeRIFFOddSize } from "../riff_chunk.js";
2
- import { writeDword } from "../../../utils/byte_functions/little_endian.js";
3
- import { combineArrays, IndexedByteArray } from "../../../utils/indexed_array.js";
4
- import { writeLins } from "./lins.js";
5
- import { getStringBytesZero, writeStringAsBytes } from "../../../utils/byte_functions/string.js";
6
- import { writeWavePool } from "./wvpl.js";
7
- import { SpessaSynthGroupCollapsed, SpessaSynthGroupEnd, SpessaSynthInfo } from "../../../utils/loggin.js";
8
- import { consoleColors } from "../../../utils/other.js";
9
-
10
- /**
11
- * Write the soundfont as a .dls file. Experimental
12
- * @this {BasicSoundBank}
13
- * @returns {Uint8Array}
14
- */
15
- export function writeDLS()
16
- {
17
- SpessaSynthGroupCollapsed(
18
- "%cSaving DLS...",
19
- consoleColors.info
20
- );
21
- // write colh
22
- const colhNum = new IndexedByteArray(4);
23
- writeDword(colhNum, this.presets.length);
24
- const colh = writeRIFFOddSize(
25
- "colh",
26
- colhNum
27
- );
28
- SpessaSynthGroupCollapsed(
29
- "%cWriting instruments...",
30
- consoleColors.info
31
- );
32
- const lins = writeLins.apply(this);
33
- SpessaSynthInfo(
34
- "%cSuccess!",
35
- consoleColors.recognized
36
- );
37
- SpessaSynthGroupEnd();
38
-
39
- SpessaSynthGroupCollapsed(
40
- "%cWriting WAVE samples...",
41
- consoleColors.info
42
- );
43
- const wavepool = writeWavePool.apply(this);
44
- const wvpl = wavepool.data;
45
- const ptblOffsets = wavepool.indexes;
46
- SpessaSynthInfo("%cSucceeded!", consoleColors.recognized);
47
- SpessaSynthGroupEnd();
48
-
49
- // write ptbl
50
- const ptblData = new IndexedByteArray(8 + 4 * ptblOffsets.length);
51
- writeDword(ptblData, 8);
52
- writeDword(ptblData, ptblOffsets.length);
53
- for (const offset of ptblOffsets)
54
- {
55
- writeDword(ptblData, offset);
56
- }
57
- const ptbl = writeRIFFOddSize(
58
- "ptbl",
59
- ptblData
60
- );
61
-
62
- this.soundFontInfo["ICMT"] = (this.soundFontInfo["ICMT"] || "Soundfont") + "\nConverted from SF2 to DLS using SpessaSynth";
63
- this.soundFontInfo["ISFT"] = "SpessaSynth";
64
- // write INFO
65
- const infos = [];
66
- for (const [info, data] of Object.entries(this.soundFontInfo))
67
- {
68
- if (
69
- info !== "ICMT" &&
70
- info !== "INAM" &&
71
- info !== "ICRD" &&
72
- info !== "IENG" &&
73
- info !== "ICOP" &&
74
- info !== "ISFT" &&
75
- info !== "ISBJ"
76
- )
77
- {
78
- continue;
79
- }
80
- infos.push(
81
- writeRIFFOddSize(
82
- info,
83
- getStringBytesZero(data),
84
- true
85
- )
86
- );
87
- }
88
- const info = writeRIFFOddSize(
89
- "INFO",
90
- combineArrays(infos),
91
- false,
92
- true
93
- );
94
-
95
- const out = new IndexedByteArray(
96
- colh.length
97
- + lins.length
98
- + ptbl.length
99
- + wvpl.length
100
- + info.length
101
- + 4);
102
- writeStringAsBytes(out, "DLS ");
103
- out.set(combineArrays([
104
- colh,
105
- lins,
106
- ptbl,
107
- wvpl,
108
- info
109
- ]), 4);
110
- SpessaSynthInfo(
111
- "%cSaved succesfully!",
112
- consoleColors.recognized
113
- );
114
- SpessaSynthGroupEnd();
115
- return writeRIFFOddSize(
116
- "RIFF",
117
- out
118
- );
119
- }