Is there a correct alternative to cancelAndHoldAtTime when the browser does not support this? - web-audio-api

Using WAA (Web Audio Api) I am using exponentialRampToValueAtTime to create a fade in and out that can be cancelled for the user pressing the "stop" button.
The stops function looks something like this:
this._gainNode.gain.cancelAndHoldAtTime(this._AudioContext.currentTime);
this._gainNode.gain.exponentialRampToValueAtTime(0.000001, this._AudioContext.currentTime + fadeDuration);
The complete function is wrapped in a Promise because I need to do something else after the stop (fadeDuration);
The problem is that in some browsers cancelAndHoldAtTime does not exit and I get some nasty clips that I do not know how to prevent. The same happens with cancelValuesAndHoldAtTime that is even less supported.
I tried with cancelScheduledValues but it does not help.
Is there a workaround or correct alternative to cancelAndHoldAtTime

You can do an approximation by calling setValueAtTime(v, t) where t is the context time at which the user pressed the stop button and v is the estimated value of the exponential at time t.
You'll probably still get a glitch, but it will probably be much better than using just cancelScheduledValues.
This is the reason why cancelAndHoldAtTime was added to the API.

Although maybe the best alternative for cancelAndHoldAtTime is the one recommended for Raymond Toy, to completely remove the clip and any glitches what I ended up doing was making a "Main Gain" between the oscillator Gain and the destination
OSC -> oscGain -> mainGain -> speakers.
Before I do anything I close the mainGain and then cancelScheduledValues and all the other stuff to the oscGain

Related

MaxMSP/Arcade Button Responding Incorrectly with HI Objject

I'm linking an arcade button connected to a USB encoder with a Max patch. The button is behaving strangely. Here's what happens:
I have the button mapped to the a key. When Max is open, this functionality breaks. Even outside of Max. Even once I close Max, I need to remap the key. I'm not using MAME or anything like that; just JoytoKey for the mapping.
This issue is negated partially through use of the HIobject. Max recognizes the button and I can use it, however it's not functioning as an on/off. Rather a bang is sent on button press and release. How do I make the button work normally (send a single bang on press, and none on release)?
Here's my patch, if it helps. I don't know how useful it is without my video files:
<pre><code>
----------begin_max5_patcher----------
2245.3oc6cszbjpaEdsmpl+CTr1gB8hGYY1jJYaRVMUptvzx1ZtzPGdX6I2J
+2i3YyCoF0.M8hqbMi6FjP5b9zQe5bPvw+92+1Sluj7EMyz3Oa7Cimd524m4
opyUdlmZOwSlm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2EtU8nuYeygqqgcYHP1w9lrXDYZ
ZsBPpRQmHjS86.Y+i7qR4GnxyMIEWhr1FEChUBJcuplAbbDj0GpyRN.Gjjx1
F42cKjeemouien5zroP4uprsQ982.4GB8l91zsOxORIweLizH4WnINe5a06s
FBTm2P6ejWc1mzywBONYUVVzkNJI8HMsxQwMRWmkC.3uYjNpgsiLf5zX6sPB
.ag0Iez8AM6BoD6FhrcCYpsRnmjwLu8SDjY13tah.1VhH3reh.PhHP1OQ.JQ
D72MQvEKQDv6mHPtmrXpIBNRDAv9IBtRDA39IBxnlPagHnTfIvsKvDjRdWAm
y6PjfL.QclzQnmiUksIx+XJRIxu+LdGRDjqEZyDPdRJaajek7eXrWFikeGfb
4WjuEan7CuECVY1ObeVmlUFvMQGIJxI7VEcDYS7eyG7nhtff1.4GAgV6mDS1
BIlfq+q2wtHwaQDzHOxNhwaQLyUYY88RhcUJNDxL7f9tBRpzM7f90I4kgGUy
wHb961ww3pjEO45qQggNBxH40ZSyH0nip0s9GsMZiiRZyLyF3FNxzFT88tXz
Q0ZSyrnMTaTZt8XNKUt6LsxO4h1rMRrRtHRPyv36I3OgDMRLr+Lk1iZv+5UJ
Di+M2Z9fym+fll0HO0Jh4ofelTG.+y0GyhqOtNwEZlR+f0dI0ItPyfzv2Y4z
v1cvy7Kml79T0eYYRiKXsAeTBkkccUdXpbeEyNGTCZU4qou+MdE9+qypUK.
-----------end_max5_patcher-----------
</code></pre>
It's hard to give an exact answer without knowing what your USB device outputs, however in your patch whatever exits the [hi] object goes into the [live.text] button, which is set to Button mode, always converting it to a bang.
In the patch below I set the [live.text] button to Toggle mode. I also took the liberty of cleaning some other things up.
The next thing though is that you will need to find out what part of the output of the hi object is the information you are looking for. You can do that with a [print] object. Then you can select that number with an [unpack] and select the 1's and use that to trigger [random] (see the patch below).
----------begin_max5_patcher----------
1559.3oc6Z0ziiZCF9bxuBDmmF4O3ypdpWpZu11SqVE4P7Lw6BXpwjYFsZ+u
WaCjPBDvIgY6gl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sARsAN8vmKbymVqxo0VdlCDXIP6aRsLHnGPOklH16GasDHsmtS2o2.poi+
2F32hhs5ESGqgMym.e+.eHHFqMLLG9ENBzA+R47htxs9dAsP4f6rhHFOVU30
q7hmfA1JHuJ4lkv8RjhBmVqryDr2ZKdYKKQOQDw6GYK0iUTIWqU9pDzoNzkl
ZBCF.A8gpv851PHOEV6E34oc6zMmosDI47nXIorhCGBa2vXKbIaJ4opHepMx
Nin964RAe8e8J6EhHqDsJiu+PbEkaEVJ8PfmoG5WUoPVWFAeOipaoy.ZnuJP
jNKe+Pbm9NSqvHD7bohlVWpXJ5g.xcjktLV2hKpCjySaTWOhUlNDMyV+dR3o
Jmn7ssbMQ7xlSmzpb1+T0z8oOqxXkJJNzSaGMgeasDmfJXF7UeKUUX9nTwzC
0JpHvSqc4G8fJFkJf1SEvakJhBLTQ7CpXPpfPDE3oogKMLqn.jef18K3AEbQ
J.YGEbyNj7hMT.7AEbQJ.ZGEbyNhv.sin.zCJXPJnM8GKngwFpcwDPFqA7Cp
XzjVcv1m0pyMGcvGqq5Iv6AYLZtRX6yU5lohvProNo+eQEMMdxY4YlBW8Auc
1O5FSgl51Osn+RdkHoc607xLb5TLIsTxxOTY7mN7CHoyX3hsTgol1AOmAaW3
H0jBmXgMmHsykNQi4TDiFVDg20B6YwBi8lAI7.NM5RMGqDxh0Qe1L28BoOP2
I0OPyA1YgDglKAZRnaNT28sQWXNDIrUJ39yjI7jNKN0MUFaaAW4TswuHLdnW
bVP+WeTj+pPuabb0+9WfPvJu3A55d0Tis.EvygIQnMpp52E68uT1nr1WlpC6
QJJ1SEkMC1rFtYjuvMttidxbKKu9VyAv5Jn6YsiutEhHYGSRSZOnV22BpO.e
WcbbQdEqINfR5VpOYURYoNclxBRsfXNX8kee4+Jwi4ZG
-----------end_max5_patcher-----------

Unity - Navmesh event on navigation end

Is there a way to raise a flag on the Navmesh navigation end, or to use a callback when it finish?
I want to run a function when my objection reach to the desire position, I can check on every frame update if the navigation has finished but I want a more elegant and efficient solution.
Thanks.
It depends what you mean by "ends", if you want to know when a path is no longer available for the NavAgent, you can use pathStatus, for example you could write:
if(myNavAgent.pathStatus != NavMeshPathStatus.PathComplete) {
// Do stuff
}
If you me reaching a location such as a "waypoint" you can use myNavAgent.remainingDistance then check if it is less than a certain value.
Here's the unity NavAgent scriptingAPI doc link: https://docs.unity3d.com/ScriptReference/AI.NavMeshAgent.html
If this doesn't work, let me know!
I have Thought the same question and i couldn't find a callback, However i managed to solve with triggers. For example if my agent goes point a, i put trigger that position and when my agent touches it i stopped agent.

Connecting FluidEnter/FluidExit at run-time

I am toying with the FluidEnter/FluidExit. So in a simple form, here is what I am trying to do:
I created in Main an empty population of agent called Terminal. For now, in Terminal, there is only a fluidEnter connected to a fluidExit (very simple)
enter image description here
Now, on startup, I want to fill this population and set up the proper connections (the terminals are ordered).
So, on startup, I call a function init(), whose body start with Terminal t = add_terminals(); (I have only one terminal for now, just toying with things)
In Main, obviously, I also have a fluidEnter and a fluidExit. I would like to connect the fluidExit of Main to the fluidEnter of the terminal t, and the fluidExit of the terminal t to the fluidEnter of Main, so code (still in init()) looks like
fluidExit.set_fluidEnter(t.fluidEnter);
t.fluidExit.set_fluidEnter(fluidEnter);
I get an exception so obviously, I am doing something wrong. Any idea?
I think the set_fluidEnter function is deprecated or just non-functional.
Instead, you should do:
fluidExit.connect(t.fluidEnter);
So just replace set_fluidEnter with connect... nothing else.
That should do the trick
I was going down the same path as you a couple of months ago. Yes... .connect() works great. It even works as a gate. If it is disconnected, then fluid stops at the exit. Once connected, fluid starts to flow again. It is very slick.

Editing Timeline from CCB file in cocos

I did some research into this and couldn't really find anything, so if this is a repetitive question I apologize. but anyway I have made a CCB file in CocosBuilder and I would like to start the timeline, for example, at one second instead of playing from the beginning. Is there a way to do this? Thanks for the help guys.
Edit: i would like this to be done in the code.
I am using 2.2.1 Cocos2DX version. I think there is no option to play it from given interval. But you can tweak yourself to get it done. (Not simple one)
You have to go to CCBAnimationManager and there you get "mNodeSequences".
It is dictionary and you get difference properties there like "rotation position etc..."
values there.
Internally AnimationManager reads this value (These values are specified in your CCB)
and puts in runAction queue.
So you have to break it as you want.(Ex. 5 min timeline you have. But you want to start
from 1 min then you have run first 1 min Actions without delay and for remaining you
have properly calculate tween intervals.
It's long procedure and needs calculation. If you don't know any other simpler way try this. If you know pls let us know (Post it).

NSStream Event Timer - iPhone

All,
Is there a way to have a minimum time to keep a stream open before it closes? For some reason, my stream is closing prematurely which is causing errors elsewhere. I need to keep it open to make sure ALL of the data is gathered, and then it can run the other code.
Thanks,
James
In the case that someone falls upon this question later, I ended up creating nested if statements to pull it off.
Basically, there is one statement that checks if the end tag is not found (for my code, the END of the ENTIRE data that I should be receiving is </SessionData> - So, I did if([outputString rangeOfString:#"</SessionData>"].location == NSNotFound). I created a string called totalOutput that would have the outputString added onto the end of totalOutput until the </SessionData> is found.
If anyone ever needs help, just go ahead and comment on here and I can give more information.