jet2jet / js-synthesizer

Synthesizer library for web-based JS program, using with Web Audio or etc.
BSD 3-Clause "New" or "Revised" License
58 stars 8 forks source link

Can reverb and chorus be set while audio is playing? #24

Closed cwiggins999 closed 1 year ago

cwiggins999 commented 1 year ago

I've been able to use createAudioNode to specify reverb and chorus settings. But can these be adjusted while audio is playing?

Fantastic project, by the way - finding this extremely useful, and I love the WASM approach for libFluidSynth.

jet2jet commented 1 year ago

In MIDI reverb and chorus are defined as types of control changes. To apply these effects, please use midiControl in ISynthesizer, using ctrl = 91 for reverb or ctrl = 93 for chorus (I did not test yet).
If using ISequencer (Synthesizer.createSequencer), please use sendEventAt with ControlChangeEvent.

cwiggins999 commented 1 year ago

Thanks! I also found in non-worklet mode I could use the "setReverb..." functions to vary effects, so that's working pretty well. I don't have experience yet with AudioWorklets. That appears to involve including libfluidsynth-2.3.0.js twice - once in a script tag and once in the addModule function. Does that effectively double the memory footprint of libfluidsynth? We haven't decided which mode to run this in yet - need to do some testing with other components of our app.

I'm curious how this is used in other applications - any place with a list of such things? It's really perfect for what we need.

jet2jet commented 1 year ago

Does that effectively double the memory footprint of libfluidsynth?

Yes, we need to load libfluidsynth both in main script (script tag) and in Audio Worklet context, because js-synthesizer main script depends on global Module object. (This may be inconvenience, sorry.)

I'm curious how this is used in other applications - any place with a list of such things?

I don't know where js-synthesizer is used. I created js-sequencer which uses js-synthesizer in Web Worker (not in Audio Worklet; js-sequencer directly uses Audio Worklet), but it is a simple sequencer, so I wonder whether it helps you.

cwiggins999 commented 1 year ago

The MIDI file player in js-synthesizer (fluidsynth I suppose) has been working fine for that so far. Is there an advantage to using js-sequencer instead?

EDIT: I looked through js-sequencer code sample a bit, and think I see what you mean - just needing to load js-synth lib once in the AudioWorklet. Our main objective is to load our default sound font and play back MIDI files, but may go for more functionality in the future in terms of generating MIDI events. So that might work if we decide we need the worklet version for performance sake.

It's really a great approach to implementation - thanks!!

jet2jet commented 1 year ago

The MIDI file player in js-synthesizer (fluidsynth I suppose) has been working fine for that so far. Is there an advantage to using js-sequencer instead?

As you wrote, to play MIDI files simply with SoundFont, using Player in js-synthesizer (fluidsynth) is easier. But to play with complex processings, such as making smooth loop, implementing own sequencer (such as js-sequencer) may be suitable.
(I'm also using js-sequencer to play dynamically-generated MIDI messages.)

cwiggins999 commented 1 year ago

Thanks for the help. Everything is working great for now. I might migrate to js-sequencer at some point.