Exemplo n.º 1
0
/********************************************************************************
void grainstream_setsnd(t_index *x, t_symbol *s)

inputs:			x		-- pointer to this object
				s		-- name of buffer to link
description:	links buffer holding the grain sound source 
returns:		nothing
********************************************************************************/
void grainstream_setsnd(t_grainstream *x, t_symbol *s)
{
    t_buffer_ref *b = buffer_ref_new((t_object*)x, s);
    
    if (buffer_ref_exists(b)) {
        t_buffer_obj	*b_object = buffer_ref_getobject(b);
        
        if (buffer_getchannelcount(b_object) != 1) {
			error("%s: buffer~ > %s < must be mono", OBJECT_NAME, s->s_name);
			x->next_snd_buf_ptr = NULL;		//added 2002.07.15
		} else {
			if (x->snd_buf_ptr == NULL) { // if first buffer make current buffer
				x->snd_sym = s;
				x->snd_buf_ptr = b;
				//x->snd_last_out = 0.0;	//removed 2005.02.03
				
				#ifdef DEBUG
					post("%s: current sound set to buffer~ > %s <", OBJECT_NAME, s->s_name);
				#endif /* DEBUG */
			} else { // else defer to next buffer
				x->snd_sym = s;
				x->next_snd_buf_ptr = b;
				//x->snd_buf_length = b->b_frames;	//removed 2002.07.11
				//x->snd_last_out = 0.0;		//removed 2002.07.24
				
				#ifdef DEBUG
					post("%s: next sound set to buffer~ > %s <", OBJECT_NAME, s->s_name);
				#endif /* DEBUG */
			}
		}
	} else {
		error("%s: no buffer~ * %s * found", OBJECT_NAME, s->s_name);
		x->next_snd_buf_ptr = NULL;
	}
}
Exemplo n.º 2
0
void index_set(t_index *x, t_symbol *s)
{
	if (!x->l_buffer_reference)
		x->l_buffer_reference = buffer_ref_new((t_object *)x, s);
	else
		buffer_ref_set(x->l_buffer_reference, s);
}
Exemplo n.º 3
0
void pokef_set(t_pokef *x, t_symbol *s)
{
	if (!x->l_buffer)
		x->l_buffer = buffer_ref_new((t_object *)x, s);
	else
		buffer_ref_set(x->l_buffer, s);
}
Exemplo n.º 4
0
void buff_get_obj(void *x, t_buff_info *buff, t_symbol *buff_sym)
{
  // Test that the symbol for the buffer name is not empty
  if (buff_sym == gensym("")) {
    buff->has_obj = false;
    buff->has_file = false;
    return;  }
  else { buff->sym = buff_sym; }
  
  // If the buffer reference already exists, change it
  if (buff->ref) { buffer_ref_set(buff->ref, buff->sym); }
  // Otherwise create a new buffer reference
  else { buff->ref = buffer_ref_new((t_object*)x, buff->sym); }

  // Test that the buffer reference was successfully changed or created
  if (buff->ref == NULL) {
    buff->has_obj = false;
    buff->has_file = false;
    return; }
  
  //==== Buffer objects ====
  
  // Create a new buffer object from the buffer reference
  buff->obj = buffer_ref_getobject(buff->ref);

  // Test that the buffer object was succesfully retrieved
  if (buff->obj == NULL) {
    buff->has_obj = false;
    buff->has_file = false;
    return; }

  else {
    buff->has_obj = true;
    return; }
}
Exemplo n.º 5
0
void buffi_doset(t_buffi *x)
{
    if (!x->src1_buffer_ref)
        x->src1_buffer_ref = buffer_ref_new((t_object *)x, x->src1);
    else
        buffer_ref_set(x->src1_buffer_ref, x->src1);

    if (!x->src2_buffer_ref)
        x->src2_buffer_ref = buffer_ref_new((t_object *)x, x->src2);
    else
        buffer_ref_set(x->src2_buffer_ref, x->src2);
    
    if (!x->dest_buffer_ref)
        x->dest_buffer_ref = buffer_ref_new((t_object *)x, x->dest);
    else
        buffer_ref_set(x->dest_buffer_ref, x->dest);
}
void *multigrain_new(t_symbol *msg, short argc, t_atom *argv)
{
    t_multigrain *x = (t_multigrain *)object_alloc(multigrain_class);
    float f = 2;
    int i;
    dsp_setup((t_pxobject *)x,1);

    
    srand(time(0)); //need "seed" message
    
    x->pitchscale = (float *) t_getbytes(MAXSCALE * sizeof(float));
    x->grains = (t_grain *) t_getbytes(MAXGRAINS * sizeof(t_grain));
    
    
    // default names
    x->wavename = gensym("waveform");
    x->windowname = gensym("window");
    
    if( argc < 2){
        error("Must enter wave buffer, window buffer, and output channel count");
        return NULL;
    }
    if(argc > 0)
        atom_arg_getsym(&x->wavename,0,argc,argv);
    if(argc > 1)
        atom_arg_getsym(&x->windowname,1,argc,argv);
    if(argc > 2)
        atom_arg_getfloat(&f,2,argc,argv);
    
    x->output_channels = (long) f;
    for(i = 0; i < x->output_channels; i++){
        outlet_new((t_pxobject *)x, "signal");
    }
    x->wavebuf = buffer_ref_new((t_object*)x, x->wavename);
    x->windowbuf = buffer_ref_new((t_object*)x, x->windowname);
    
    
    multigrain_init(x,0);
    return x;
}
Exemplo n.º 7
0
void *buffer_proxy_new(t_symbol *s)
{
    
    t_buffer_proxy *x = NULL;

    if((x = (t_buffer_proxy *)object_alloc(buffer_proxy_class)))
    {
        x->name = s;
        x->ref = buffer_ref_new((t_object *)x, x->name);
        x->buffer_modified = true;
    }

    return x;
}
Exemplo n.º 8
0
//external buffer stuff
void munger_setbuffer(t_munger *x, t_symbol *s)
{
	if (!x->l_buffer)
		x->l_buffer = buffer_ref_new((t_object *)x, s);
	else
		buffer_ref_set(x->l_buffer, s);
		
	if (buffer_ref_exists(x->l_buffer)) {
		x->externalBuffer = 1;
		x->l_chan = 0;
	}
	else {
		x->externalBuffer = 0;
	}
}
Exemplo n.º 9
0
void *breakgen_new(t_symbol *s, long argc, t_atom *argv)
{
	t_breakgen *x = NULL;
    
	if ((x = (t_breakgen *)object_alloc(breakgen_class))) {
		x->name = gensym("");
		if (argc && argv) {
			x->name = atom_getsym(argv);
		}
		if (!x->name || x->name == gensym(""))
			x->name = symbol_unique();
		
		atom_setlong(&x->val, 0);
		x->out = outlet_new(x, NULL);
        
        x->constsig = 0;
        x->constval = 1.0;
        
        x->rando_gen = NULL;
        x->rando_gen = new_rando();
        if(x->rando_gen == NULL){
            post("no memory for random generator\n");
        }
        x->rando_func = no_rando;
        
        srand(time(NULL));
        
        x->tick = sinetick;
        x->sr = 10000.00;
        x->freq = 100.00;
        x->osc = NULL;
        x->osc = new_oscil(x->sr);
        if(x->osc == NULL){
            post("no memory for oscillator\n");
        }
        
        x->buffy = buffer_ref_new((t_object *)x, gensym("buffy"));
        if (buffer_ref_exists(x->buffy) != 0) {
            post("buf ref exists");
        } else {
            post("buf ref doesn't exist");
        };
	}
	return (x);
}
Exemplo n.º 10
0
void breakgen_writebuf(t_breakgen *x, t_symbol *s, long argc, t_atom *argv)
{
    t_atom *ap;
    t_atom_long framecount;
    long num_frames;
    t_buffer_obj *buf;  // need to free this
    float *bufframe;
    t_max_err buferror;
    int i;
    
    ap = argv;
    
    if (atom_gettype(ap) == A_SYM) {
        x->buffy = buffer_ref_new((t_object *)x, atom_getsym(ap));
        if (buffer_ref_exists(x->buffy) != 0) {
            buf = buffer_ref_getobject(x->buffy);
            framecount = buffer_getframecount(buf);
            ap++;
            if (atom_gettype(ap) == A_LONG) {
                num_frames = atom_getlong(ap);
                if (num_frames < framecount) framecount = num_frames;
                bufframe = buffer_locksamples(buf);
                if (bufframe) {
                    for (i = 0; i < framecount; i++) {
                        *bufframe = output_val(x) - 1.0;
                        bufframe++;
                    }
                }
                buferror = buffer_setdirty(buf);
                buffer_unlocksamples(buf);
            }
        } else {
            post("buffer doesn't exist");
        };
    }
}
Exemplo n.º 11
0
void buffi_autofunc(t_buffi *x, t_floatarg minval, t_floatarg maxval, t_symbol *buffername)
{
    int minpoints, maxpoints, segpoints, i;
    int pointcount = 0;
    double target, lastval;
    double m1, m2;
    t_buffer_ref *tablebuf_ref;
    t_buffer_obj *dbuf;
    long b_nchans;
    long b_frames;
    float *b_samples;
    
    /////

    tablebuf_ref = buffer_ref_new((t_object*)x, buffername);

    dbuf = buffer_ref_getobject(tablebuf_ref);
    if(dbuf == NULL){
        object_post((t_object*)x,"%s: nonexistent buffer ( %s )",
                    OBJECT_NAME, buffername->s_name);
        return;
    }
    b_nchans = buffer_getchannelcount(dbuf);
    b_frames = buffer_getframecount(dbuf);
    if(b_nchans != 1){
        post("%s: table must be mono",OBJECT_NAME);
        return;
    }
    x->warpfunc = (float *)sysmem_newptr(b_frames * sizeof(float));
    
    minpoints = 0.05 * (float) b_frames;
    maxpoints = 0.25 * (float) b_frames;
    if( minval > 1000.0 || minval < .001 ){
        minval = 0.5;
    }
    if( maxval < 0.01 || maxval > 1000.0 ){
        minval = 2.0;
    }
    
    lastval = buffi_randf(minval, maxval);
    // post("automate: min %d max %d",minpoints, maxpoints);
    while( pointcount < b_frames ){
        target = buffi_randf(minval, maxval);
        segpoints = minpoints + (rand() % (maxpoints-minpoints));
        if( pointcount + segpoints > b_frames ){
            segpoints = b_frames - pointcount;
        }
        for( i = 0; i < segpoints; i++ ){
            m2 = (float)i / (float) segpoints ;
            m1 = 1.0 - m2;
            x->warpfunc[ pointcount + i ] = m1 * lastval + m2 * target;
        }
        lastval = target;
        pointcount += segpoints;
    }
    // buffer stuffer
    b_samples = buffer_locksamples(dbuf);
    for(i = 0; i < b_frames; i++){
        b_samples[i] = x->warpfunc[i];
    }
    buffer_unlocksamples(dbuf);
    sysmem_freeptr( (void *) x->warpfunc );
    object_method(dbuf, gensym("dirty"));
}
Exemplo n.º 12
0
void breakgen_setter(t_breakgen *x, t_symbol *s, long argc, t_atom *argv)
{
    t_atom *ap;
    int wavetype;
    
    ap = argv;
    
    if (atom_gettype(ap) == A_SYM) {
        if (atom_getsym(ap) == gensym("freq")) {
            ap++;
            if (atom_gettype(ap) == A_FLOAT) {
                if (atom_getfloat(ap) > 0.0) {
                    x->freq = atom_getfloat(ap);
                    post("freq set to %f", atom_getfloat(ap));
                } else {
                    post("frequency must be positive");
                }
            } else {
                post("set sr argument of incorrect type");
            }
        } else if (atom_getsym(ap) == gensym("constval")) {
            ap++;
            if (atom_gettype(ap) == A_FLOAT) {
                post("const val set to %f", atom_getfloat(ap));
                x->constval = atom_getfloat(ap);
            } else {
                post("set const val arg of incorrect type");
            }
        } else if (atom_getsym(ap) == gensym("wavetype")) {
            ap++;
            if (atom_gettype(ap) == A_LONG) {
                wavetype = atom_getlong(ap);
                if (wavetype < 6) {
                x->constsig = 0;
                    switch (wavetype) {
                        case 0:
                            /* sine */
                            x->tick = sinetick;
                            break;
                        case 1:
                            /* triange */
                            x->tick = tritick;
                            break;
                        case 2:
                            /* square */
                            x->tick = sqtick;
                            break;
                        case 3:
                            /* sawdown */
                            x->tick = sawdtick;
                            break;
                        case 4:
                            /* sawup */
                            x->tick = sawutick;
                            break;
                        case 5:
                            x->constsig = 1;
                            break;
                            
                        default:
                            x->tick = sinetick;
                            break;
                    }
                    post("wavetype set to %i", wavetype);
                } else {
                    post("wavetype must be between 0 and 5");
                }
            } else {
                post("set wavetype argument of incorrect type");
            }
        } else if (atom_getsym(ap) == gensym("random")) {
            ap++;
            if (atom_gettype(ap) == A_LONG) {
                wavetype = atom_getlong(ap);
                if (wavetype < 4) {
                    switch (wavetype) {
                        case 0:
                            /* no random number */
                            x->rando_func = no_rando;
                            break;
                        case 1:
                            /* replace value with random number */
                            x->rando_func = rando_replace;;
                            break;
                        case 2:
                            /* scale random and +/- from val */
                            x->rando_func = rando_multi;
                            break;
                        case 3:
                            /* scale random and +/- from val with interval interp */
                            x->rando_func = rando_interp;
                            break;
                            
                        default:
                            x->rando_func = no_rando;
                            break;
                    }
                    post("random mode set to %i", wavetype);
                } else {
                    post("random mode must be between 0 and 3");
                }
            } else {
                post("set random argument of incorrect type");
            }
        } else if (atom_getsym(ap) == gensym("interval")) {
            ap++;
            if (atom_gettype(ap) == A_LONG) {
                x->rando_gen->interval = atom_getlong(ap);
            } else {
                post("set random interval argument of incorrect type");
            }
        } else if (atom_getsym(ap) == gensym("intensity")) {
            ap++;
            if (atom_gettype(ap) == A_FLOAT) {
                x->rando_gen->intensity = atom_getfloat(ap);
            } else {
                post("set random intensity argument of incorrect type");
            }
        } else if (atom_getsym(ap) == gensym("buffer")) {
            t_symbol *symb;
            ap++;
            if (atom_gettype(ap) == A_SYM) {
                symb = atom_getsym(ap);
                x->buffy = buffer_ref_new((t_object *)x, symb);
                if (buffer_ref_exists(x->buffy) != 0) {
                    object_post((t_object *)x, "\"%s\" buffer referenced", symb->s_name);
                } else {
                    object_post((t_object *)x, "\"%s\" buffer referenced but doesn't exist", symb->s_name);
                };
            } else {
                post("set buffer argument of incorrect type");
            }
        } else if (atom_getsym(ap) == gensym("sr")) {
            ap++;
            if (atom_gettype(ap) == A_FLOAT) {
                if (atom_getfloat(ap) > 0.0) {
                    x->sr = atom_getfloat(ap);
                    free(x->osc);
                    x->osc = new_oscil(x->sr);
                    post("sampling rate set to %f", atom_getfloat(ap));
                } else {
                    post("sampling rate can't be negative");
                }
            } else {
                post("set sr arg of incorrect type");
            }
        }
    }
}
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
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;
}