Animating to Sound or Mic using ZIM SoundWave

Here are two basic examples for using ZIM SoundWave()

You are welcome to ask any questions or post examples below.

A post was split to a new topic: Dropping Balls

Is impulse the best way to achive the best result here? It seems like the drop is not very smooth. The jump seems a bit over done. Thanks

@mathtechie - cool idea! Yes, impulse() is how you would do it. There is no need to change the force based on size as the force will already take into account the size and mass. So you could give the balls more mass perhaps or reduce the force. It will be up to you to get the balance right (Depeche Mode).

1 Like

It's moving along nicely. I just have some tweaks to make and it's all good.

Is there anyway to start/stop or pause the soundwave so that it stops listening?


let ticker = Ticker.add(calculatingFunction);
timeout(3, ()=>{Ticker.remove(ticker);});
timeout(6, ()=>{Ticker.add(ticker);});
1 Like

Ya - it's working well. I would make the ceiling higher.

const boundary = new Boundary(0,-H,W,2*H);
new Physics(10, boundary);

You also might want to only apply the force if the ball is touching the ground - or not currently active.

if (!emoj.body.IsAwake()) emoj.impulse(0, -data[i] * (emoj.b / emoj.a));

You know what... I just realized that you are probably constantly calling impulse because the soundwaves keep going. So maybe force() would be better than impulse. You might have to maginify the force by an amount but I bet that would be better - and then do not bother with the awake code.

Almost, there. I have added the check for the floor and adjusted the impulse accordingly. The issue I have now is that the floor check "times out" or something after a couple of seconds . After this it no longer detects the mic. I have to tap on the screen to "wake it" up but then it times out again, if the mic doesn't detect the mic. => {
   if (obj.side == "bottom") {
      emoj.impulse(0, -data[i] * 220);

You can store a property on each object as to whether it has been pushed. So then if it has not been pushed, push it and set the pushed to true. Then on contact set pushed to false. This way it will fly up only once - on an impulse. And when it hits the ground, it will be ready to fly up again.