Max 5 API Reference
00001 /* 00002 * jit.transfer.step.c 00003 * 00004 * Copyright 2001-2005 - Cycling '74 00005 * Derek Gerstmann - derek@cycling74.com 00006 * 00007 * functor for a transfer step functor 00008 * 00009 */ 00010 00011 // -------------------------------------------------------------------------- 00012 00013 #include "jit.common.h" 00014 #include "jit.functor.h" 00015 00016 // -------------------------------------------------------------------------- 00017 00018 typedef struct _jit_functor_transfer_step 00019 { 00020 t_jit_object ob; 00021 double threshold; 00022 } t_jit_functor_transfer_step; 00023 00024 // -------------------------------------------------------------------------- 00025 00026 t_jit_object *jit_functor_transfer_step_new(void); 00027 t_jit_err jit_functor_transfer_step_free(t_jit_functor_transfer_step *x); 00028 t_jit_err jit_functor_transfer_step_threshold(t_jit_functor_transfer_step *x, void *attr, long argc, t_atom *argv); 00029 t_jit_err jit_functor_transfer_step_recalc(t_jit_functor_transfer_step *x); 00030 00031 long jit_functor_transfer_step_eval_fixed(t_jit_functor_transfer_step *x, long dimcount, long *vals); 00032 float jit_functor_transfer_step_eval_float32(t_jit_functor_transfer_step *x, long dimcount, float *vals); 00033 double jit_functor_transfer_step_eval_float64(t_jit_functor_transfer_step *x, long dimcount, double *vals); 00034 long jit_functor_transfer_step_eval_fixed_scalar(t_jit_functor_transfer_step *x, long val); 00035 float jit_functor_transfer_step_eval_float32_scalar(t_jit_functor_transfer_step *x, float val); 00036 double jit_functor_transfer_step_eval_float64_scalar(t_jit_functor_transfer_step *x, double val); 00037 00038 t_class * _jit_functor_transfer_step_class; 00039 00040 // -------------------------------------------------------------------------- 00041 00042 t_jit_err jit_functor_transfer_step_init(void) 00043 { 00044 t_jit_object *attr; 00045 00046 // create functor class 00047 _jit_functor_transfer_step_class = jit_class_new("jit_functor_transfer_step", 00048 (method)jit_functor_transfer_step_new,(method)jit_functor_transfer_step_free, 00049 sizeof(t_jit_functor_transfer_step),0L); 00050 00051 // add attribute methods 00052 attr = jit_object_new(_jit_sym_jit_attr_offset,"threshold",_jit_sym_float64,0, 00053 (method)0L,(method)jit_functor_transfer_step_threshold, 00054 calcoffset(t_jit_functor_transfer_step,threshold)); 00055 jit_class_addattr(_jit_functor_transfer_step_class,attr); 00056 00057 jit_class_addmethod(_jit_functor_transfer_step_class, 00058 (method)jit_functor_transfer_step_eval_fixed, "evalfixed", A_CANT, 0L); 00059 jit_class_addmethod(_jit_functor_transfer_step_class, 00060 (method)jit_functor_transfer_step_eval_float32, "evalfloat32", A_CANT, 0L); 00061 jit_class_addmethod(_jit_functor_transfer_step_class, 00062 (method)jit_functor_transfer_step_eval_float64, "evalfloat64", A_CANT, 0L); 00063 00064 // important to add last for subclassing methods 00065 jit_functor_setup_class(_jit_functor_transfer_step_class,"transfer","step"); 00066 jit_class_register(_jit_functor_transfer_step_class); 00067 00068 return JIT_ERR_NONE; 00069 } 00070 00071 t_jit_object *jit_functor_transfer_step_new(void) 00072 { 00073 t_jit_functor_transfer_step *x; 00074 00075 if (x = (t_jit_functor_transfer_step *)jit_object_alloc(_jit_functor_transfer_step_class)) { 00076 00077 // initialization 00078 x->threshold = 1.0; 00079 jit_functor_transfer_step_recalc(x); 00080 } 00081 00082 return (t_jit_object *)x; 00083 } 00084 00085 t_jit_err jit_functor_transfer_step_free(t_jit_functor_transfer_step *x) 00086 { 00087 return JIT_ERR_NONE; 00088 } 00089 00090 t_jit_err jit_functor_transfer_step_threshold( 00091 t_jit_functor_transfer_step *x, void *attr, long argc, t_atom *argv) 00092 { 00093 double v; 00094 00095 if (x) { 00096 v=jit_atom_getfloat(argv); 00097 if (x->threshold != v) { 00098 x->threshold = v; 00099 jit_functor_transfer_step_recalc(x); 00100 } 00101 return JIT_ERR_NONE; 00102 } 00103 return JIT_ERR_INVALID_PTR; 00104 } 00105 00106 t_jit_err jit_functor_transfer_step_recalc(t_jit_functor_transfer_step *x) 00107 { 00108 // calculate intermediary values for efficiency 00109 return JIT_ERR_NONE; 00110 } 00111 00112 // -------------------------------------------------------------------------- 00113 // vector evaluation functions (calls scalar functions and generates a product of scalar evaluation for each dimension) 00114 // -------------------------------------------------------------------------- 00115 long jit_functor_transfer_step_eval_fixed( 00116 t_jit_functor_transfer_step *x, long dimcount, long *vals) 00117 { 00118 return jit_functor_eval_fixed_with_float64((t_jit_object *)x,dimcount,vals, 00119 (t_jit_functor_float64_sig)jit_functor_transfer_step_eval_float64); 00120 } 00121 00122 float jit_functor_transfer_step_eval_float32( 00123 t_jit_functor_transfer_step *x, long dimcount, float *vals) 00124 { 00125 return jit_functor_eval_float32_with_scalar_product((t_jit_object *)x,dimcount,vals, 00126 (t_jit_functor_float32_scalar_sig)jit_functor_transfer_step_eval_float32_scalar); 00127 } 00128 00129 double jit_functor_transfer_step_eval_float64( 00130 t_jit_functor_transfer_step *x, long dimcount, double *vals) 00131 { 00132 return jit_functor_eval_float64_with_scalar_product((t_jit_object *)x,dimcount,vals, 00133 (t_jit_functor_float64_scalar_sig)jit_functor_transfer_step_eval_float64_scalar); 00134 } 00135 00136 // -------------------------------------------------------------------------- 00137 // scalar evaluation functions 00138 // -------------------------------------------------------------------------- 00139 long jit_functor_transfer_step_eval_fixed_scalar( 00140 t_jit_functor_transfer_step *x, long val) 00141 { 00142 return FloatToFixed(jit_functor_transfer_step_eval_float32_scalar(x,FixedToFloat(val))); 00143 } 00144 00145 float jit_functor_transfer_step_eval_float32_scalar( 00146 t_jit_functor_transfer_step *x, float val) 00147 { 00148 return (val < x->threshold) ? 0.0f : 1.0f; 00149 } 00150 00151 double jit_functor_transfer_step_eval_float64_scalar( 00152 t_jit_functor_transfer_step *x, double val) 00153 { 00154 return (val < x->threshold) ? 0.0 : 1.0; 00155 } 00156 // --------------------------------------------------------------------------
Copyright © 2008, Cycling '74