WDI-SEA / game-project-issues

0 stars 0 forks source link

Listener feature running too many times? #34

Closed dryutsun closed 3 years ago

dryutsun commented 3 years ago

What's the problem you're trying to solve?

As one of my stretch features, I am attempting for an audio file to be read for "peak frequencies" and return to me a true or false value. This is to be tied to object spawns. Unfortunately, due to the nature of sound, I am getting like 80x true values detected instead of the 1 that I desire for the spawning.

Post any code you think might be relevant (one fenced block per file)

 if (data.f[0] > 250 && data.f[0] <= 255) { // get the first index of every updated sample value
    for (let i = 0; i < 1; i++) {
    isBeat = true;
    ctx.fillStyle = "red"
    ctx.font = "40px Fira Mono"
    ctx.textAlign = 'left';
    ctx.fillText(`${isBeat}`, 
    canvas.width / 2, canvas.height / 4);

  }} else {
    isBeat = false;
  }
  console.log(isBeat)

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

I don't have an error message, but because of the nature of the problem, I am receiving more data than I actually need which interferes with the function I am trying to build.

What is your best guess as to the source of the problem?

I have no way of setting a debounce period after a limit has been registered.

What things have you already tried to solve the problem?

I tried making the logic more strict and constraining the possible values being returned and I am now looking into debouncing and throttling. I am unsure if this is the right path to go down. Are there any eventlisteners that will listen to pure javascript and detect if a variable has changed its value? Please advise.

dryutsun commented 3 years ago

Thanks Doireann for your suggestions.

I may have to give up on this issue.

DoireannJane commented 3 years ago

You're welcome to leave it open. One of us can always come back to it tomorrow.

dryutsun commented 3 years ago

We have concluded that time is better spent achieving other stretch goals. Thank you Timm and Doireann!