Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
Error al cambiar la entrada de P5.Amplitude() con p5.sound.js

Tengo este código simple que se supone que muestra la amplitud de una señal de un oscilador, antes y después de pasarla por un filtro passBand. Parece que el error aparece cuando trato de cambiar la entrada del objeto p5.Amplitude cuando uso p5.Amplitude.setInput(). Qué estoy haciendo mal aquí ?

Aquí el mensaje de error:

 Uncaught TypeError: Cannot read properties of undefined (reading 'length') at RingBuffer.push (ae4c7513-7172-4e09-988d-70743483fbb1:75:45) at AmplitudeProcessor.process (ae4c7513-7172-4e09-988d-70743483fbb1:193:28)

Y aquí está mi código: (hice mi filtro bandPass agregando un lowPass y un highPass, no uso el objeto bandPass a propósito)

 let cnv, soundOnCheckbox, filterOnCheckbox let osc; let OscAmpIn, OscAmpOut let filterTab = [] function setup() { cnv = createCanvas(windowWidth, windowHeight); //Signal and Amplitudes OscAmpIn = new p5.Amplitude(0.9) OscAmpOut = new p5.Amplitude(0.9) osc = new p5.Oscillator('sine'); osc.freq(700) //Checkbox to turn sound and filters on/off soundOnCheckbox = createCheckbox('Sound On/Off', false) soundOnCheckbox.changed(soundOn); soundOnCheckbox.position(width/2,height/2) filterOnCheckbox = createCheckbox('Filter On/Off', false) filterOnCheckbox.changed(filterOn); filterOnCheckbox.position(width/2,height/2+20) creationFilter() } function draw() { background(55); translate(width/2, height/2) noStroke() fill(255) textSize(20) text("AmpIn = " + OscAmpIn.getLevel(),0,100) text("AmpOut = " + OscAmpOut.getLevel(),0,120) } //Turn the sound on/off function soundOn() { userStartAudio(); if(!soundOnCheckbox.checked()){ osc.stop() }else{ osc.start() } } //Create two filters (lowpass and highpass) to create a passBand function creationFilter(){ let lowPass = new p5.LowPass() let highPass = new p5.HighPass() lowPass.set(15000) highPass.set(10000) filterTab.push({lowPass,highPass}) } //Turn the filter on/off function filterOn(){ if(filterOnCheckbox.checked()){ osc.disconnect() //disconnect the osc from the main output osc.connect(filterTab[0].highPass) //Connect the osc to highpass filterTab[0].lowPass.connect(filterTab[0].highPass) //Connect the lowpass to the highpass. So we eventually have the osc connected to a bandpass setAmpInput() }else{ //If no filter, osc is linked to main output and AmpIn and AmpOut input are the same osc.connect() OscAmpIn.setInput(osc) OscAmpOut.setInput(osc) } } //Set the input of the amplitudes function setAmpInput(){ OscAmpIn.setInput(osc) //Set input of the amp as the sound before the filter OscAmpOut.setInput(filterTab[0].lowPass) //Set input of the amp as the sound after the filter }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que esto podría ser un error y podrías publicar un problema en p5.sound github. Debería poder conectar un filtro a la Amplitud...

OscAmpOut.setInput(filterTab[0].lowPass); no está conectando la Amplitud a la salida del filtro correctamente. Tienes dos opciones;

Puedes hacer OscAmpOut.setInput(); para que la Amplitud se conecte a la salida principal, que es la misma que la salida del filtro.

O, si desea utilizar la salida real de esta configuración de osc/filtro, debe agregar un nodo de ganancia. Se conecta después del filtro, osc -> lowPass -> highPass -> ganancia -> salida principal.

 let cnv, soundOnCheckbox, filterOnCheckbox; let osc; let OscAmpIn, OscAmpOut; let filterTab = []; function setup() { cnv = createCanvas(windowWidth, windowHeight); //Signal and Amplitudes OscAmpIn = new p5.Amplitude(0.9); OscAmpOut = new p5.Amplitude(0.9); osc = new p5.Oscillator("sine"); osc.freq(700); //Checkbox to turn sound and filters on/off soundOnCheckbox = createCheckbox("Sound On/Off", false); soundOnCheckbox.changed(soundOn); soundOnCheckbox.position(width / 2, height / 2); filterOnCheckbox = createCheckbox("Filter On/Off", false); filterOnCheckbox.changed(filterOn); filterOnCheckbox.position(width / 2, height / 2 + 20); creationFilter(); } function draw() { background(55); translate(width / 2, height / 2); noStroke(); fill(255); textSize(20); text("AmpIn = " + OscAmpIn.getLevel(), 0, 100); text("AmpOut = " + OscAmpOut.getLevel(), 0, 120); } //Turn the sound on/off function soundOn() { userStartAudio(); if (!soundOnCheckbox.checked()) { osc.stop(); } else { osc.start(); } } //Create two filters (lowpass and highpass) to create a passBand function creationFilter() { let lowPass = new p5.LowPass(); let highPass = new p5.HighPass(); let gain = new p5.Gain(); // setup a gain node //connect filter to gain lowPass.set(680); highPass.set(720); lowPass.disconnect(); highPass.disconnect(); lowPass.connect(highPass); //output from lowPass -> highPass highPass.connect(gain); //output from highpass -> gain gain.connect(); //output from gain -> main output filterTab.push({ lowPass, highPass, gain }); } //Turn the filter on/off function filterOn() { if (filterOnCheckbox.checked()) { //disconnect osc from main output osc.disconnect(); //connect osc to filter //output from osc -> lowpass -> highpass -> gain osc.connect(filterTab[0].lowPass); //set amplitude inputs OscAmpIn.setInput(osc); OscAmpOut.setInput(filterTab[0].gain); } else { //connect osc to main output osc.disconnect(); osc.connect(); //set amplitude inputs OscAmpIn.setInput(osc); OscAmpOut.setInput(osc); } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!