50 #define NUM_OF_POINTS 128
52 typedef struct _envExp {
57 double attr_amplitude;
59 double attr_decayrate;
60 double attr_threshold;
69 void *
envExp_new(Symbol *s,
long argc, t_atom *argv);
84 void envExp_assist(t_envExp *x,
void *b,
long msg,
long arg,
char *dst);
109 t_symbol *jps_symbol;
111 t_symbol *jps_float32;
112 t_symbol *jps_dumpout;
117 int JAMOMA_EXPORT_MAXOBJ
main(
void)
125 common_symbols_init();
126 jps_symbol = gensym(
"symbol");
127 jps_long = gensym(
"long");
128 jps_float32 = gensym(
"float32");
129 jps_dumpout = gensym(
"dumpout");
132 c = class_new(
"j.envexp",(method)
envExp_new, 0L,
sizeof(t_envExp), (method)0L, A_GIMME, 0);
135 class_addmethod(c, (method)
envExp_bang,
"bang", A_CANT, 0);
136 class_addmethod(c, (method)
envExp_float,
"float", A_FLOAT, 0);
137 class_addmethod(c, (method)
envExp_assist,
"assist", A_CANT, 0);
138 class_addmethod(c, (method)object_obex_dumpout,
"dumpout", A_CANT, 0);
141 attr = attr_offset_new(
"attack", jps_float32, attrflags,
143 class_addattr(c, attr);
146 attr = attr_offset_new(
"amplitude", jps_float32, attrflags,
148 class_addattr(c, attr);
151 attr = attr_offset_new(
"decayrate", jps_float32, attrflags,
153 class_addattr(c, attr);
156 attr = attr_offset_new(
"threshold", jps_float32, attrflags,
158 class_addattr(c, attr);
161 attr = attr_offset_new(
"steal", jps_long, attrflags,
162 (method)0L, (method)0L, calcoffset(t_envExp, attr_steal));
163 class_addattr(c, attr);
166 class_register(CLASS_BOX, c);
175 #pragma mark life cycle
181 t_envExp *x = (t_envExp *)object_alloc(
this_class);
187 object_obex_store((
void *)x, jps_dumpout, (
object *)outlet_new(x,NULL));
189 x->outlet =outlet_new(x, 0L);
193 x->attr_amplitude = 1.;
194 x->attr_decayrate = 90.;
195 x->attr_threshold = -90;
198 attr_args_process(x,argc,argv);
214 outlet_float(x->outlet, 0.);
222 x->attr_amplitude = f;
235 f = atom_getfloat(argv);
248 x->attr_amplitude = atom_getfloat(argv);
261 f = atom_getfloat(argv);
264 x->attr_decayrate = f;
276 f = atom_getfloat(argv);
278 error (
"j.envexp: Invalid threshold value");
280 x->attr_threshold = f;
292 case 0: strcpy(dst,
"(List) Max. ampl, attack time, decay time");
297 strcpy(dst,
"Envelope data in line~ format");
307 #pragma mark calculations
317 atom_setfloat(&x->envelope[j], x->attr_attack);
318 timestep = (-1000.*x->attr_threshold) /(x->attr_decayrate*(
NUM_OF_POINTS - 2.));
322 atom_setfloat(&x->envelope[j], timestep);
326 k = pow(10.,-0.05*x->attr_decayrate);
327 for (i=0; i<(NUM_OF_POINTS-1); i++)
330 atom_setfloat(&x->envelope[j], x->attr_amplitude*pow(k,i*timestep*0.001) );
332 j = (NUM_OF_POINTS-1)*2;
333 atom_setfloat(&x->envelope[j], 0.);
void envExp_bang(t_envExp *x)
Trigger new amplitude envelope using currenlty stored values.
int JAMOMA_EXPORT_MAXOBJ main(void)
Class Definition.
void envExp_setattack(t_envExp *x, void *attr, long argc, t_atom *argv)
Set attack time in ms.
void envExp_setthreshold(t_envExp *x, void *attr, long argc, t_atom *argv)
Sets the threshold attribute.
void envExp_steal(t_envExp *x, long var)
Sets the note stealing attribute.
void envExp_calculate(t_envExp *x)
Calculates array of envelope points.
void envExp_setamplitude(t_envExp *x, void *attr, long argc, t_atom *argv)
Sets the peak amplitude.
void envExp_float(t_envExp *x, double f)
Set peak amplitude attribute and trigger output.
#define NUM_OF_POINTS
maximum number of points that line~ accepts
void * envExp_new(Symbol *s, long argc, t_atom *argv)
Creates new instance.
void envExp_assist(t_envExp *x, void *b, long msg, long arg, char *dst)
Provides assistance cues.
t_class * this_class
Required. Global pointing to this class.
void envExp_setdecayrate(t_envExp *x, void *attr, long argc, t_atom *argv)
Sets the decay rate attribute.