spessasynth_core 1.0.4 → 1.0.6

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 (56) hide show
  1. package/.idea/inspectionProfiles/Project_Default.xml +0 -0
  2. package/.idea/jsLibraryMappings.xml +0 -0
  3. package/.idea/modules.xml +0 -0
  4. package/.idea/spessasynth_core.iml +0 -0
  5. package/.idea/vcs.xml +0 -0
  6. package/LICENSE +0 -0
  7. package/README.md +15 -1
  8. package/index.js +2 -1
  9. package/package.json +2 -2
  10. package/spessasynth_core/midi_parser/README.md +0 -0
  11. package/spessasynth_core/midi_parser/midi_loader.js +0 -0
  12. package/spessasynth_core/midi_parser/midi_message.js +0 -0
  13. package/spessasynth_core/sequencer/sequencer.js +0 -0
  14. package/spessasynth_core/sequencer/worklet_sequencer/play.js +0 -0
  15. package/spessasynth_core/sequencer/worklet_sequencer/process_event.js +0 -0
  16. package/spessasynth_core/sequencer/worklet_sequencer/process_tick.js +0 -0
  17. package/spessasynth_core/sequencer/worklet_sequencer/song_control.js +0 -0
  18. package/spessasynth_core/soundfont/README.md +0 -0
  19. package/spessasynth_core/soundfont/chunk/generators.js +0 -0
  20. package/spessasynth_core/soundfont/chunk/instruments.js +0 -0
  21. package/spessasynth_core/soundfont/chunk/modulators.js +0 -0
  22. package/spessasynth_core/soundfont/chunk/presets.js +0 -0
  23. package/spessasynth_core/soundfont/chunk/riff_chunk.js +0 -0
  24. package/spessasynth_core/soundfont/chunk/samples.js +0 -0
  25. package/spessasynth_core/soundfont/chunk/zones.js +0 -0
  26. package/spessasynth_core/soundfont/soundfont_parser.js +0 -0
  27. package/spessasynth_core/synthetizer/README.md +0 -0
  28. package/spessasynth_core/synthetizer/synthesizer.js +0 -0
  29. package/spessasynth_core/synthetizer/worklet_system/README.md +0 -0
  30. package/spessasynth_core/synthetizer/worklet_system/worklet_methods/controller_control.js +0 -0
  31. package/spessasynth_core/synthetizer/worklet_system/worklet_methods/data_entry.js +0 -0
  32. package/spessasynth_core/synthetizer/worklet_system/worklet_methods/note_off.js +0 -0
  33. package/spessasynth_core/synthetizer/worklet_system/worklet_methods/note_on.js +2 -2
  34. package/spessasynth_core/synthetizer/worklet_system/worklet_methods/program_control.js +0 -0
  35. package/spessasynth_core/synthetizer/worklet_system/worklet_methods/system_exclusive.js +0 -0
  36. package/spessasynth_core/synthetizer/worklet_system/worklet_methods/tuning_control.js +0 -0
  37. package/spessasynth_core/synthetizer/worklet_system/worklet_methods/vibrato_control.js +0 -0
  38. package/spessasynth_core/synthetizer/worklet_system/worklet_methods/voice_control.js +51 -15
  39. package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/lfo.js +0 -0
  40. package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/lowpass_filter.js +0 -0
  41. package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/modulation_envelope.js +0 -0
  42. package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/modulator_curves.js +0 -0
  43. package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/stereo_panner.js +0 -0
  44. package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/unit_converter.js +0 -0
  45. package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/volume_envelope.js +0 -0
  46. package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/wavetable_oscillator.js +0 -0
  47. package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/worklet_modulator.js +0 -0
  48. package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/worklet_processor_channel.js +0 -0
  49. package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/worklet_voice.js +0 -0
  50. package/spessasynth_core/utils/README.md +0 -0
  51. package/spessasynth_core/utils/buffer_to_wav.js +0 -0
  52. package/spessasynth_core/utils/byte_functions.js +0 -0
  53. package/spessasynth_core/utils/loggin.js +0 -0
  54. package/spessasynth_core/utils/other.js +0 -0
  55. package/spessasynth_core/utils/shiftable_array.js +0 -0
  56. package/spessasynth_core/utils/stbvorbis_sync.js +0 -0
File without changes
File without changes
package/.idea/modules.xml CHANGED
File without changes
File without changes
package/.idea/vcs.xml CHANGED
File without changes
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -59,6 +59,7 @@ import("spessasynth_core").then(core => {
59
59
  - [Sequencer](#sequencer)
60
60
  - [MIDI](#midi)
61
61
  - [SoundFont2](#soundfont2)
62
+ - [How to disable console output](#logging)
62
63
 
63
64
  ### Importing the library
64
65
  spessasynth_core is an es6 package.
@@ -373,4 +374,17 @@ console.log(`The track lasts for ${sequencer.duration} seconds!`);
373
374
  See [MIDI on SpessaSynth wiki](https://github.com/spessasus/SpessaSynth/wiki/MIDI-Class)
374
375
 
375
376
  ## SoundFont2
376
- See [SoundFont2 on SpessaSynth wiki](https://github.com/spessasus/SpessaSynth/wiki/SoundFont2-Class)
377
+ See [SoundFont2 on SpessaSynth wiki](https://github.com/spessasus/SpessaSynth/wiki/SoundFont2-Class)
378
+
379
+ ## Logging
380
+ By default, SpessaSynth prints out a lot of stuff to console.
381
+ Here's how you can disable it:
382
+ ```js
383
+ // import (or require) here
384
+ SpessaSynthLogging(enableInfo, enableWarning, enableGroup, enableTable);
385
+ ```
386
+ All the input variables are booleans corresponding to the things SpessaSynth logs.
387
+ - Info - all general info such as parsing soundfonts, midi files, RPN changes, etc.
388
+ - Warnings - all messages unrecognized by the synthesizer, other warnings
389
+ - group - the groups for parsing the soundfont and midi files.
390
+ - table - the debug table `when enableDebugging` is set to `true` for `synth.noteOn`
package/index.js CHANGED
@@ -3,5 +3,6 @@ import {Sequencer} from "./spessasynth_core/sequencer/sequencer.js";
3
3
  import {MIDI} from "./spessasynth_core/midi_parser/midi_loader.js";
4
4
  import {rawDataToWav} from "./spessasynth_core/utils/buffer_to_wav.js";
5
5
  import {SoundFont2} from "./spessasynth_core/soundfont/soundfont_parser.js";
6
+ import {SpessaSynthLogging} from "./spessasynth_core/utils/loggin.js";
6
7
 
7
- export { Synthesizer, Sequencer, MIDI, SoundFont2, rawDataToWav };
8
+ export { Synthesizer, Sequencer, MIDI, SoundFont2, rawDataToWav, SpessaSynthLogging };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spessasynth_core",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "SoundFont2 synthesizer library for node.js",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/spessasus/spessasynth_core.git"
12
+ "url": "git+https://github.com/spessasus/spessasynth_core.git"
13
13
  },
14
14
  "keywords": [
15
15
  "sf2",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -64,12 +64,12 @@ export function noteOn(channel, midiNote, velocity, enableDebugging = false)
64
64
  computeModulators(voice, this.workletProcessorChannels[channel].midiControllers);
65
65
  voice.currentAttenuationDb = 100;
66
66
  })
67
- channelVoices.push(...voices);
68
67
 
69
68
  this.totalVoicesAmount += voices.length;
70
69
  // cap the voices
71
70
  if(this.totalVoicesAmount > VOICE_CAP)
72
71
  {
73
- this.voiceKilling(this.totalVoicesAmount - VOICE_CAP);
72
+ this.voiceKilling(voices.length);
74
73
  }
74
+ channelVoices.push(...voices);
75
75
  }
@@ -143,6 +143,35 @@ export function renderVoice(channel, voice, output, reverbOutput, chorusOutput)
143
143
  chorusOutput, voice.modulatedGenerators[generatorTypes.chorusEffectsSend]);
144
144
  }
145
145
 
146
+ /**
147
+ * @param channel {WorkletProcessorChannel}
148
+ * @param voice {WorkletVoice}
149
+ * @return {number}
150
+ */
151
+ function getPriority(channel, voice)
152
+ {
153
+ let priority = 0;
154
+ if(channel.drumChannel)
155
+ {
156
+ // important
157
+ priority += 5;
158
+ }
159
+ if(voice.isInRelease)
160
+ {
161
+ // not important
162
+ priority -= 5;
163
+ }
164
+ // less velocity = less important
165
+ priority += voice.velocity / 25; // map to 0-5
166
+ // the newer, more important
167
+ priority -= voice.volumeEnvelopeState;
168
+ if(voice.isInRelease)
169
+ {
170
+ priority -= 5;
171
+ }
172
+ priority -= voice.currentAttenuationDb / 50;
173
+ return priority;
174
+ }
146
175
 
147
176
  /**
148
177
  * @this {Synthesizer}
@@ -150,23 +179,30 @@ export function renderVoice(channel, voice, output, reverbOutput, chorusOutput)
150
179
  */
151
180
  export function voiceKilling(amount)
152
181
  {
153
- // kill the smallest velocity voices
154
- let voicesOrderedByVelocity = this.workletProcessorChannels.map(channel => channel.voices);
155
-
156
- /**
157
- * @type {WorkletVoice[]}
158
- */
159
- voicesOrderedByVelocity = voicesOrderedByVelocity.flat();
160
- voicesOrderedByVelocity.sort((v1, v2) => v1.velocity - v2.velocity);
161
- if(voicesOrderedByVelocity.length < amount)
182
+ let allVoices = [];
183
+ for (const channel of this.workletProcessorChannels)
162
184
  {
163
- amount = voicesOrderedByVelocity.length;
185
+ for (const voice of channel.voices)
186
+ {
187
+ if (!voice.finished)
188
+ {
189
+ const priority = getPriority(channel, voice);
190
+ allVoices.push({ channel, voice, priority });
191
+ }
192
+ }
164
193
  }
165
- for (let i = 0; i < amount; i++) {
166
- const voice = voicesOrderedByVelocity[i];
167
- this.workletProcessorChannels[voice.channelNumber].voices
168
- .splice(this.workletProcessorChannels[voice.channelNumber].voices.indexOf(voice), 1);
169
- this.totalVoicesAmount--;
194
+
195
+ // Step 2: Sort voices by priority (ascending order)
196
+ allVoices.sort((a, b) => a.priority - b.priority);
197
+ const voicesToRemove = allVoices.slice(0, amount);
198
+
199
+ for (const { channel, voice } of voicesToRemove)
200
+ {
201
+ const index = channel.voices.indexOf(voice);
202
+ if (index > -1)
203
+ {
204
+ channel.voices.splice(index, 1);
205
+ }
170
206
  }
171
207
  }
172
208
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes