Tonejs / Tone.js

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

Crunchy sound artifact when playing chords with PolySynth #977

Closed abauville closed 2 years ago

abauville commented 2 years ago

Describe the bug

Whenever I play a chord with Polysynth (default parameters) there is crunchy sound like a very fast trill. It is particularly noticeable when the attack is longer. It seems to be occurring in Chrome but not in Firefox, although I hear different artifacts in Firefox (I'm not sure what's the correct term to describe them)

To Reproduce

In the official documentation for PolySynth V14.7.77 (https://tonejs.github.io/docs/14.7.77/PolySynth#maxPolyphony), modify the first example as:

const synth = new Tone.PolySynth().toDestination(); // set the attributes across all the voices using 'set' synth.set({ envelope: {attack: 0.5 }}); // play a chord synth.triggerAttackRelease(["C4", "E4", "A4"], 1);

The artifact can even be heard when playing octave ["C4", "C5"].

Expected behavior I really don't know

What I've tried I tried using different browsers, and the artifacts are different in Chrome and Firefox. There are less noticeable and different artifacts in Firefox.

Additional context MacOSX 11.6 Chrome Version 95.0.4638.69 (Official Build) (x86_64) Firefox 92.0.1

dirkk0 commented 2 years ago

I think it's just clipping:

const synth = new Tone.PolySynth();
const vol = new Tone.Volume(-12).toDestination();
// set the attributes across all the voices using 'set'
synth.set({ envelope: {attack: 0.5 }});
synth.connect(vol)
// play a chord
synth.triggerAttackRelease(["C4", "E4", "A4"], 1);
abauville commented 2 years ago

It occurs at minimum volume on Chrome and not at all on Firefox even at higher volume, therefore I don't think it's clipping. The artifact occurs both on headphones of through the computer output. Although the previous artifacts I mentioned on Firefox might have been clipping. My bad. To give you a better idea of what I mean, here's a reference clip of the sound playing on firefox: https://sndup.net/5q6h and the glitchy sound on Chrome: https://sndup.net/37r3

Also I'm using Tone.js v14.8.32

dirkk0 commented 2 years ago

What code did you use? Did you include Tone.Volume or Gain?

abauville commented 2 years ago

Nothing else. Actually, for the recording, I used the interactive documentation, with the code I provided above

dirkk0 commented 2 years ago

I did, too, that's why I am asking: did you try the code I provided?

abauville commented 2 years ago

Ha, sorry I didn't try your code earlier. Indeed, that fixes it. Thank you! I think we can close the issue. Although it is still curious that it works in Firefox without needing to pass the signal through a volume controller. Anyway, thanks a lot.

dirkk0 commented 2 years ago

Great! You can close this issue now.

abauville commented 2 years ago

:) Thanks again for your time @dirkk0.