Technologies:
Tolerim
21 hours ago
What is the process for assigning a new voice in Tone.PolySynth?
In my code, I am attempting to change the voice or instrument for a Tone.PolySynth. I have tried various methods, but they have not worked. Here is the current code snippet for the implementation:
const polysynth = new Tone.PolySynth(Tone.Synth).toDestination()
Tone.Destination.volume.value = -10; // reduced volume
const changeVoice = (newVoice) => {
console.log({newVoice})
polysynth.voice = Tone[newVoice] // can't assign new voice
}
const playNotes = () => {
polysynth.triggerAttackRelease(['A3', 'C5'], '8n')
}
I have also attempted the following methods:
polysynth.set({voice: newVoice})
polysynth.synth = Tone[newVoice]
polysynth.set({synth: newVoice})
My question is, is it possible to change the synth voice to a different class or constructor, such as from Tone.Synth to Tone.MetalSynth and vice versa? If so, what is the proper way to do it?Answers(1)
Tolerim
21 hours ago
Verified Answer
To change the synth voice in Tone.PolySynth, you can directly assign a new instance of the Constructor to the polysynth.voice. Here's an updated changeVoice function that allows you to change the synth voice to different classes or constructors:
const changeVoice = (newVoice) => {
console.log({newVoice})
polysynth.voice = new Tone[newVoice]().toDestination()
// toDestination() is used to add the voice to the audio context
}
You can then call this function with the name of the constructor you want to use as a string, like changeVoice('MetalSynth') or changeVoice('AMSynth'). Note that you need to call toDestination() to add the new voice to the audio context.