Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.51k stars 983 forks source link

Unexpected behavior when modifying FatOscillator spread param #1064

Closed erdemoney closed 2 years ago

erdemoney commented 2 years ago

I'm building a synthesizer with React and Tone.js. When modifying the spread parameter for a FatOscillator, I found it does not create the expected effect on the sound of the oscillator and when adjusting it back to a zero value the original sound is not restored either. I'm very new to JS, React and Tone.js so it's likely this is an issue with my code rather than tone itself but I can't seem to figure out what's going on by myself.

https://codesandbox.io/s/jovial-meadow-7r76lh?file=/src/App.js Here's a small example. Just use the Input to change the spread to see what I'm talking about.

tambien commented 2 years ago

I think i understand what's going on: the expectation is that it would sound exactly the same when you get back to spread = 0, but after you move away from spread = 0 the oscillators go out of phase since some of the oscillators are actually running at a slightly higher or lower frequency than the base frequency. The detune spread of multiple oscillators is what gives the oscillator its "Fat" sound. When you get back to 0, the phases are no longer aligned like they were when it started so you'll have a slightly different sound.

I'll try illustrate these 3 states with some simple sketches:

Initial - spread = 0

Multiple oscillators with the same frequency and same phase, so they all overlap.

image

Spread > 0

Multiple oscillators are all at slightly different frequencies.

image

Return to spread = 0

The oscillators are at the same frequency, but they are not longer aligned in phase.

image

I hope this makes sense. If you're looking to have the exact same sound when you get back to spread = 0, the best way to do this is probably to stop and restart the oscillator.