Control via audio level

Mar 23, 2010 at 12:09pm

Control via audio level

Hello all,

I’m trying to trigger a “metro” object via audio input from mic (i.e. when the music starts).
Is there a convenient method for this (“control by means of detecting audio level”)?
I tried it using “snapshot~”, but it didn’t result in consistent behavior.

Looking forward to any help…

#49298
Mar 23, 2010 at 12:18pm

Maybe average~ or thresh~ would give better results…

p

#177110
Mar 23, 2010 at 2:08pm

Thank you, I hope it will work this time…

#177111
Mar 23, 2010 at 3:41pm

try the right output of the levelmeter~ object

#177112
Mar 23, 2010 at 3:43pm

(or is it the left one ?)

#177113
Mar 23, 2010 at 3:56pm

oh wait i misunderstood your problem
hm so just try what Patrick said :) anyway you can use the output of that levelmeter~ (which is a unique outlet), and then use a change which causes a bang in case of 0 to non zero transition (and if you want that bang once you can add a change after that output so it won’t hapen twice), and in between add or substract a value to find the good calue of threshold.
Is that it ?

#177114
Mar 23, 2010 at 3:58pm
– Pasted Max Patch, click to expand. –

is that the sort of thing you’re looking for ?

#177115
Mar 24, 2010 at 4:34pm

Hi vichug, just seen your msgs, thank you for your help. I tried your patch (appending it to audio), but the “change”s never seem to cause a “bang”. I will be on it…

#177116
Mar 24, 2010 at 6:28pm

He didn’t test the patch…;-)
Onebang is probably also helpful in this context…

– Pasted Max Patch, click to expand. –
#177117
Mar 26, 2010 at 3:22am

indeed, that onebang is the kind of useful basic objects i forget too easily :)

#177118
Mar 26, 2010 at 2:14pm

I think I did it. I followed Patrick’s recommendation. Could you please have a look at this:

– Pasted Max Patch, click to expand. –
#177119
Mar 27, 2010 at 5:59pm

Hello again. About the patch I sent yesterday (could anyone try it?), it seems that each time I reload the patch, “the optimum threshold~ set value for reasonable operation” changes. Any ideas about the cause/solution?

#177120
Mar 28, 2010 at 10:28pm

– Pasted Max Patch, click to expand. –
#177121
Mar 29, 2010 at 3:30am

Mmhhh… Is there an object that works as opposite of [past]?

Thanks and regards.

#177122
Mar 29, 2010 at 4:18pm

I would use and if statement

– Pasted Max Patch, click to expand. –
#177123
Mar 29, 2010 at 5:42pm

Thanks stoplaughing, your patch does it very well.
I’ll have to add some additional controls to prevent false alarms as now the metro starts even with a click produced while taking the microphone in the hand or turning it on/off. (The [metro] should be triggered only with persistent audio level.)

#177124
Apr 1, 2010 at 4:00pm

(to MBM and stoplaughing… –how do we technically notify certain users during posting, anyway?)
MBM’s question about the “opposite of [past]” won’t be realized using that [if] statement (e.g., [if $f1<0.05 then bang]; this continuously gives bangs at the [meter~]‘s output rate), because these should also be tested: the “current” value should be less than the “previous” value while the previous one must have left the “below threshold” region.
This javascript code below functions just as the opposite of [past] object:

var A = new Array(0.05, 0);
function msg_float(r)
{
A[1] = r;
if((A[0] >= 0.05) && (r < A[0]) && (r < 0.05))
outlet(0, “bang”);
A[0] = A[1];
}

Meanwhile, if anyone knows a method to realize this kind of queue structure without using a js object, please teach me.
(to stefantiedje) Sorry I forgot to thank for your post. Thank you.

#177125
Apr 2, 2010 at 2:30pm

< < MBM's question about the "opposite of [past]" won't be realized using that [if] statement (e.g., [if $f1<0.05 then bang]; this continuously gives bangs at the [meter~]'s output rate), because these should also be tested: the "current" value should be less than the "previous" value while the previous one must have left the "below threshold" region. >>

or you could use a [onebang] after the logical test

#177126
Apr 2, 2010 at 3:21pm

[Onebang] is the answer, of course, I didn´t realize. Thanks.

Emerson, thank you very much, but I don´t know JS and I don´t know how open your “patch” (is that its name?) with Max. Thanks.

#177127
Apr 2, 2010 at 6:58pm

About using a [onebang] there:
I couldn’t figure it out exactly, vichug, especially how to solve the representation of current and previous values.
Could you post an example or explain it a little more?

MBM, you’re welcome, you can use that code like this:
in the Max patcher, create a js (javascript) object. i.e.: write something like this on it:

js oppositepast.js

Lock the patcher, double click the js object, paste the code inside the opening window, (for a better initial value, change the 0.05 “only in the first line” with any smaller number to prevent an unnecessary single bang in the beginning -my bad), save.

Now you can connect its inlet to [meter~] and its outlet to a [bang].

#177128
Apr 3, 2010 at 6:34am

Thank you very much, Emerson :-)

Best regards.

#177129
Apr 4, 2010 at 10:35am

Using both the [past] and its opposite (the [js ...] above; still curious if anyone can make it without js code), I’m posting the patch below, which detects rise and fall of audio level, and restarts a [counter] whenever the audio level does not stay high for long enough at least once, otherwise quits checking.
(i.e., the controls I mentioned before, to prevent false alarms caused by clicks/pulses.)

Of course, the beginning of the music itself could consist of clicks/pulses, but I’m trying to tailor the detection to suit my specific plan: Trying to start the flow of some algorithms simultaneously with a singer starting to sing through the mic.

I’ve written this much about it to ask a question: Which one is a failsafe method to serve the above purpose:
-Detecting the audio level like this
or
-Detecting the -monophonic- pitch
(the first note of the singer is known a priori)

Looking forward to any ideas. Here’s the patch, suggested for the 1st option:

– Pasted Max Patch, click to expand. –
#177130
Apr 4, 2010 at 5:30pm

So, any opinions?

#177131
Apr 4, 2010 at 5:42pm

copypasting js objecs doesn”t work here, one has to manually add your js code in the [js compseq.js] object and to save it on his computer (i think) for it to work.

#177132
Apr 4, 2010 at 5:52pm

I had guessed that, but I thought the content could be found above as I had given before (7 posts before, though.)

Ok, let me upload the maxpat and js files as a zip file.

Btw, the content of js was as follows:

inlets = 1;
outlets = 1;

var A = new Array(0.03, 0);

function msg_float(r)
{

A[1] = r;
if((A[0] >= 0.05) && (r < A[0]) && (r < 0.05))
outlet(0, “bang”);
A[0] = A[1];

}

#177133
Apr 4, 2010 at 5:57pm

Here’s the upload…

Attachments:
  1. patch_and_js.zip
#177134
Aug 20, 2010 at 12:05am

Hey guys, I modified the patch a bit for my own purposes and I thought you might enjoy my modifications.

I just jumped on to Max for Live, coming from PD, and I was highly surprised the incredibly useful threshold~ object from PD isn’t available in Max.

My goal was to have a gate open with a kick drum, and close when the kick drops below a threshold.

I first use onepole~ with a very low cutoff so it’s as cheap an LPF as I can get then send it to Miller Puckette’s excellent bonk~ transient detector to grab beat onsets. I use the output of bonk~ to open my final gate as well as open the gate that leads to past and compseq.js which I use to close the final gate.

I left compseq.js the same as it is earlier in this thread but basically just use bonk~ to do my beat onset detection.

Comments are more than welcome. Enjoy!

– Pasted Max Patch, click to expand. –
#177135
Aug 20, 2010 at 5:55am

smilinggoat wrote: “I was highly surprised the incredibly useful threshold~ object from PD isn’t available in Max.”

the pdmax conversion is interesting indeed… often clearcut, sometimes not so much…
you can create pd’s threshold~ somewhat easily using thresh~ and edge~, although the debounce time parameter for pd’s threshold~ will take a little more working out:

– Pasted Max Patch, click to expand. –

just in case it helps.

#177136
Aug 20, 2010 at 6:04pm

Thanks for the tip, Noob4Life. I wasn’t aware of the edge~ object, saves me a lot of logic programming time. So many new (for me) toys to play with.

#177137

You must be logged in to reply to this topic.