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,89 +0,0 @@
1
- import { modulatorCurveTypes } from "../../../soundfont/basic_soundfont/modulator.js";
2
-
3
- /**
4
- * modulator_curves.js
5
- * precomputes modulator concave and conves curves and calculates a curve value for a given polarity, direction and type
6
- */
7
-
8
- // the length of the precomputed curve tables
9
- export const MOD_PRECOMPUTED_LENGTH = 16384;
10
-
11
- // Precalculate lookup tables for concave and convex curves
12
- const concave = new Float32Array(MOD_PRECOMPUTED_LENGTH + 1);
13
- const convex = new Float32Array(MOD_PRECOMPUTED_LENGTH + 1);
14
- // the equation is taken from FluidSynth as it's the standard for soundFonts
15
- // more precisely, the gen_conv.c file
16
- concave[0] = 0;
17
- concave[concave.length - 1] = 1;
18
-
19
- convex[0] = 0;
20
- convex[convex.length - 1] = 1;
21
- for (let i = 1; i < MOD_PRECOMPUTED_LENGTH - 1; i++)
22
- {
23
- let x = (-200 * 2 / 960) * Math.log(i / (concave.length - 1)) / Math.LN10;
24
- convex[i] = 1 - x;
25
- concave[concave.length - 1 - i] = x;
26
- }
27
-
28
- /**
29
- * Transforms a value with a given curve type
30
- * @param polarity {number} 0 or 1
31
- * @param direction {number} 0 or 1
32
- * @param curveType {number} see modulatorCurveTypes in modulators.js
33
- * @param value {number} the linear value, 0 to 1
34
- * @returns {number} the transformed value, 0 to 1, or -1 to 1
35
- */
36
- export function getModulatorCurveValue(direction, curveType, value, polarity)
37
- {
38
- // inverse the value if needed
39
- if (direction)
40
- {
41
- value = 1 - value;
42
- }
43
- switch (curveType)
44
- {
45
- case modulatorCurveTypes.linear:
46
- if (polarity)
47
- {
48
- // bipolar curve
49
- return value * 2 - 1;
50
- }
51
- return value;
52
-
53
- case modulatorCurveTypes.switch:
54
- // switch
55
- value = value > 0.5 ? 1 : 0;
56
- if (polarity)
57
- {
58
- // multiply
59
- return value * 2 - 1;
60
- }
61
- return value;
62
-
63
- case modulatorCurveTypes.concave:
64
- // look up the value
65
- if (polarity)
66
- {
67
- value = value * 2 - 1;
68
- if (value < 0)
69
- {
70
- return -concave[~~(value * -MOD_PRECOMPUTED_LENGTH)];
71
- }
72
- return concave[~~(value * MOD_PRECOMPUTED_LENGTH)];
73
- }
74
- return concave[~~(value * MOD_PRECOMPUTED_LENGTH)];
75
-
76
- case modulatorCurveTypes.convex:
77
- // look up the value
78
- if (polarity)
79
- {
80
- value = value * 2 - 1;
81
- if (value < 0)
82
- {
83
- return -convex[~~(value * -MOD_PRECOMPUTED_LENGTH)];
84
- }
85
- return convex[~~(value * MOD_PRECOMPUTED_LENGTH)];
86
- }
87
- return convex[~~(value * MOD_PRECOMPUTED_LENGTH)];
88
- }
89
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * @enum {number}
3
- */
4
- export const WorkletSoundfontManagerMessageType = {
5
- reloadSoundFont: 0, // buffer<ArrayBuffer>
6
- addNewSoundFont: 2, // [buffer<ArrayBuffer>, id<string>, bankOffset<number>]
7
- deleteSoundFont: 3, // id<string>
8
- rearrangeSoundFonts: 4 // newOrder<string[]> // where string is the id
9
- };
@@ -1,254 +0,0 @@
1
- import { SpessaSynthWarn } from "../../../../utils/loggin.js";
2
- import { WorkletSoundfontManagerMessageType } from "./sfman_message.js";
3
- import { loadSoundFont } from "../../../../soundfont/load_soundfont.js";
4
- import { isXGDrums } from "../../../../utils/xg_hacks.js";
5
-
6
- /**
7
- * @typedef {Object} SoundFontType
8
- * @property {string} id - unique id for the soundfont
9
- * @property {BasicSoundBank} soundfont - the soundfont itself
10
- * @property {number} bankOffset - the soundfont's bank offset
11
- */
12
-
13
- export class WorkletSoundfontManager
14
- {
15
- /**
16
- * Creates a new instance of worklet soundfont manager (worklet scope)
17
- * @param initialSoundFontBuffer {ArrayBuffer} Array buffer of the soundfont. This soudfont always has the id "main"
18
- * @param readyCallback {function} postReady() method from synth
19
- */
20
- constructor(initialSoundFontBuffer, readyCallback)
21
- {
22
- /**
23
- * @type {Function}
24
- */
25
- this.ready = readyCallback;
26
- this.reloadManager(initialSoundFontBuffer);
27
- }
28
-
29
- generatePresetList()
30
- {
31
- /**
32
- * <"bank-program", "presetName">
33
- * @type {Object<string, string>}
34
- */
35
- const presetList = {};
36
- // gather the presets in reverse and replace if necessary
37
- for (let i = this.soundfontList.length - 1; i >= 0; i--)
38
- {
39
- const font = this.soundfontList[i];
40
- /**
41
- * prevent preset names from the same soudfont from being overriden
42
- * if the soundfont has two presets with matching bank and program
43
- * @type {Set<string>}
44
- */
45
- const presets = new Set();
46
- for (const p of font.soundfont.presets)
47
- {
48
- const presetString = `${p.bank + font.bankOffset}-${p.program}`;
49
- if (presets.has(presetString))
50
- {
51
- continue;
52
- }
53
- presets.add(presetString);
54
- presetList[presetString] = p.presetName;
55
- }
56
- }
57
-
58
- /**
59
- * @type {{bank: number, presetName: string, program: number}[]}
60
- */
61
- this.presetList = [];
62
- for (const [string, name] of Object.entries(presetList))
63
- {
64
- const pb = string.split("-");
65
- this.presetList.push({
66
- presetName: name,
67
- program: parseInt(pb[1]),
68
- bank: parseInt(pb[0])
69
- });
70
- }
71
- }
72
-
73
- /**
74
- * @param type {WorkletSoundfontManagerMessageType}
75
- * @param data {any}
76
- */
77
- handleMessage(type, data)
78
- {
79
- switch (type)
80
- {
81
- case WorkletSoundfontManagerMessageType.addNewSoundFont:
82
- this.addNewSoundFont(data[0], data[1], data[2]);
83
- break;
84
-
85
- case WorkletSoundfontManagerMessageType.reloadSoundFont:
86
- this.reloadManager(data);
87
- break;
88
-
89
- case WorkletSoundfontManagerMessageType.deleteSoundFont:
90
- this.deleteSoundFont(data);
91
- break;
92
-
93
- case WorkletSoundfontManagerMessageType.rearrangeSoundFonts:
94
- this.rearrangeSoundFonts(data);
95
- }
96
- }
97
-
98
- /**
99
- * Get the final preset list
100
- * @returns {{bank: number, presetName: string, program: number}[]}
101
- */
102
- getPresetList()
103
- {
104
- return this.presetList.slice();
105
- }
106
-
107
- /**
108
- * Clears all soundfonts and adds a new one
109
- * @param soundFontArrayBuffer {ArrayBuffer}
110
- */
111
- reloadManager(soundFontArrayBuffer)
112
- {
113
- const font = loadSoundFont(soundFontArrayBuffer);
114
- /**
115
- * All the soundfonts, ordered from the most important to the least.
116
- * @type {SoundFontType[]}
117
- */
118
- this.soundfontList = [];
119
- this.soundfontList.push({
120
- id: "main",
121
- bankOffset: 0,
122
- soundfont: font
123
- });
124
- this.generatePresetList();
125
- this.ready();
126
- }
127
-
128
- deleteSoundFont(id)
129
- {
130
- if (this.soundfontList.length === 0)
131
- {
132
- SpessaSynthWarn("1 soundfont left. Aborting!");
133
- return;
134
- }
135
- const index = this.soundfontList.findIndex(s => s.id === id);
136
- if (index === -1)
137
- {
138
- SpessaSynthWarn(`No soundfont with id of "${id}" found. Aborting!`);
139
- return;
140
- }
141
- delete this.soundfontList[index].soundfont.presets;
142
- delete this.soundfontList[index].soundfont.instruments;
143
- delete this.soundfontList[index].soundfont.samples;
144
- this.soundfontList.splice(index, 1);
145
- this.generatePresetList();
146
- }
147
-
148
- /**
149
- * Adds a new soundfont buffer with a given ID
150
- * @param buffer {ArrayBuffer}
151
- * @param id {string}
152
- * @param bankOffset {number}
153
- */
154
- addNewSoundFont(buffer, id, bankOffset)
155
- {
156
- if (this.soundfontList.find(s => s.id === id) !== undefined)
157
- {
158
- throw new Error("Cannot overwrite the existing soundfont. Use soundfontManager.delete(id) instead.");
159
- }
160
- this.soundfontList.push({
161
- id: id,
162
- soundfont: loadSoundFont(buffer),
163
- bankOffset: bankOffset
164
- });
165
- this.generatePresetList();
166
- this.ready();
167
- }
168
-
169
- /**
170
- * Rearranges the soundfonts
171
- * @param newList {string[]} the order of soundfonts, a list of strings, first overwrites second
172
- */
173
- rearrangeSoundFonts(newList)
174
- {
175
- this.soundfontList.sort((a, b) =>
176
- newList.indexOf(a.id) - newList.indexOf(b.id)
177
- );
178
- this.generatePresetList();
179
- }
180
-
181
- /**
182
- * Gets a given preset from the soundfont stack
183
- * @param bankNumber {number}
184
- * @param programNumber {number}
185
- * @param allowXGDrums {boolean} if true, allows XG drum banks (120, 126 and 127) as drum preset
186
- * @returns {BasicPreset} the preset
187
- */
188
- getPreset(bankNumber, programNumber, allowXGDrums = false)
189
- {
190
- if (this.soundfontList.length < 1)
191
- {
192
- throw new Error("No soundfonts! This should never happen.");
193
- }
194
- for (const sf of this.soundfontList)
195
- {
196
- // check for the preset (with given offset)
197
- const preset = sf.soundfont.getPresetNoFallback(
198
- bankNumber - sf.bankOffset,
199
- programNumber,
200
- allowXGDrums
201
- );
202
- if (preset !== undefined)
203
- {
204
- return preset;
205
- }
206
- // if not found, advance to the next soundfont
207
- }
208
- const isDrum = bankNumber === 128 || (allowXGDrums && isXGDrums(bankNumber));
209
- // if none found, return the first correct preset found
210
- if (!isDrum)
211
- {
212
- for (const sf of this.soundfontList)
213
- {
214
- const preset = sf.soundfont.presets.find(p => p.program === programNumber && !p.isDrumPreset(
215
- allowXGDrums));
216
- if (preset)
217
- {
218
- return preset;
219
- }
220
- }
221
- // if nothing at all, use the first preset
222
- return this.soundfontList[0].soundfont.presets[0];
223
- }
224
- else
225
- {
226
- for (const sf of this.soundfontList)
227
- {
228
- // check for any drum type (127/128) and matching program
229
- const p = sf.soundfont.presets.find(p => p.isDrumPreset(allowXGDrums) && p.program === programNumber);
230
- if (p)
231
- {
232
- return p;
233
- }
234
- // check for any drum preset
235
- const preset = sf.soundfont.presets.find(p => p.isDrumPreset(allowXGDrums));
236
- if (preset)
237
- {
238
- return preset;
239
- }
240
- }
241
- // if nothing at all, use the first preset
242
- return this.soundfontList[0].soundfont.presets[0];
243
- }
244
- }
245
-
246
- destroyManager()
247
- {
248
- this.soundfontList.forEach(s =>
249
- {
250
- s.soundfont.destroySoundBank();
251
- });
252
- delete this.soundfontList;
253
- }
254
- }
@@ -1,120 +0,0 @@
1
- import { generatorTypes } from "../../../soundfont/basic_soundfont/generator.js";
2
-
3
- /**
4
- * stereo_panner.js
5
- * purpose: pans a given voice out to the stereo output and to the effects' outputs
6
- */
7
-
8
- export const PAN_SMOOTHING_FACTOR = 0.05;
9
-
10
- export const WORKLET_SYSTEM_REVERB_DIVIDER = 4600;
11
- export const WORKLET_SYSTEM_CHORUS_DIVIDER = 2000;
12
- const HALF_PI = Math.PI / 2;
13
-
14
- const MIN_PAN = -500;
15
- const MAX_PAN = 500;
16
- const PAN_RESOLUTION = MAX_PAN - MIN_PAN;
17
-
18
- // initialize pan lookup tables
19
- const panTableLeft = new Float32Array(PAN_RESOLUTION + 1);
20
- const panTableRight = new Float32Array(PAN_RESOLUTION + 1);
21
- for (let pan = MIN_PAN; pan <= MAX_PAN; pan++)
22
- {
23
- // clamp to 0-1
24
- const realPan = (pan - MIN_PAN) / PAN_RESOLUTION;
25
- const tableIndex = pan - MIN_PAN;
26
- panTableLeft[tableIndex] = Math.cos(HALF_PI * realPan);
27
- panTableRight[tableIndex] = Math.sin(HALF_PI * realPan);
28
- }
29
-
30
- /**
31
- * Pans the voice to the given output buffers
32
- * @param voice {Voice} the voice to pan
33
- * @param inputBuffer {Float32Array} the input buffer in mono
34
- * @param outputLeft {Float32Array} left output buffer
35
- * @param outputRight {Float32Array} right output buffer
36
- * @param reverbLeft {Float32Array} left reverb input
37
- * @param reverbRight {Float32Array} right reverb input
38
- * @param chorusLeft {Float32Array} left chorus buffer
39
- * @param chorusRight {Float32Array} right chorus buffer
40
- * @this {MidiAudioChannel}
41
- */
42
- export function panVoice(voice,
43
- inputBuffer,
44
- outputLeft, outputRight,
45
- reverbLeft, reverbRight,
46
- chorusLeft, chorusRight)
47
- {
48
- if (isNaN(inputBuffer[0]))
49
- {
50
- return;
51
- }
52
- /**
53
- * clamp -500 to 500
54
- * @type {number}
55
- */
56
- let pan;
57
- if (voice.overridePan)
58
- {
59
- pan = voice.overridePan;
60
- }
61
- else
62
- {
63
- // smooth out pan to prevent clicking
64
- voice.currentPan += (voice.modulatedGenerators[generatorTypes.pan] - voice.currentPan) * this.synth.panSmoothingFactor;
65
- pan = voice.currentPan;
66
- }
67
-
68
- const gain = this.synth.currentGain * voice.gain;
69
- const index = ~~(pan + 500);
70
- // get voice's gain levels for each channel
71
- const gainLeft = panTableLeft[index] * gain * this.synth.panLeft;
72
- const gainRight = panTableRight[index] * gain * this.synth.panRight;
73
-
74
- // disable reverb and chorus if necessary
75
- if (this.synth.effectsEnabled)
76
- {
77
- const reverbSend = voice.modulatedGenerators[generatorTypes.reverbEffectsSend];
78
- if (reverbSend > 0)
79
- {
80
- // reverb is mono so we need to multiply by gain
81
- const reverbGain = this.synth.reverbGain * gain * (reverbSend / WORKLET_SYSTEM_REVERB_DIVIDER);
82
- for (let i = 0; i < inputBuffer.length; i++)
83
- {
84
- reverbLeft[i] += reverbGain * inputBuffer[i];
85
- }
86
- // copy as its mono
87
- reverbRight.set(reverbLeft);
88
- }
89
-
90
- const chorusSend = voice.modulatedGenerators[generatorTypes.chorusEffectsSend];
91
- if (chorusSend > 0)
92
- {
93
- // chorus is stereo so we do not need to
94
- const chorusGain = this.synth.chorusGain * chorusSend / WORKLET_SYSTEM_CHORUS_DIVIDER;
95
- const chorusLeftGain = gainLeft * chorusGain;
96
- const chorusRightGain = gainRight * chorusGain;
97
- for (let i = 0; i < inputBuffer.length; i++)
98
- {
99
- chorusLeft[i] += chorusLeftGain * inputBuffer[i];
100
- chorusRight[i] += chorusRightGain * inputBuffer[i];
101
- }
102
- }
103
- }
104
-
105
- // mix down the audio data
106
- if (gainLeft > 0)
107
- {
108
- for (let i = 0; i < inputBuffer.length; i++)
109
- {
110
- outputLeft[i] += gainLeft * inputBuffer[i];
111
- }
112
- }
113
- if (gainRight > 0)
114
- {
115
- for (let i = 0; i < inputBuffer.length; i++)
116
- {
117
- outputRight[i] += gainRight * inputBuffer[i];
118
- }
119
- }
120
- }
@@ -1,73 +0,0 @@
1
- /**
2
- * unit_converter.js
3
- * purpose: converts soundfont units into more useable values with the use of lookup tables to improve performance
4
- */
5
-
6
-
7
- // timecent lookup table
8
- const MIN_TIMECENT = -15000;
9
- const MAX_TIMECENT = 15000;
10
- const timecentLookupTable = new Float32Array(MAX_TIMECENT - MIN_TIMECENT + 1);
11
- for (let i = 0; i < timecentLookupTable.length; i++)
12
- {
13
- const timecents = MIN_TIMECENT + i;
14
- timecentLookupTable[i] = Math.pow(2, timecents / 1200);
15
- }
16
-
17
- /**
18
- * Converts timecents to seconds
19
- * @param timecents {number} timecents
20
- * @returns {number} seconds
21
- */
22
- export function timecentsToSeconds(timecents)
23
- {
24
- if (timecents <= -32767)
25
- {
26
- return 0;
27
- }
28
- return timecentLookupTable[timecents - MIN_TIMECENT];
29
- }
30
-
31
- // abs cent lookup table
32
- const MIN_ABS_CENT = -20000; // freqVibLfo
33
- const MAX_ABS_CENT = 16500; // filterFc
34
- const absoluteCentLookupTable = new Float32Array(MAX_ABS_CENT - MIN_ABS_CENT + 1);
35
- for (let i = 0; i < absoluteCentLookupTable.length; i++)
36
- {
37
- const absoluteCents = MIN_ABS_CENT + i;
38
- absoluteCentLookupTable[i] = 440 * Math.pow(2, (absoluteCents - 6900) / 1200);
39
- }
40
-
41
- /**
42
- * Converts absolute cents to hertz
43
- * @param cents {number} absolute cents
44
- * @returns {number} hertz
45
- */
46
- export function absCentsToHz(cents)
47
- {
48
- if (cents < MIN_ABS_CENT || cents > MAX_ABS_CENT)
49
- {
50
- return 440 * Math.pow(2, (cents - 6900) / 1200);
51
- }
52
- return absoluteCentLookupTable[~~(cents) - MIN_ABS_CENT];
53
- }
54
-
55
- // decibel lookup table (2 points of precision)
56
- const MIN_DECIBELS = -1660;
57
- const MAX_DECIBELS = 1600;
58
- const decibelLookUpTable = new Float32Array((MAX_DECIBELS - MIN_DECIBELS) * 100 + 1);
59
- for (let i = 0; i < decibelLookUpTable.length; i++)
60
- {
61
- const decibels = (MIN_DECIBELS * 100 + i) / 100;
62
- decibelLookUpTable[i] = Math.pow(10, -decibels / 20);
63
- }
64
-
65
- /**
66
- * convers decibel attenuation to gain
67
- * @param decibels {number} the decibel attenuation
68
- * @returns {number} gain
69
- */
70
- export function decibelAttenuationToGain(decibels)
71
- {
72
- return decibelLookUpTable[Math.floor((decibels - MIN_DECIBELS) * 100)];
73
- }