This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

play audio when signal goes over a threshold
#1
dear all,
I'd like to implement a kind of audio feedback control that makes the phone playing a sound everytime the gyroscope x-axis signal goes above a given threshold. Using the online editor, first I added an audio output in the "Output" tab of the editor. Then, in the "Analysis" tab, should I just add a "threshold" module with the x output of the sensor block as the y-input of the "threshold" module and then connect its output ("position") with the input of the "audio" module? 
Thanks,
Pietro
Reply
#2
In my understanding, you would like to play a tone whenever the gyroscope-y exceeds a certain value and none if it is below. You need a bit more logic in the analysis block, so that the tone in fact also stops.

A quick and dirty solution would perhaps be to set a brief sleep period for the analysis block and check with “max” (put a clear flag to that buffer!) if you are above threshold. With “if” you (un)set the tone…
Reply
#3
Hi Jens,
yes, you got it right! I've actually decided to use the phone's inclination about the y-axis to make things smoother. I created a simple experiment using atan2(ax,az) that outputs the inclination of the phone in degrees in the xz plane. Now, let's say that I want a sound when the inclination goes over 10° and it quits playing the sound when the inclination returns below 10°.
Unfortunately, I didn't really get your advices. Would a "threshold" module be ok rather than using "max" module? I tried to make the "if" module work but without succes. Would you please try to add some control to the attached experiment? Many thanks, Pietro.
.phyphox   feedback inclinometer.phyphox (Size: 2.08 KB / Downloads: 220)
Reply
#4
Photo 
Hi Jens, 
sorry to bother you again. I tried to use the "if" module like shown in the attached picture and I succeeded to play the sound when the signal crosses the value of "10". The problem is that it doesn't quit when the signal goes below 10. Honestly, I'm having some troubles in fully understanding how the "if" module works (not a general "if" statement I mean, as I usually program in Matlab, but PhyPhox's "if" module specifically.

In PhyPhox wiki on the analysis modules, about the "if" module, I read: "  For example if you set the true input to empty, do not connect the false input and set the output to clear, it will only clear the output if the condition is true, but leaves it alone otherwise. This can be used as a reset condition." This looks like a possible solution to stop quit the tone and I tried to implement it but I couldn't make it work.

Any ideas? Thanks for you patience,
Pietro


Attached Files Thumbnail(s)
   
Reply
#5
dear Jens,
as this thread hasn't got any reply since more than two months, I think this thread can be closed. I'm going to open a new thread to look for some support on the general use of the if-module (that is striclty related to the aim of this thread). Thanks for your time, Pietro
Reply
#6
Hi, somehow I have not been aware of the (unanswered) original post – and it has taken some time to look into this now… Sad

It is hard to tell from your screenshot what exactly is going on in the resulting xml code. I suppose that “Note, that since the visual editor does not support reusing buffers, you probably cannot do this there in a reasonable way...”, see https://phyphox.org/wiki/index.php/Analysis_modules#if, might be the reason.

We hope that we can settle this with a new blockly-based editor that will (keeping fingers crossed) be released soon…ish.

Until then, you likely need to fine tune the resulting code with a text editor (that sounds harder than it is, particularly, when you know a bit about XML).
Reply
#7
ok thank you Jens! I'm looking forward for the update! (ish.... :-) )
In the meanwhile, I'm able to use the if-module in a reasonable way now. I've also discovered that the audio module wants a binary input and it works perfectly with the if-module as you can set the output to "1" or "0".
So we can keep this thread open!
Keep in touch. Regards,
Pietro
Reply
#8
Hello,

I played a bit with the xlm file of the original gyroscope experiment, and here is a way to do it. If you want to modify it, just open the file with a text editor, I am not sure whether the online phyphox editor will handle the file.

Cheers,

Fred


Attached Files
.phyphox   gyroscope with tone.phyphox (Size: 33.26 KB / Downloads: 197)
Reply
#9
thanks! it actually works if embedded in PhyPhox app using the QR code but in the editor the audio block appears unlinked. But I'll start from here. Thanks!
Pietro
Reply


Forum Jump: