Control via audio level

    Mar 23 2010 | 12:09 pm
    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...

    • Mar 23 2010 | 12:18 pm
      Maybe average~ or thresh~ would give better results...
    • Mar 23 2010 | 2:08 pm
      Thank you, I hope it will work this time...
    • Mar 23 2010 | 3:41 pm
      try the right output of the levelmeter~ object
    • Mar 23 2010 | 3:43 pm
      (or is it the left one ?)
    • Mar 23 2010 | 3:56 pm
      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 ?
    • Mar 23 2010 | 3:58 pm
      is that the sort of thing you're looking for ?
    • Mar 24 2010 | 4:34 pm
      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...
    • Mar 24 2010 | 6:28 pm
      He didn't test the patch...;-)
      Onebang is probably also helpful in this context...
    • Mar 26 2010 | 3:22 am
      indeed, that onebang is the kind of useful basic objects i forget too easily :)
    • Mar 26 2010 | 2:14 pm
      I think I did it. I followed Patrick's recommendation. Could you please have a look at this:
    • Mar 27 2010 | 5:59 pm
      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?
    • Mar 28 2010 | 10:28 pm
    • Mar 29 2010 | 3:30 am
      Mmhhh... Is there an object that works as opposite of [past]?
      Thanks and regards.
    • Mar 29 2010 | 4:18 pm
      I would use and if statement
    • Mar 29 2010 | 5:42 pm
      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.)
    • Apr 01 2010 | 4:00 pm
      (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 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.
    • Apr 02 2010 | 2:30 pm
      << MBM's question about the "opposite of [past]" won't be realized using that [if] statement (e.g., [if $f1>
      or you could use a [onebang] after the logical test
    • Apr 02 2010 | 3:21 pm
      [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.
    • Apr 02 2010 | 6:58 pm
      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].
    • Apr 03 2010 | 6:34 am
      Thank you very much, Emerson :-)
      Best regards.
    • Apr 04 2010 | 10:35 am
      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
      -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:
    • Apr 04 2010 | 5:30 pm
      So, any opinions?
    • Apr 04 2010 | 5:42 pm
      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.
    • Apr 04 2010 | 5:52 pm
      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];
    • Apr 04 2010 | 5:57 pm
      Here's the upload...
    • Aug 20 2010 | 12:05 am
      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!
    • Aug 20 2010 | 5:55 am
      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:
      just in case it helps.
    • Aug 20 2010 | 6:04 pm
      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.