コード例 #1
0
ファイル: vdb~.c プロジェクト: ericlyon/LyonPotpourri-MaxMSP
void *vdb_new(t_symbol *s, int argc, t_atom *argv)
{
int i;
int user_chans;
t_vdb *x;

	if(argc < 2){
		error("%s: you must provide a valid buffer name and channel count",OBJECT_NAME);
		return (void *)NULL;
	}	
	
	x = (t_vdb *)newobject(vdb_class);
	x->sr = sys_getsr();
	
	if(!x->sr){
		error("zero sampling rate - set to 44100");
		x->sr = 44100;
	}
	// DSP CONFIG


	// SET DEFAULTS
	x->maxdelay = 50.0; // milliseconds
	x->feedback = 0.5;
	x->delay_time  = 0.0;

// args: name channels [max delay, initial delay, feedback, interpolation_flag]

    x->buffername = atom_getsymarg(0,argc,argv);
	user_chans = atom_getfloatarg(1,argc,argv);
	x->maxdelay = atom_getfloatarg(2,argc,argv);
	x->delay_time = atom_getfloatarg(3,argc,argv);
	x->feedback = atom_getfloatarg(4,argc,argv);
	x->interpolate = atom_getfloatarg(5,argc,argv);   
	x->b_nchans = user_chans;
/*
	if(! x->b_nchans){
		error("did not find channels from buffer");
		if(user_chans > 0)
			
	} */
	/* need data checking here */
	x->inlet_count = x->b_nchans + 2;
	x->outlet_count = x->b_nchans;
	x->delay_inlet = x->b_nchans;
	x->feedback_inlet = x->delay_inlet + 1;

	dsp_setup((t_pxobject *)x,x->inlet_count);
	for(i = 0; i < x->outlet_count; i++){
		outlet_new((t_object *)x, "signal");
	}
    x->x_obj.z_misc |= Z_NO_INPLACE;
    	

		
	vdb_init(x,0);
	return (x);
}
コード例 #2
0
ファイル: rtlsdr~.c プロジェクト: gpmed/pd-rtlsdr
// gain message - sets the radio gain in dB (Max and Pd)
//
// format: gain <gain in db> [now]
// (note you can also set to "auto"
//
// the optional 'now' argument, if equal to 1,  sets gain right now, if radio is running.
// if argument is not passed or equals zero (default) gain setting will be deferred until the radio
// gets reset.
//
void rtlsdr_gain (t_rtlsdr *x, t_symbol *mesg, short argc, t_atom *argv ) {
    
    // char msg[100];
    int now = 0;      // default is to defer setting until reset
    t_symbol *sym;   // special param for auto gain setting
    
    
    if(argc < 1) {
        post("freq: <gain in db> [now]", 0);
        return;
    }
    
    
    //
    if(argc > 0) {
        // first check for 'auto' gain
        // Max and Pd have different names for function to retrive symbols...
#ifdef PDVERSION
        sym = atom_getsymbolarg(0, argc,argv);
#else
        sym = atom_getsymarg(0, argc,argv);
#endif
        if(strcmp(sym->s_name,"auto") == 0) {
            x->x_gain_db10 = AUTO_GAIN;
        }
        else {  // not auto - so parse as float val
            x->x_gain_db10 = (int) (atom_getfloatarg(0, argc,argv) * 10);
           
        }
    new_gain = x->x_gain_db10;
    // sprintf(msg, "freq: setting freq to: %f", x->x_freq_hz);
    // post(msg, 0);
    }
    if(argc > 1 ) {
        now = (int) atom_getfloatarg(1, argc,argv);
    }
    
    // tz - note all gain settings deferred right now - during testing
    
    if(now == 0) {
		// post("gain: deferred");
        return;         // don't set now
    }
    
	// post("gain: immediate");
	
    // note, if radio is off, nothing happens until its turned on
    
    if(x->x_radio_is_running == 1) {
        need_to_set_gain = 1;
    }
    
    
}
コード例 #3
0
ファイル: vd~.c プロジェクト: ericlyon/LyonPotpourri-MaxMSP
void vd_copy_to_buffer(t_vd *x, t_symbol *msg, short argc, t_atom *argv)
{
	t_symbol *destname;
	
	float *b_samples = x->delay_line;
	long b_nchans = 1;	
	long b_frames = x->len + 2;
	
	float *b_dest_samples;
	long b_dest_nchans;	
	long b_dest_frames;
	
	long b_copy_frames;
	
	destname = atom_getsymarg(0,argc,argv);
	
	if(! vd_setdestbuf(x, destname)){
		post("could not find buffer");
		return;
	}
	b_dest_samples = x->destbuf->b_samples;
	b_dest_nchans = x->destbuf->b_nchans;
	b_dest_frames = x->destbuf->b_frames;
	b_copy_frames = b_frames;
	
	
	if(b_nchans != 1){
		error("%s: buffer must be mono",OBJECT_NAME);
		return;
	}
	if(b_dest_frames < b_copy_frames ){
		b_copy_frames = b_dest_frames;
		//		post("%s: destination buffer %s is too small, copy region truncated",OBJECT_NAME,destname->s_name);
	}
 	// post("cleaning out %d frames",b_dest_frames);
	/* first clean out destination */
	memset((char *)b_dest_samples, 0, b_dest_frames * 1 * sizeof(float));
	
	// post("copying %d frames",b_frames);
	
	/* now copy segment */
	memcpy(b_dest_samples, b_samples, b_copy_frames  * 1 * sizeof(float) );
	
}
コード例 #4
0
ファイル: simpwave~.c プロジェクト: pukulsesuatu/max6-sdk
void *simpwave_new(t_symbol *s,  long argc, t_atom *argv)
{
	t_simpwave *x = (t_simpwave *)object_alloc(s_simpwave_class);
	t_symbol *buf=0;
	float start=0., end=0.; 
	dsp_setup((t_pxobject *)x,3);
	// x->w_phase = 0;
	buf = atom_getsymarg(0,argc,argv);
	start = atom_getfloatarg(1,argc,argv);
	end = atom_getfloatarg(2,argc,argv);
	
	x->w_name = buf;
	x->w_msr = sys_getsr() * 0.001;
	x->w_start = start;
	x->w_end = end;
	x->w_begin = start * x->w_msr;
	x->w_len = (end - start) * x->w_msr;
	x->w_buf = 0;
	x->w_nchans = 1;
	outlet_new((t_object *)x, "signal");		// audio outlet
	return (x);
}
コード例 #5
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;
}
コード例 #6
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;
}