From d41e58e6cd71fdacdca69ba78c29d42dc7d330d5 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 20 Nov 2002 17:46:33 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r224, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/maxlib/; revision=225 --- src/velocity.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/velocity.c (limited to 'src/velocity.c') diff --git a/src/velocity.c b/src/velocity.c new file mode 100644 index 0000000..0f2d481 --- /dev/null +++ b/src/velocity.c @@ -0,0 +1,102 @@ +/* ------------------------- velocity ----------------------------------------- */ +/* */ +/* Get velocity of input in digits per second. */ +/* Written by Olaf Matthes (olaf.matthes@gmx.de) */ +/* Originally written for Max by Trond Lossius. */ +/* Get source at http://www.akustische-kunst.org/puredata/maxlib/ */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* You should have received a copy of the GNU Lesser General Public */ +/* License along with this library; if not, write to the */ +/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ +/* Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* ---------------------------------------------------------------------------- */ + +// velocity.c: (1000*(x[n]-x[n-1]))/Ęt +// (C) Trond Lossius/BEK 2000 +// Last revision: 4/7 2000 +// +// Input: +// float +// int (converted to float) +// set (set new value but no output) +// Argument (optional, defaults to 0): +// Initial stored value +// Output: +// float: Velocity as change per second (not ms) + +#include "m_pd.h" + +static char *version = "velocity v0.1, written by Olaf Matthes "; + +typedef struct velocity +{ + t_object x_ob; + t_outlet *x_out; + t_float x_xn1; /* input (floats) */ + t_float x_xn; + double x_lasttime; +} t_velocity; + +static void velocity_bang(t_velocity *x) +{ + double thistime; + t_float vel; + + thistime = clock_getlogicaltime(); + vel = (1000 * (x->x_xn - x->x_xn1) ) / (clock_gettimesince(x->x_lasttime)); + x->x_lasttime = thistime; + outlet_float(x->x_out, vel); +} + +static void velocity_float(t_velocity *x, t_floatarg f) +{ + x->x_xn1 = x->x_xn; + x->x_xn = f; + velocity_bang(x); +} + +static void velocity_free(t_velocity *x) +{ + // nothing to do +} + +static t_class *velocity_class; + +static void *velocity_new(t_floatarg f) +{ + t_velocity *x = (t_velocity *)pd_new(velocity_class); + x->x_out = outlet_new(&x->x_ob, gensym("float")); +#ifndef MAXLIB + post(version); +#endif + x->x_lasttime = clock_getlogicaltime(); + + return (void *)x; +} + +void velocity_setup(void) +{ + velocity_class = class_new(gensym("velocity"), (t_newmethod)velocity_new, + (t_method)velocity_free, sizeof(t_velocity), 0, A_DEFFLOAT, 0); + class_addfloat(velocity_class, velocity_float); + class_addbang(velocity_class, velocity_bang); + class_sethelpsymbol(velocity_class, gensym("maxlib/help-velocity.pd")); +} + -- cgit v1.2.1