p5.js-sound
p5.js-sound copied to clipboard
PolySynth noteADSR error
I'm trying to apply an envelope to a note generate using p5.PolySynth, when clicking on the canvas.
I'm using the play()
to play the note and noteADSR()
to set the envelope (see code below).
I get the following error when calling playSynth()
:
Uncaught TypeError: this.notes[note] is undefined
Am I missing something? The documentation says that the envelope should be reset before setting a new one, but I'm not sure how to do it. Is that the issue?
Code
let synth;
function setup(){
let cnv = createCanvas(400, 400);
cnv.mousePressed(playSynth);
synth = new p5.PolySynth();
}
function draw(){
background('black');
}
function playSynth() {
userStartAudio();
let note1 = random(0, 127); // generates a random note.
let dur = 1.5; // note duration (in seconds)
let time = 0; // time from now (in seconds)
let vel = 0.1; // velocity (volume, from 0 to 1)
synth.play(note1, vel);
synth.noteADSR(note1, 0.02, 0.1, 0.5, 10);
}
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.
@balandinodidonato noteADSR only works when the current note is playing. So you should code like this
synth.noteAttack()
synth.noteADSR()
synth.noteRelease()
and hn currently use the secondFromNow
param to get desired output.