Detecting a fast numerical increase or drop


    Aug 07 2013 | 4:50 pm
    I have incoming numbers of 0 - 127, how would I want to do something like this: if $i1 decreases by 30 in 10ms then bang.
    I'm trying to create sword effects triggered by wiimote movements and I want the "clang" sample to be triggered if a sudden decrease in accelerometer data is detected.
    Any ideas?
    Thanks in advance, you guys have been great in the few days since I got my Max license. Hopefully I'll have learnt enough to be able to help out others before too long.

    • Aug 07 2013 | 5:42 pm
      Not to self promote, but I've made a video tutorial on doing basically exactly what you're describing. You can cheggiddout here:
      That being said, if you're looking for something you can copy-paste, something like this might get you started:
    • Aug 07 2013 | 5:49 pm
      One way to detect a large drop between successive input values. Edit: posted this before seeing Sam's response. Different approach to timing but otherwise similar...
    • Aug 07 2013 | 8:37 pm
      Thanks both.
      Sam - is there any reason why the patch you describe in your video wouldn't work using the ctlin object rather than udp?
      This is what I have at the moment and it doesn't seem to be working. The number object displays incoming MIDI numbers so osculator is working fine.
      Edit: I've decided to just go with the UDP method as it seems to be working well. I am curious as to why my patch wasn't working though...
      ----------begin_max5_patcher----------
      { "boxes" : [ { "box" : { "maxclass" : "comment", "text" : "raw accel data \nx y z", "linecount" : 2, "frgb" : 0.0, "numoutlets" : 0, "fontname" : "Arial", "patching_rect" : [ 212.0, 98.0, 210.5, 33.0 ], "id" : "obj-43", "fontsize" : 12.0, "numinlets" : 1 }
      } , { "box" : { "maxclass" : "newobj", "text" : "ctlin a1 2", "numoutlets" : 2, "fontname" : "Arial", "patching_rect" : [ 286.0, 132.0, 59.0, 20.0 ], "id" : "obj-37", "fontsize" : 12.0, "outlettype" : [ "int", "int" ], "numinlets" : 1 }
      } , { "box" : { "maxclass" : "newobj", "text" : "ctlin a1 1", "numoutlets" : 2, "fontname" : "Arial", "patching_rect" : [ 212.0, 132.0, 59.0, 20.0 ], "id" : "obj-33", "fontsize" : 12.0, "outlettype" : [ "int", "int" ], "numinlets" : 1 }
      } , { "box" : { "maxclass" : "button", "numoutlets" : 1, "patching_rect" : [ 407.5, 377.0, 20.0, 20.0 ], "id" : "obj-5", "outlettype" : [ "bang" ], "numinlets" : 1 }
      } , { "box" : { "maxclass" : "flonum", "numoutlets" : 2, "fontname" : "Arial", "patching_rect" : [ 520.0, 184.0, 50.0, 20.0 ], "id" : "obj-1", "parameter_enable" : 0, "fontsize" : 12.0, "outlettype" : [ "float", "bang" ], "numinlets" : 1 }
      } , { "box" : { "maxclass" : "newobj", "text" : "togedge", "numoutlets" : 2, "fontname" : "Arial", "patching_rect" : [ 407.5, 325.5, 54.0, 20.0 ], "id" : "obj-48", "fontsize" : 12.0, "outlettype" : [ "bang", "bang" ], "numinlets" : 1 }
      } , { "box" : { "maxclass" : "newobj", "text" : "> 69.", "numoutlets" : 1, "fontname" : "Arial", "patching_rect" : [ 407.5, 273.0, 38.0, 20.0 ], "id" : "obj-46", "fontsize" : 12.0, "outlettype" : [ "int" ], "numinlets" : 2 }
      } , { "box" : { "maxclass" : "newobj", "text" : "- 0.", "numoutlets" : 1, "fontname" : "Arial", "patching_rect" : [ 407.5, 238.0, 32.5, 20.0 ], "id" : "obj-45", "fontsize" : 12.0, "outlettype" : [ "float" ], "numinlets" : 2 }
      } , { "box" : { "maxclass" : "newobj", "text" : "t f f", "numoutlets" : 2, "fontname" : "Arial", "patching_rect" : [ 407.5, 192.5, 32.5, 20.0 ], "id" : "obj-44", "fontsize" : 12.0, "outlettype" : [ "float", "float" ], "numinlets" : 1 }
      } , { "box" : { "maxclass" : "newobj", "text" : "ctlin a1 3", "numoutlets" : 2, "fontname" : "Arial", "patching_rect" : [ 361.5, 132.0, 59.0, 20.0 ], "id" : "obj-40", "fontsize" : 12.0, "outlettype" : [ "int", "int" ], "numinlets" : 1 }
      } ], "lines" : [ { "patchline" : { "source" : [ "obj-44", 1 ], "destination" : [ "obj-45", 0 ], "hidden" : 0, "disabled" : 0 }
      } , { "patchline" : { "source" : [ "obj-44", 0 ], "destination" : [ "obj-45", 1 ], "hidden" : 0, "disabled" : 0 }
      } , { "patchline" : { "source" : [ "obj-48", 0 ], "destination" : [ "obj-5", 0 ], "hidden" : 0, "disabled" : 0 }
      } , { "patchline" : { "source" : [ "obj-40", 0 ], "destination" : [ "obj-1", 0 ], "hidden" : 0, "disabled" : 0 }
      } , { "patchline" : { "source" : [ "obj-40", 0 ], "destination" : [ "obj-44", 0 ], "hidden" : 0, "disabled" : 0 }
      } , { "patchline" : { "source" : [ "obj-46", 0 ], "destination" : [ "obj-48", 0 ], "hidden" : 0, "disabled" : 0 }
      } , { "patchline" : { "source" : [ "obj-45", 0 ], "destination" : [ "obj-46", 0 ], "hidden" : 0, "disabled" : 0 }
      } ], "appversion" : { "major" : 6, "minor" : 1, "revision" : 3, "architecture" : "x86" }
      } -----------end_max5_patcher-----------