spessasynth_lib 0.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 (154) hide show
  1. package/.idea/modules.xml +8 -0
  2. package/.idea/spessasynth_lib.iml +12 -0
  3. package/.idea/vcs.xml +6 -0
  4. package/copy_version.sh +38 -0
  5. package/index.js +73 -0
  6. package/package/@types/externals/stbvorbis_sync/stbvorbis_sync.min.d.ts +1 -0
  7. package/package/@types/index.d.ts +34 -0
  8. package/package/@types/midi_handler/midi_handler.d.ts +39 -0
  9. package/package/@types/midi_handler/web_midi_link.d.ts +12 -0
  10. package/package/@types/midi_parser/midi_data.d.ts +95 -0
  11. package/package/@types/midi_parser/midi_editor.d.ts +45 -0
  12. package/package/@types/midi_parser/midi_loader.d.ts +100 -0
  13. package/package/@types/midi_parser/midi_message.d.ts +154 -0
  14. package/package/@types/midi_parser/midi_writer.d.ts +6 -0
  15. package/package/@types/midi_parser/rmidi_writer.d.ts +9 -0
  16. package/package/@types/midi_parser/used_keys_loaded.d.ts +7 -0
  17. package/package/@types/sequencer/sequencer.d.ts +180 -0
  18. package/package/@types/sequencer/worklet_sequencer/sequencer_message.d.ts +28 -0
  19. package/package/@types/soundfont/read/generators.d.ts +98 -0
  20. package/package/@types/soundfont/read/instruments.d.ts +50 -0
  21. package/package/@types/soundfont/read/modulators.d.ts +73 -0
  22. package/package/@types/soundfont/read/presets.d.ts +87 -0
  23. package/package/@types/soundfont/read/riff_chunk.d.ts +31 -0
  24. package/package/@types/soundfont/read/samples.d.ts +134 -0
  25. package/package/@types/soundfont/read/zones.d.ts +141 -0
  26. package/package/@types/soundfont/soundfont.d.ts +76 -0
  27. package/package/@types/soundfont/write/ibag.d.ts +6 -0
  28. package/package/@types/soundfont/write/igen.d.ts +6 -0
  29. package/package/@types/soundfont/write/imod.d.ts +6 -0
  30. package/package/@types/soundfont/write/inst.d.ts +6 -0
  31. package/package/@types/soundfont/write/pbag.d.ts +6 -0
  32. package/package/@types/soundfont/write/pgen.d.ts +6 -0
  33. package/package/@types/soundfont/write/phdr.d.ts +6 -0
  34. package/package/@types/soundfont/write/pmod.d.ts +6 -0
  35. package/package/@types/soundfont/write/sdta.d.ts +11 -0
  36. package/package/@types/soundfont/write/shdr.d.ts +8 -0
  37. package/package/@types/soundfont/write/soundfont_trimmer.d.ts +6 -0
  38. package/package/@types/soundfont/write/write.d.ts +21 -0
  39. package/package/@types/synthetizer/audio_effects/effects_config.d.ts +29 -0
  40. package/package/@types/synthetizer/audio_effects/fancy_chorus.d.ts +93 -0
  41. package/package/@types/synthetizer/audio_effects/reverb.d.ts +7 -0
  42. package/package/@types/synthetizer/synth_event_handler.d.ts +161 -0
  43. package/package/@types/synthetizer/synthetizer.d.ts +294 -0
  44. package/package/@types/synthetizer/worklet_system/message_protocol/worklet_message.d.ts +89 -0
  45. package/package/@types/synthetizer/worklet_system/worklet_utilities/worklet_processor_channel.d.ts +134 -0
  46. package/package/@types/synthetizer/worklet_url.d.ts +5 -0
  47. package/package/@types/utils/buffer_to_wav.d.ts +8 -0
  48. package/package/@types/utils/byte_functions/big_endian.d.ts +13 -0
  49. package/package/@types/utils/byte_functions/little_endian.d.ts +35 -0
  50. package/package/@types/utils/byte_functions/string.d.ts +22 -0
  51. package/package/@types/utils/byte_functions/variable_length_quantity.d.ts +12 -0
  52. package/package/@types/utils/indexed_array.d.ts +21 -0
  53. package/package/@types/utils/loggin.d.ts +26 -0
  54. package/package/@types/utils/other.d.ts +32 -0
  55. package/package/LICENSE +26 -0
  56. package/package/README.md +84 -0
  57. package/package/externals/NOTICE +9 -0
  58. package/package/externals/libvorbis/@types/OggVorbisEncoder.d.ts +34 -0
  59. package/package/externals/libvorbis/OggVorbisEncoder.min.js +1 -0
  60. package/package/externals/stbvorbis_sync/@types/stbvorbis_sync.d.ts +12 -0
  61. package/package/externals/stbvorbis_sync/LICENSE +202 -0
  62. package/package/externals/stbvorbis_sync/stbvorbis_sync.min.js +1 -0
  63. package/package/index.js +73 -0
  64. package/package/midi_handler/README.md +3 -0
  65. package/package/midi_handler/midi_handler.js +118 -0
  66. package/package/midi_handler/web_midi_link.js +41 -0
  67. package/package/midi_parser/README.md +3 -0
  68. package/package/midi_parser/midi_data.js +121 -0
  69. package/package/midi_parser/midi_editor.js +557 -0
  70. package/package/midi_parser/midi_loader.js +502 -0
  71. package/package/midi_parser/midi_message.js +234 -0
  72. package/package/midi_parser/midi_writer.js +95 -0
  73. package/package/midi_parser/rmidi_writer.js +271 -0
  74. package/package/midi_parser/used_keys_loaded.js +172 -0
  75. package/package/package.json +43 -0
  76. package/package/sequencer/README.md +23 -0
  77. package/package/sequencer/sequencer.js +439 -0
  78. package/package/sequencer/worklet_sequencer/events.js +92 -0
  79. package/package/sequencer/worklet_sequencer/play.js +309 -0
  80. package/package/sequencer/worklet_sequencer/process_event.js +167 -0
  81. package/package/sequencer/worklet_sequencer/process_tick.js +85 -0
  82. package/package/sequencer/worklet_sequencer/sequencer_message.js +39 -0
  83. package/package/sequencer/worklet_sequencer/song_control.js +193 -0
  84. package/package/sequencer/worklet_sequencer/worklet_sequencer.js +218 -0
  85. package/package/soundfont/README.md +8 -0
  86. package/package/soundfont/read/generators.js +212 -0
  87. package/package/soundfont/read/instruments.js +125 -0
  88. package/package/soundfont/read/modulators.js +249 -0
  89. package/package/soundfont/read/presets.js +300 -0
  90. package/package/soundfont/read/riff_chunk.js +81 -0
  91. package/package/soundfont/read/samples.js +398 -0
  92. package/package/soundfont/read/zones.js +310 -0
  93. package/package/soundfont/soundfont.js +357 -0
  94. package/package/soundfont/write/ibag.js +39 -0
  95. package/package/soundfont/write/igen.js +75 -0
  96. package/package/soundfont/write/imod.js +46 -0
  97. package/package/soundfont/write/inst.js +34 -0
  98. package/package/soundfont/write/pbag.js +39 -0
  99. package/package/soundfont/write/pgen.js +77 -0
  100. package/package/soundfont/write/phdr.js +42 -0
  101. package/package/soundfont/write/pmod.js +46 -0
  102. package/package/soundfont/write/sdta.js +72 -0
  103. package/package/soundfont/write/shdr.js +54 -0
  104. package/package/soundfont/write/soundfont_trimmer.js +169 -0
  105. package/package/soundfont/write/write.js +180 -0
  106. package/package/synthetizer/README.md +6 -0
  107. package/package/synthetizer/audio_effects/effects_config.js +21 -0
  108. package/package/synthetizer/audio_effects/fancy_chorus.js +120 -0
  109. package/package/synthetizer/audio_effects/impulse_response_2.flac +0 -0
  110. package/package/synthetizer/audio_effects/reverb.js +24 -0
  111. package/package/synthetizer/synth_event_handler.js +156 -0
  112. package/package/synthetizer/synthetizer.js +766 -0
  113. package/package/synthetizer/worklet_processor.min.js +13 -0
  114. package/package/synthetizer/worklet_system/README.md +6 -0
  115. package/package/synthetizer/worklet_system/main_processor.js +363 -0
  116. package/package/synthetizer/worklet_system/message_protocol/handle_message.js +197 -0
  117. package/package/synthetizer/worklet_system/message_protocol/message_sending.js +74 -0
  118. package/package/synthetizer/worklet_system/message_protocol/worklet_message.js +121 -0
  119. package/package/synthetizer/worklet_system/minify_processor.sh +4 -0
  120. package/package/synthetizer/worklet_system/worklet_methods/controller_control.js +230 -0
  121. package/package/synthetizer/worklet_system/worklet_methods/data_entry.js +277 -0
  122. package/package/synthetizer/worklet_system/worklet_methods/note_off.js +109 -0
  123. package/package/synthetizer/worklet_system/worklet_methods/note_on.js +91 -0
  124. package/package/synthetizer/worklet_system/worklet_methods/program_control.js +183 -0
  125. package/package/synthetizer/worklet_system/worklet_methods/reset_controllers.js +177 -0
  126. package/package/synthetizer/worklet_system/worklet_methods/snapshot.js +129 -0
  127. package/package/synthetizer/worklet_system/worklet_methods/system_exclusive.js +272 -0
  128. package/package/synthetizer/worklet_system/worklet_methods/tuning_control.js +195 -0
  129. package/package/synthetizer/worklet_system/worklet_methods/vibrato_control.js +29 -0
  130. package/package/synthetizer/worklet_system/worklet_methods/voice_control.js +233 -0
  131. package/package/synthetizer/worklet_system/worklet_processor.js +9 -0
  132. package/package/synthetizer/worklet_system/worklet_utilities/lfo.js +23 -0
  133. package/package/synthetizer/worklet_system/worklet_utilities/lowpass_filter.js +130 -0
  134. package/package/synthetizer/worklet_system/worklet_utilities/modulation_envelope.js +73 -0
  135. package/package/synthetizer/worklet_system/worklet_utilities/modulator_curves.js +86 -0
  136. package/package/synthetizer/worklet_system/worklet_utilities/stereo_panner.js +81 -0
  137. package/package/synthetizer/worklet_system/worklet_utilities/unit_converter.js +66 -0
  138. package/package/synthetizer/worklet_system/worklet_utilities/volume_envelope.js +265 -0
  139. package/package/synthetizer/worklet_system/worklet_utilities/wavetable_oscillator.js +83 -0
  140. package/package/synthetizer/worklet_system/worklet_utilities/worklet_modulator.js +234 -0
  141. package/package/synthetizer/worklet_system/worklet_utilities/worklet_processor_channel.js +116 -0
  142. package/package/synthetizer/worklet_system/worklet_utilities/worklet_voice.js +272 -0
  143. package/package/synthetizer/worklet_url.js +5 -0
  144. package/package/utils/README.md +4 -0
  145. package/package/utils/buffer_to_wav.js +101 -0
  146. package/package/utils/byte_functions/big_endian.js +28 -0
  147. package/package/utils/byte_functions/little_endian.js +74 -0
  148. package/package/utils/byte_functions/string.js +97 -0
  149. package/package/utils/byte_functions/variable_length_quantity.js +37 -0
  150. package/package/utils/encode_vorbis.js +30 -0
  151. package/package/utils/indexed_array.js +41 -0
  152. package/package/utils/loggin.js +79 -0
  153. package/package/utils/other.js +54 -0
  154. package/package.json +43 -0
@@ -0,0 +1,32 @@
1
+ /**
2
+ * other.js
3
+ * purpose: contains some useful functions that don't belong in any specific category
4
+ */
5
+ /**
6
+ * Formats the given seconds to nice readable time
7
+ * @param totalSeconds {number} time in seconds
8
+ * @return {{seconds: number, minutes: number, time: string}}
9
+ */
10
+ export function formatTime(totalSeconds: number): {
11
+ seconds: number;
12
+ minutes: number;
13
+ time: string;
14
+ };
15
+ /**
16
+ * @param fileName {string}
17
+ * @returns {string}
18
+ */
19
+ export function formatTitle(fileName: string): string;
20
+ /**
21
+ * Does what it says
22
+ * @param arr {number[]}
23
+ * @returns {string}
24
+ */
25
+ export function arrayToHexString(arr: number[]): string;
26
+ export namespace consoleColors {
27
+ let warn: string;
28
+ let unrecognized: string;
29
+ let info: string;
30
+ let recognized: string;
31
+ let value: string;
32
+ }
@@ -0,0 +1,26 @@
1
+ Main program is licensed under the MIT License:
2
+ MIT License
3
+
4
+ Copyright (c) 2024 Spessasus
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+
24
+ Apache 2.0 License
25
+ The following file(s) in this project are licensed under the Apache License 2.0:
26
+ - externals/stbvorbis_sync.js
@@ -0,0 +1,84 @@
1
+ # spessasynth_lib
2
+ **A powerful soundfont/MIDI JavaScript library for the browsers.**
3
+
4
+ ```shell
5
+ npm install --save spessasynth_lib
6
+ ```
7
+
8
+ ### [Project site (consider giving it a star!)](https://github.com/spessasus/SpessaSynth)
9
+ ### [Demo](https://spessasus.github.io/SpessaSynth)
10
+
11
+ ### [Complete documentation](https://github.com/spessasus/SpessaSynth/wiki/Usage-As-Library)
12
+
13
+ #### Basic example: play a single note
14
+ ```js
15
+ import {Synthetizer} from "spessasynth_lib"
16
+ const sfont = await (await fetch("soundfont.sf3")).arrayBuffer();
17
+ const ctx = new AudioContext();
18
+ // make sure you copied the worklet processor!
19
+ await ctx.audioWorklet.addModule("./worklet_processor.min.js");
20
+ const synth = new Synthetizer(ctx.destination, sfont);
21
+ document.getElementById("button").onclick = async () => {
22
+ await ctx.resume();
23
+ synth.programChange(0, 48); // strings ensemble
24
+ synth.noteOn(0, 52, 127);
25
+ }
26
+ ```
27
+
28
+ ## Current Features
29
+ ### Easy Integration
30
+ - **Modular design:** Easy integration into other projects (load what you need)
31
+ - **[Detailed documentation:](https://github.com/spessasus/SpessaSynth/wiki/Home)** With [examples!](https://github.com/spessasus/SpessaSynth/wiki/Usage-As-Library#examples)
32
+ - **Easy to Use:** basic setup is just [two lines of code!](https://github.com/spessasus/SpessaSynth/wiki/Usage-As-Library#minimal-setup)
33
+ - **No dependencies:** _batteries included!_
34
+
35
+ ### Powerful SoundFont Synthesizer
36
+ - Suitable for both **real-time** and **offline** synthesis
37
+ - **Excellent SoundFont support:**
38
+ - - **Generator Support**
39
+ - - **Modulator Support:** _First (to my knowledge) JavaScript SoundFont synth with that feature!_
40
+ - - **SoundFont3 Support:** Play compressed SoundFonts!
41
+ - - **Can load very large SoundFonts:** up to 4GB! _Note: Only Firefox handles this well; Chromium has a hard-coded memory limit_
42
+ - **Reverb and chorus support:** [customizable!](https://github.com/spessasus/SpessaSynth/wiki/Synthetizer-Class#effects-configuration-object)
43
+ - **Export audio files** using [OfflineAudioContext](https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext)
44
+ - **[Custom modulators for additional controllers](https://github.com/spessasus/SpessaSynth/wiki/Modulator-Class#default-modulators):** Why not?
45
+ - **Written using AudioWorklets:** runs in a separate thread for maximum performance, works perfectly in Firefox and Chrome!
46
+ - **Unlimited channel count:** Your CPU is the limit!
47
+ - **Various MIDI Standards Support:**
48
+ - - **MIDI Controller Support:** Default supported controllers [here](https://github.com/spessasus/SpessaSynth/wiki/MIDI-Implementation#supported-controllers)
49
+ - - [Full **RPN** and limited **NRPN** support](https://github.com/spessasus/SpessaSynth/wiki/MIDI-Implementation#supported-registered-parameters)
50
+ - - Supports some [**Roland GS** and **Yamaha XG** system exclusives](https://github.com/spessasus/SpessaSynth/wiki/MIDI-Implementation#supported-system-exclusives)
51
+ - **High-performance mode:** Play Rush E! _note: may kill your browser ;)_
52
+ - **Written in pure JavaScript using the WebAudio API:** Supported by all modern browsers!
53
+
54
+ ### Built-in Powerful and Fast Sequencer
55
+ - **Supports MIDI formats 0, 1, and 2:** _note: format 2 support is experimental as it's very, very rare_
56
+ - **[Multi-Port MIDI](https://github.com/spessasus/SpessaSynth/wiki/About-Multi-Port) support:** More than 16 channels!
57
+ - **Smart preloading:** Only preloads the samples used in the MIDI file for smooth playback (down to key and velocity!)
58
+ - **Lyrics support:** Add karaoke to your program!
59
+ - **Raw lyrics available:** Decode in any encoding! (Kanji? No problem!)
60
+
61
+ ### Read and Write SoundFont and MIDI Files with Ease
62
+ #### Read and write MIDI files
63
+ - **Smart name detection:** Handles incorrectly formatted and non-standard track names
64
+ - **Port detection during load time:** Manage ports and channels easily!
65
+ - **Used channels on track:** Quickly determine which channels are used
66
+ - **Key range detection:** Detect the key range of the MIDI
67
+ - **Easy MIDI editing:** Use [helper functions](https://github.com/spessasus/SpessaSynth/wiki/Writing-MIDI-Files#modifymidi) to modify the song to your needs!
68
+ - **Loop detection:** Automatically detects loops in MIDIs (e.g., from _Touhou Project_)
69
+ - **First note detection:** Skip unnecessary silence at the start by jumping to the first note!
70
+ - **Easy saving:** Save with just [one function!](https://github.com/spessasus/SpessaSynth/wiki/Writing-MIDI-Files#writemidifile)
71
+ #### Read and write [RMID files with embedded SF2 soundfonts](https://github.com/spessasus/SpessaSynth/wiki/About-RMIDI)
72
+ - **Compression and trimming support:** Reduce a MIDI file with a 1GB soundfont to **as small as 5MB**!
73
+ - **Easy saving:** [As simple as saving a MIDI file!](https://github.com/spessasus/SpessaSynth/wiki/Writing-MIDI-Files#writermidi)
74
+ #### Read and write SoundFont2 files
75
+ - **Smart trimming:** Trim the SoundFont to only include samples used in the MIDI (down to key and velocity!)
76
+ - **sf3 conversion:** Compress SoundFont2 files to SoundFont3!
77
+ - **Easy saving:** Also just [one function!](https://github.com/spessasus/SpessaSynth/wiki/SoundFont2-Class#write)
78
+ #### Read and write SoundFont3 files
79
+ - Same features as SoundFont2 but with now with **Ogg Vorbis compression!**
80
+ - **Variable compression quality:** You choose between file size and quality!
81
+ - **Compression preserving:** Avoid decompressing and recompressing uncompressed samples for minimal quality loss!
82
+
83
+ ## License
84
+ MIT License, except for the stbvorbis_sync.js in the `externals` folder which is licensed under the Apache-2.0 license.
@@ -0,0 +1,9 @@
1
+ LICENSE is for stbvorbis_sync.js which is licensed under Apache-2.0
2
+
3
+ Modifications made to stbvorbis_sync.js
4
+ 1. minified the code
5
+ 2. added types declaration
6
+
7
+ OggVorbisEncoder (https://github.com/higuma/ogg-vorbis-encoder-js)
8
+ is licensed under MIT.
9
+ The file provided is a slight modification to work with es6.
@@ -0,0 +1,34 @@
1
+ /**
2
+ * initializes libvorbis
3
+ * @returns {null}
4
+ */
5
+ export namespace libvorbis {
6
+
7
+ /**
8
+ * Represents an Ogg Vorbis encoder.
9
+ */
10
+ class OggVorbisEncoder {
11
+ /**
12
+ * Creates an instance of Encoder
13
+ * @param {number} sampleRate - The sample rate of the audio in Hz
14
+ * @param {number} channels - The number of audio channels (e.g., 1 for mono, 2 for stereo)
15
+ * @param {number} quality - The quality of the encoding, between -0.1 and 1
16
+ */
17
+ constructor(sampleRate: number, channels: number, quality: number);
18
+
19
+ /**
20
+ * Encodes audio data
21
+ * @param {Float32Array[]} audioData - An array of Float32Arrays, where each Float32Array represents a block of audio samples
22
+ * @returns {null}
23
+ */
24
+ encode(audioData: Float32Array[]): null;
25
+
26
+ /**
27
+ * Finishes the encoding process and retrieves the encoded data
28
+ * @returns {Uint8Array[]} An array of Uint8Arrays representing the encoded audio data
29
+ */
30
+ finish(): Uint8Array[];
31
+ }
32
+
33
+ function init(): null
34
+ }