g200kg / webaudio-tinysynth

Light-weight GM mapped WebAudio-JavaScript Synthesizer Engine / MIDI Player
Apache License 2.0
229 stars 22 forks source link

Per-channel effects #4

Closed fenomas closed 7 years ago

fenomas commented 7 years ago

Hi,

I'd like to differentiate the voices produced by tinysynth (e.g. add distortion to one channel but not others, or apply different amounts of reverb to different channels). Would inserting new audio nodes between the chPan nodes and actx.destination be the correct way to do it? That is:

var effect = // new audio node
synth.chpan[0].disconnect( synth.actx.destination )
synth.chpan[0].connect( effect )
effect.connect( synth.actx.destination )

or something along those lines? Or is there a better/safer way to do this?

Thanks!

g200kg commented 7 years ago

signal flow is : each note =>this.chvol[ch]=>this.chpan[ch]=>this.out=>this.conv/this.rev=>this.comp=>this.dest

chpan[] to actx.destination is not connected directly. this.out controls master volume. I recommend inserting nodes between chvol[ch] and chpan[ch].

However there is a problem that chpan[ch] may be omitted if the browser has not createStereoPanner(), that Safari does not support yet. If you need to support safari, around webaudio-tinysynth.js line 1074 should be modified.

fenomas commented 7 years ago

All very clear, thanks!