void *uwemsp_new(t_symbol *s, long argc, t_atom *argv) { // Max calls this function when it needs an instance of your object t_uwemsp *x = 0; int count; if (x = (t_uwemsp *)object_alloc(uwemsp_class)) { // add signal inlets (these can be used for other messages dsp_setup((t_pxobject *)x, UWE_SIG_INPUTS_COUNT); x->u_pxob.z_misc |= Z_NO_INPLACE; // regular outlets would need adding here, before signal outets //... // add signal outlets for(count = 0; count < UWE_SIG_OUTPUTS_COUNT; count++) { outlet_new(x, "signal"); } // allocate an array to store our signal pointers in x->u_buffers = (t_float**)sysmem_newptrclear(sizeof(t_float**) * UWE_SIG_IO_COUNT); // initialise any other data x->u_param = 1.f; } // return a pointer to our object back to Max return (x); }
int memalloc(t_myObj *x, int n) { if(x->infilt) x->infilt = (double*)sysmem_resizeptr(x->infilt, (n+2)*sizeof(double)); else x->infilt = (double *)sysmem_newptrclear((n+2)*sizeof(double)); if(!x->infilt) { object_error((t_object *)x, "memory allocation failed!"); return 1; } if(x->outfilt) x->outfilt = (double *)sysmem_resizeptr(x->outfilt, (n+2)*sizeof(double)); else x->outfilt = (double *)sysmem_newptrclear((n+2)*sizeof(double)); if(!x->outfilt) { object_error((t_object *)x, "memory allocation failed!"); return 1; } x->blocksize = n; return 0; }
void *urner_new(t_symbol *s, long argc, t_atom *argv) { t_urner *x = NULL; long size; if (argc < 1) return NULL; size = atom_getlong(argv); // SIZE OF OUR URN if (size < 1) return NULL; // CHECK FOR INVALID DATA if (x = (t_urner *)object_alloc(urner_class)) { x->table = (char *)sysmem_newptrclear(size); // size BYTES for the alloced pointer urner_reset(x); // initializes x->count x->bangout = outlet_new(x, NULL); // rightmost outlet first x->out = outlet_new(x, NULL); // then to the left } return (x); }
void multigrain_init(t_multigrain *x,short initialized) { int i; if(!initialized){ x->pitchsteps = 0; // we could predefine a 12t scale x->mute = 0; x->steady = 0; x->events = 1; // set to 10 LATER x->horizon_ms = 1000; x->min_incr = 0.5; x->max_incr = 2.0; x->minamp = .1; x->maxamp = 1.0; x->mindur_ms = 150; x->maxdur_ms = 750; x->transpose = 1.0; x->pitch_deviation = 0.0; x->lowblock_increment = 0.0; // by default we do not block any increments x->highblock_increment = 0.0; // ditto x->constrain_scale = 0; x->retro_odds = 0.5;// after testing, set this to zero x->maxskip = -1;//flag to reset in setbuf SHOULD BE -1 x->nopan = 0;//panning is on by default x->interpolate = 1; x->interpolate_envelope = 0; x->groupflag = 0; x->changroup = (long *)sysmem_newptrclear(x->output_channels); x->minchanr = 0; x->maxchanr = x->output_channels - 1; } x->horizon = x->horizon_ms * .001 * x->sr; x->mindur = x->mindur_ms * .001 * x->sr; x->maxdur = x->maxdur_ms * .001 * x->sr; for( i = 0; i < MAXGRAINS; i++ ){ // this is what we test for a legal place to insert grain x->grains[i].active = 0; } }
// Platform independent (cleared) memory allocation tt_ptr tt_audio_base::mem_alloc(long size) { tt_ptr alloc; // Cycling '74 Max #if defined(MAC_VERSION) || defined(WIN_VERSION) alloc = (tt_ptr)sysmem_newptrclear(size); if(alloc){ return alloc; } else{ error("tt_audio_base::mem_alloc - could not get memory"); return 0; } // Generic Mac #elif defined(TAPTOOLS_TARGET_MAC) alloc = (tt_ptr)NewPtrClear(size); if(alloc) return alloc; else{ //error("tt_audio_base::mem_alloc - could not get memory"); return 0; } // Generic Win #elif defined(TAPTOOLS_TARGET_WIN) //alloc = HeapAlloc(GetProcessHeap(), 0, size); // Windows API alloc = (tt_ptr)calloc(1, size); // Should add some error checking here return alloc; // Not Defined #else #error VALID TARGET NOT DEFINED! #endif }
void *cmgrainlabs_new(t_symbol *s, long argc, t_atom *argv) { t_cmgrainlabs *x = (t_cmgrainlabs *)object_alloc(cmgrainlabs_class); // create the object and allocate required memory dsp_setup((t_pxobject *)x, 11); // create 11 inlets if (argc < ARGUMENTS) { object_error((t_object *)x, "%d arguments required (sample/window/voices)", ARGUMENTS); return NULL; } x->buffer_name = atom_getsymarg(0, argc, argv); // get user supplied argument for sample buffer x->window_name = atom_getsymarg(1, argc, argv); // get user supplied argument for window buffer x->grains_limit = atom_getintarg(2, argc, argv); // get user supplied argument for maximum grains // HANDLE ATTRIBUTES object_attr_setlong(x, gensym("stereo"), 0); // initialize stereo attribute object_attr_setlong(x, gensym("w_interp"), 0); // initialize window interpolation attribute object_attr_setlong(x, gensym("s_interp"), 1); // initialize window interpolation attribute object_attr_setlong(x, gensym("zero"), 0); // initialize zero crossing attribute attr_args_process(x, argc, argv); // get attribute values if supplied as argument // CHECK IF USER SUPPLIED MAXIMUM GRAINS IS IN THE LEGAL RANGE (1 - MAXGRAINS) if (x->grains_limit < 1 || x->grains_limit > MAXGRAINS) { object_error((t_object *)x, "maximum grains allowed is %d", MAXGRAINS); return NULL; } // CREATE OUTLETS (OUTLETS ARE CREATED FROM RIGHT TO LEFT) x->grains_count_out = intout((t_object *)x); // create outlet for number of currently playing grains outlet_new((t_object *)x, "signal"); // right signal outlet outlet_new((t_object *)x, "signal"); // left signal outlet // GET SYSTEM SAMPLE RATE x->m_sr = sys_getsr() * 0.001; // get the current sample rate and write it into the object structure /************************************************************************************************************************/ // ALLOCATE MEMORY FOR THE BUSY ARRAY x->busy = (short *)sysmem_newptrclear((MAXGRAINS) * sizeof(short *)); if (x->busy == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE GRAINPOS ARRAY x->grainpos = (long *)sysmem_newptrclear((MAXGRAINS) * sizeof(long *)); if (x->grainpos == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE START ARRAY x->start = (long *)sysmem_newptrclear((MAXGRAINS) * sizeof(long *)); if (x->start == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE T_LENGTH ARRAY x->t_length = (long *)sysmem_newptrclear((MAXGRAINS) * sizeof(long *)); if (x->t_length == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE GR_LENGTH ARRAY x->gr_length = (long *)sysmem_newptrclear((MAXGRAINS) * sizeof(long *)); if (x->gr_length == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE PAN_LEFT ARRAY x->pan_left = (double *)sysmem_newptrclear((MAXGRAINS) * sizeof(double *)); if (x->pan_left == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE PAN_RIGHT ARRAY x->pan_right = (double *)sysmem_newptrclear((MAXGRAINS) * sizeof(double *)); if (x->pan_right == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE GAIN ARRAY x->gain = (double *)sysmem_newptrclear((MAXGRAINS) * sizeof(double *)); if (x->gain == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } /************************************************************************************************************************/ // INITIALIZE VALUES x->startmin_float = 0.0; // initialize float inlet value for current start min value x->startmax_float = 0.0; // initialize float inlet value for current start max value x->lengthmin_float = 150; // initialize float inlet value for min grain length x->lengthmax_float = 150; // initialize float inlet value for max grain length x->pitchmin_float = 1.0; // initialize inlet value for min pitch x->pitchmax_float = 1.0; // initialize inlet value for min pitch x->panmin_float = 0.0; // initialize value for min pan x->panmax_float = 0.0; // initialize value for max pan x->gainmin_float = 1.0; // initialize value for min gain x->gainmax_float = 1.0; // initialize value for max gain x->tr_prev = 0.0; // initialize value for previous trigger sample x->grains_count = 0; // initialize the grains count value x->grains_limit_old = 0; // initialize value for the routine when grains limit was modified x->limit_modified = 0; // initialize channel change flag x->buffer_modified = 0; // initialized buffer modified flag /************************************************************************************************************************/ // BUFFER REFERENCES x->buffer = buffer_ref_new((t_object *)x, x->buffer_name); // write the buffer reference into the object structure x->w_buffer = buffer_ref_new((t_object *)x, x->window_name); // write the window buffer reference into the object structure return x; }
void *cmbuffercloud_new(t_symbol *s, long argc, t_atom *argv) { t_cmbuffercloud *x = (t_cmbuffercloud *)object_alloc(cmbuffercloud_class); // create the object and allocate required memory dsp_setup((t_pxobject *)x, 11); // create 11 inlets if (argc < ARGUMENTS) { object_error((t_object *)x, "%d arguments required (sample buffer / window type / max. voices)", ARGUMENTS); return NULL; } x->buffer_name = atom_getsymarg(0, argc, argv); // get user supplied argument for sample buffer x->window_name = atom_getsymarg(1, argc, argv); // get user supplied argument for window buffer x->grains_limit = atom_getintarg(2, argc, argv); // get user supplied argument for maximum grains // HANDLE ATTRIBUTES object_attr_setlong(x, gensym("stereo"), 0); // initialize stereo attribute object_attr_setlong(x, gensym("w_interp"), 0); // initialize window interpolation attribute object_attr_setlong(x, gensym("s_interp"), 1); // initialize window interpolation attribute object_attr_setlong(x, gensym("zero"), 0); // initialize zero crossing attribute attr_args_process(x, argc, argv); // get attribute values if supplied as argument // CHECK IF USER SUPPLIED MAXIMUM GRAINS IS IN THE LEGAL RANGE (1 - MAXGRAINS) if (x->grains_limit < 1 || x->grains_limit > MAXGRAINS) { object_error((t_object *)x, "maximum grains allowed is %d", MAXGRAINS); return NULL; } // CREATE OUTLETS (OUTLETS ARE CREATED FROM RIGHT TO LEFT) x->grains_count_out = intout((t_object *)x); // create outlet for number of currently playing grains outlet_new((t_object *)x, "signal"); // right signal outlet outlet_new((t_object *)x, "signal"); // left signal outlet // GET SYSTEM SAMPLE RATE x->m_sr = sys_getsr() * 0.001; // get the current sample rate and write it into the object structure /************************************************************************************************************************/ // ALLOCATE MEMORY FOR THE BUSY ARRAY x->busy = (short *)sysmem_newptrclear((MAXGRAINS) * sizeof(short)); if (x->busy == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE GRAINPOS ARRAY x->grainpos = (long *)sysmem_newptrclear((MAXGRAINS) * sizeof(long)); if (x->grainpos == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE START ARRAY x->start = (long *)sysmem_newptrclear((MAXGRAINS) * sizeof(long)); if (x->start == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE smp_length ARRAY x->smp_length = (long *)sysmem_newptrclear((MAXGRAINS) * sizeof(long)); if (x->smp_length == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE pitch_length ARRAY x->pitch_length = (long *)sysmem_newptrclear((MAXGRAINS) * sizeof(long)); if (x->pitch_length == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE PAN_LEFT ARRAY x->pan_left = (double *)sysmem_newptrclear((MAXGRAINS) * sizeof(double)); if (x->pan_left == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE PAN_RIGHT ARRAY x->pan_right = (double *)sysmem_newptrclear((MAXGRAINS) * sizeof(double)); if (x->pan_right == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE GAIN ARRAY x->gain = (double *)sysmem_newptrclear((MAXGRAINS) * sizeof(double)); if (x->gain == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE OBJET FLOAT_INLETS ARRAY x->object_inlets = (double *)sysmem_newptrclear((FLOAT_INLETS) * sizeof(double)); if (x->object_inlets == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE GRAIN PARAMETERS ARRAY x->grain_params = (double *)sysmem_newptrclear((FLOAT_INLETS) * sizeof(double)); if (x->grain_params == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE GRAIN PARAMETERS ARRAY x->randomized = (double *)sysmem_newptrclear((FLOAT_INLETS / 2) * sizeof(double)); if (x->randomized == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } // ALLOCATE MEMORY FOR THE TEST VALUES ARRAY x->testvalues = (double *)sysmem_newptrclear((FLOAT_INLETS) * sizeof(double)); if (x->testvalues == NULL) { object_error((t_object *)x, "out of memory"); return NULL; } /************************************************************************************************************************/ // INITIALIZE VALUES x->object_inlets[0] = 0.0; // initialize float inlet value for current start min value x->object_inlets[1] = 0.0; // initialize float inlet value for current start max value x->object_inlets[2] = 150; // initialize float inlet value for min grain length x->object_inlets[3] = 150; // initialize float inlet value for max grain length x->object_inlets[4] = 1.0; // initialize inlet value for min pitch x->object_inlets[5] = 1.0; // initialize inlet value for min pitch x->object_inlets[6] = 0.0; // initialize value for min pan x->object_inlets[7] = 0.0; // initialize value for max pan x->object_inlets[8] = 1.0; // initialize value for min gain x->object_inlets[9] = 1.0; // initialize value for max gain x->tr_prev = 0.0; // initialize value for previous trigger sample x->grains_count = 0; // initialize the grains count value x->grains_limit_old = 0; // initialize value for the routine when grains limit was modified x->limit_modified = 0; // initialize channel change flag x->buffer_modified = 0; // initialized buffer modified flag // initialize the testvalues which are not dependent on sampleRate x->testvalues[0] = 0.0; // dummy MIN_START x->testvalues[1] = 0.0; // dummy MAX_START x->testvalues[4] = MIN_PITCH; x->testvalues[5] = MAX_PITCH; x->testvalues[6] = MIN_PAN; x->testvalues[7] = MAX_PAN; x->testvalues[8] = MIN_GAIN; x->testvalues[9] = MAX_GAIN; // calculate constants for panning function x->piovr2 = 4.0 * atan(1.0) * 0.5; x->root2ovr2 = sqrt(2.0) * 0.5; x->bang_trigger = 0; /************************************************************************************************************************/ // BUFFER REFERENCES x->buffer = buffer_ref_new((t_object *)x, x->buffer_name); // write the buffer reference into the object structure x->w_buffer = buffer_ref_new((t_object *)x, x->window_name); // write the window buffer reference into the object structure return x; }
void *env_tilde_new(t_symbol *s, long argc, t_atom *argv) { t_sigenv *x = (t_sigenv *)object_alloc(env_tilde_class); float npoints; float period; int i, isPow2; //s=s; if (x) { dsp_setup((t_pxobject *)x, 1); // MSP inlets: arg is # of inlets and is REQUIRED! // use 0 if you don't need inlets //outlet_new(x, "signal"); // signal outlet (note "signal" rather than NULL) //x->offset = 0.0; if(argc > 1) { npoints = atom_getfloat(argv); // should perform a check for >64 && power of two isPow2 = (int)npoints && !( ((int)npoints-1) & (int)npoints ); if(!isPow2) { error("requested window size is not a power of 2. default value of 1024 used instead."); npoints = 1024; } else x->x_npoints=(int)npoints; period = atom_getfloat(argv+1); isPow2 = (int)period && !( ((int)period-1) & (int)period ); if(!isPow2) { error("requested window size is not a power of 2. default value of 512 used instead."); period = npoints/2; } else x->x_period=(int)period; } else if(argc > 0) { npoints = atom_getfloat(argv); isPow2 = (int)npoints && !( ((int)npoints-1) & (int)npoints ); if(!isPow2) { error("requested window size is not a power of 2. default value of 1024 used instead."); x->x_npoints = 1024; } else x->x_npoints=(int)npoints; period = x->x_npoints/2; } else { x->x_npoints = 1024; x->x_period = 512; } if (x->x_period < x->x_npoints / MAXOVERLAP + 1) x->x_period = x->x_npoints / MAXOVERLAP + 1; if (!(x->x_buf= sysmem_newptrclear(sizeof(t_sample) * (x->x_npoints + INITVSTAKEN)))) { error("env: couldn't allocate buffer"); return (0); } x->x_phase = 0; for (i = 0; i < MAXOVERLAP; i++) x->x_sumbuf[i] = 0; for (i = 0; i < x->x_npoints; i++) x->x_buf[i] = (1. - cos((2 * 3.14159 * i) / x->x_npoints))/x->x_npoints; for (; i < x->x_npoints+INITVSTAKEN; i++) x->x_buf[i] = 0; x->x_clock = clock_new((t_object *)x, (method)env_tilde_tick); x->x_outlet = floatout(x); x->x_f = 0; x->x_allocforvs = INITVSTAKEN; } return (x); }