p5.js-sound
p5.js-sound copied to clipboard
Polysynth performance problems?
I'm trying to sequence some notes using a p5.Phrase, p5.Part and a p5.PolySynth. The performance is very poor with lots of noticeable glitches. I wonder if I have made a mistake in my implementation? I've tried with my own custom AudioVoice class, and the default p5.MonoSynth, but perform as badly as each other. The code is posted below, and here is a link to a p5.js Editor version.
let polySynth, phrase, music;
function setup() {
createCanvas(100, 100);
background(220);
text('click to play', 20, 20);
polySynth = new p5.PolySynth();
phrase = new p5.Phrase('melody', playSynth, ['G3', 'G4', 'G3', 'G2', 'G3', 'G4', 'G5', 'G6']);
polySynth.setADSR(0.1, 0.3, 0.6, 0.1);
music = new p5.Part();
music.addPhrase(phrase);
music.setBPM(80);
music.loop();
userStartAudio();
}
function playSynth(time, note) {
let dur = 1;
let vel = 0.25;
polySynth.play(note, vel, time, dur);
}