oscil~/Source/oscil~common.c
void *oscil_common_new(t_oscil *x, short argc, t_atom *argv)
{
#ifdef TARGET_IS_MAX
	/* Create signal inlets */
	dsp_setup((t_pxobject *)x, NUM_INLETS);
	
	/* Create signal outlets */
	outlet_new((t_object *)x, "signal");
	
	/* Avoid sharing memory among audio vectors */
	x->obj.z_misc |= Z_NO_INPLACE;
#elif TARGET_IS_PD
	/* Create signal inlets */
	inlet_new(&x->obj, &x->obj.ob_pd, gensym("signal"), gensym("signal"));
	
	/* Create signal outlets */
	outlet_new(&x->obj, gensym("signal"));
#endif
    
    /* Parse passed arguments */
    parse_float_arg(&x->frequency, MINIMUM_FREQUENCY, DEFAULT_FREQUENCY, MAXIMUM_FREQUENCY, A_FREQUENCY, argc, argv);
    parse_int_arg(&x->table_size, MINIMUM_TABLE_SIZE, DEFAULT_TABLE_SIZE, MAXIMUM_TABLE_SIZE, A_TABLE_SIZE, argc, argv);
    parse_symbol_arg(&x->waveform, gensym(DEFAULT_WAVEFORM), A_WAVEFORM, argc, argv);
    parse_int_arg(&x->harmonics, MINIMUM_HARMONICS, DEFAULT_HARMONICS, MAXIMUM_HARMONICS, A_HARMONICS, argc, argv);
    
	/* Initialize state variables */
    x->wavetable_bytes = x->table_size * sizeof(float);
    x->wavetable = (float *)new_memory(x->wavetable_bytes);
    x->wavetable_old = (float *)new_memory(x->wavetable_bytes);
    
    x->amplitudes_bytes = MAXIMUM_HARMONICS * sizeof(float);
    x->amplitudes = (float *)new_memory(x->amplitudes_bytes);
    
    x->fs = sys_getsr();
    
    x->phase = 0;
    x->increment = (float)x->table_size / x->fs;
    x->dirty = 0;
    
    x->crossfade_type = POWER_CROSSFADE;
    x->crossfade_time = DEFAULT_CROSSFADE;
    x->crossfade_samples = x->crossfade_time * x->fs / 1000.0;
    x->crossfade_countdown = 0;
    x->crossfade_in_progress = 0;
    x->just_turned_on = 1;
    
    x->twopi = 8.0 * atan(1.0);
    x->piOtwo = 2.0 * atan(1.0);
    
    /* Build wavetable */
    if (x->waveform == gensym("sine")) {
        x->waveform = gensym("");
        oscil_build_sine(x);
    } else if (x->waveform == gensym("triangle")) {
        x->waveform = gensym("");
        oscil_build_triangle(x);
    } else if (x->waveform == gensym("sawtooth")) {
        x->waveform = gensym("");
        oscil_build_sawtooth(x);
    } else if (x->waveform == gensym("square")) {
        x->waveform = gensym("");
        oscil_build_square(x);
    } else if (x->waveform == gensym("pulse")) {
        x->waveform = gensym("");
        oscil_build_pulse(x);
    } else {
        x->waveform = gensym("");
        oscil_build_sine(x);
        
        error("oscil~ • Invalid argument: Waveform set to %s", x->waveform->s_name);
    }
    
	/* Print message to Max window */
	post("oscil~ • Object was created");
	
	/* Return a pointer to the new object */
	return x;
}
/* The common 'new instance' routine ******************************************/
The common 'new instance' routine
The common ' new instance ' routine
void *oscil_common_new(t_oscil *x, short argc, t_atom *argv)
{
#ifdef TARGET_IS_MAX
	dsp_setup((t_pxobject *)x, NUM_INLETS);
	outlet_new((t_object *)x, "signal");
	x->obj.z_misc |= Z_NO_INPLACE;
#elif TARGET_IS_PD
	inlet_new(&x->obj, &x->obj.ob_pd, gensym("signal"), gensym("signal"));
	outlet_new(&x->obj, gensym("signal"));
#endif
    parse_float_arg(&x->frequency, MINIMUM_FREQUENCY, DEFAULT_FREQUENCY, MAXIMUM_FREQUENCY, A_FREQUENCY, argc, argv);
    parse_int_arg(&x->table_size, MINIMUM_TABLE_SIZE, DEFAULT_TABLE_SIZE, MAXIMUM_TABLE_SIZE, A_TABLE_SIZE, argc, argv);
    parse_symbol_arg(&x->waveform, gensym(DEFAULT_WAVEFORM), A_WAVEFORM, argc, argv);
    parse_int_arg(&x->harmonics, MINIMUM_HARMONICS, DEFAULT_HARMONICS, MAXIMUM_HARMONICS, A_HARMONICS, argc, argv);
    x->wavetable_bytes = x->table_size * sizeof(float);
    x->wavetable = (float *)new_memory(x->wavetable_bytes);
    x->wavetable_old = (float *)new_memory(x->wavetable_bytes);
    x->amplitudes_bytes = MAXIMUM_HARMONICS * sizeof(float);
    x->amplitudes = (float *)new_memory(x->amplitudes_bytes);
    x->fs = sys_getsr();
    x->phase = 0;
    x->increment = (float)x->table_size / x->fs;
    x->dirty = 0;
    x->crossfade_type = POWER_CROSSFADE;
    x->crossfade_time = DEFAULT_CROSSFADE;
    x->crossfade_samples = x->crossfade_time * x->fs / 1000.0;
    x->crossfade_countdown = 0;
    x->crossfade_in_progress = 0;
    x->just_turned_on = 1;
    x->twopi = 8.0 * atan(1.0);
    x->piOtwo = 2.0 * atan(1.0);
    if (x->waveform == gensym("sine")) {
        x->waveform = gensym("");
        oscil_build_sine(x);
    } else if (x->waveform == gensym("triangle")) {
        x->waveform = gensym("");
        oscil_build_triangle(x);
    } else if (x->waveform == gensym("sawtooth")) {
        x->waveform = gensym("");
        oscil_build_sawtooth(x);
    } else if (x->waveform == gensym("square")) {
        x->waveform = gensym("");
        oscil_build_square(x);
    } else if (x->waveform == gensym("pulse")) {
        x->waveform = gensym("");
        oscil_build_pulse(x);
    } else {
        x->waveform = gensym("");
        oscil_build_sine(x);
        error("oscil~ • Invalid argument: Waveform set to %s", x->waveform->s_name);
    }
	post("oscil~ • Object was created");
	return x;
}
void * oscil_common_new ( t_oscil * x , short argc , t_atom * argv ) { #ifdef TARGET_IS_MAX dsp_setup ( ( t_pxobject * ) x , NUM_INLETS ) ; outlet_new ( ( t_object * ) x , " " ) ; x -> obj . z_misc |= Z_NO_INPLACE ; #elif TARGET_IS_PD inlet_new ( & x -> obj , & x -> obj . ob_pd , gensym ( " " ) , gensym ( " " ) ) ; outlet_new ( & x -> obj , gensym ( " " ) ) ; #endif parse_float_arg ( & x -> frequency , MINIMUM_FREQUENCY , DEFAULT_FREQUENCY , MAXIMUM_FREQUENCY , A_FREQUENCY , argc , argv ) ; parse_int_arg ( & x -> table_size , MINIMUM_TABLE_SIZE , DEFAULT_TABLE_SIZE , MAXIMUM_TABLE_SIZE , A_TABLE_SIZE , argc , argv ) ; parse_symbol_arg ( & x -> waveform , gensym ( DEFAULT_WAVEFORM ) , A_WAVEFORM , argc , argv ) ; parse_int_arg ( & x -> harmonics , MINIMUM_HARMONICS , DEFAULT_HARMONICS , MAXIMUM_HARMONICS , A_HARMONICS , argc , argv ) ; x -> wavetable_bytes = x -> table_size * sizeof ( float ) ; x -> wavetable = ( float * ) new_memory ( x -> wavetable_bytes ) ; x -> wavetable_old = ( float * ) new_memory ( x -> wavetable_bytes ) ; x -> amplitudes_bytes = MAXIMUM_HARMONICS * sizeof ( float ) ; x -> amplitudes = ( float * ) new_memory ( x -> amplitudes_bytes ) ; x -> fs = sys_getsr ( ) ; x -> phase = 0 ; x -> increment = ( float ) x -> table_size / x -> fs ; x -> dirty = 0 ; x -> crossfade_type = POWER_CROSSFADE ; x -> crossfade_time = DEFAULT_CROSSFADE ; x -> crossfade_samples = x -> crossfade_time * x -> fs / 1000.0 ; x -> crossfade_countdown = 0 ; x -> crossfade_in_progress = 0 ; x -> just_turned_on = 1 ; x -> twopi = 8.0 * atan ( 1.0 ) ; x -> piOtwo = 2.0 * atan ( 1.0 ) ; if ( x -> waveform == gensym ( " " ) ) { x -> waveform = gensym ( " " ) ; oscil_build_sine ( x ) ; } else if ( x -> waveform == gensym ( " " ) ) { x -> waveform = gensym ( " " ) ; oscil_build_triangle ( x ) ; } else if ( x -> waveform == gensym ( " " ) ) { x -> waveform = gensym ( " " ) ; oscil_build_sawtooth ( x ) ; } else if ( x -> waveform == gensym ( " " ) ) { x -> waveform = gensym ( " " ) ; oscil_build_square ( x ) ; } else if ( x -> waveform == gensym ( " " ) ) { x -> waveform = gensym ( " " ) ; oscil_build_pulse ( x ) ; } else { x -> waveform = gensym ( " " ) ; oscil_build_sine ( x ) ; error ( " x > wa veform-> s_ name); } post ( " ; return x ; }
The common 'new instance' routine
The common ' new instance ' routine
/* Create signal inlets */ /* Create signal outlets */ /* Avoid sharing memory among audio vectors */ /* Create signal inlets */ /* Create signal outlets */ /* Parse passed arguments */ /* Initialize state variables */ /* Build wavetable */ /* Print message to Max window */ /* Return a pointer to the new object */