diff --git a/src/core/ugen_osc.cpp b/src/core/ugen_osc.cpp index ee5908f39..84d7c8fa3 100644 --- a/src/core/ugen_osc.cpp +++ b/src/core/ugen_osc.cpp @@ -136,6 +136,19 @@ DLL_QUERY osc_query( Chuck_DL_Query * QUERY ) doc.c_str() ) ) return FALSE; + // overload constructor (float freq) + func = make_new_mfun( "void", "Phasor", oscx_ctor_1 ); + func->add_arg( "float", "freq" ); + func->doc = "Constructor to initialize a Phasor at specified frequency."; + if( !type_engine_import_mfun( env, func ) ) goto error; + + // overload constructor (float freq, float phase) + func = make_new_mfun( "void", "Phasor", oscx_ctor_2 ); + func->add_arg( "float", "freq" ); + func->add_arg( "float", "phase" ); + func->doc = "Constructor to initialize a Phasor at specified frequency and phase."; + if( !type_engine_import_mfun( env, func ) ) goto error; + // add examples | 1.5.0.0 added if( !type_engine_import_add_ex( env, "basic/phasor.ck" ) ) goto error; @@ -151,6 +164,19 @@ DLL_QUERY osc_query( Chuck_DL_Query * QUERY ) doc.c_str() ) ) return FALSE; + // overload constructor (float freq) + func = make_new_mfun( "void", "SinOsc", oscx_ctor_1 ); + func->add_arg( "float", "freq" ); + func->doc = "Constructor to initialize a SinOsc at specified frequency."; + if( !type_engine_import_mfun( env, func ) ) goto error; + + // overload constructor (float freq, float phase) + func = make_new_mfun( "void", "SinOsc", oscx_ctor_2 ); + func->add_arg( "float", "freq" ); + func->add_arg( "float", "phase" ); + func->doc = "Constructor to initialize a SinOsc at specified frequency and phase."; + if( !type_engine_import_mfun( env, func ) ) goto error; + // add examples | 1.5.0.0 (ge) type_engine_import_add_ex( env, "otf_05.ck" ); type_engine_import_add_ex( env, "otf_06.ck" ); @@ -174,6 +200,19 @@ DLL_QUERY osc_query( Chuck_DL_Query * QUERY ) doc.c_str() ) ) return FALSE; + // overload constructor (float freq) + func = make_new_mfun( "void", "TriOsc", oscx_ctor_1 ); + func->add_arg( "float", "freq" ); + func->doc = "Constructor to initialize a TriOsc at specified frequency."; + if( !type_engine_import_mfun( env, func ) ) goto error; + + // overload constructor (float freq, float phase) + func = make_new_mfun( "void", "TriOsc", oscx_ctor_2 ); + func->add_arg( "float", "freq" ); + func->add_arg( "float", "phase" ); + func->doc = "Constructor to initialize a TriOsc at specified frequency and phase."; + if( !type_engine_import_mfun( env, func ) ) goto error; + func = make_new_mfun( "float", "width", osc_ctrl_width ); func->add_arg( "float", "width" ); func->doc = "set width of triangle wave (ratio of rise time to fall time)."; @@ -200,6 +239,19 @@ DLL_QUERY osc_query( Chuck_DL_Query * QUERY ) doc.c_str() ) ) return FALSE; + // overload constructor (float freq) + func = make_new_mfun( "void", "SawOsc", oscx_ctor_1 ); + func->add_arg( "float", "freq" ); + func->doc = "Constructor to initialize a SawOsc at specified frequency."; + if( !type_engine_import_mfun( env, func ) ) goto error; + + // overload constructor (float freq, float phase) + func = make_new_mfun( "void", "SawOsc", oscx_ctor_2 ); + func->add_arg( "float", "freq" ); + func->add_arg( "float", "phase" ); + func->doc = "Constructor to initialize a SawOsc at specified frequency and phase."; + if( !type_engine_import_mfun( env, func ) ) goto error; + func = make_new_mfun( "float", "width", sawosc_ctrl_width ); func->add_arg( "float", "width" ); func->doc = "whether sawtooth wave is to fall (0) or rise (1)."; @@ -226,6 +278,19 @@ DLL_QUERY osc_query( Chuck_DL_Query * QUERY ) doc.c_str() ) ) return FALSE; + // overload constructor (float freq) + func = make_new_mfun( "void", "PulseOsc", oscx_ctor_1 ); + func->add_arg( "float", "freq" ); + func->doc = "Constructor to initialize a PulseOsc at specified frequency."; + if( !type_engine_import_mfun( env, func ) ) goto error; + + // overload constructor (float freq, float phase) + func = make_new_mfun( "void", "PulseOsc", oscx_ctor_2 ); + func->add_arg( "float", "freq" ); + func->add_arg( "float", "phase" ); + func->doc = "Constructor to initialize a PulseOsc at specified frequency and phase."; + if( !type_engine_import_mfun( env, func ) ) goto error; + func = make_new_mfun( "float", "width", osc_ctrl_width ); func->add_arg( "float", "width" ); func->doc = "set width of duty cycle [0,1)."; @@ -251,6 +316,19 @@ DLL_QUERY osc_query( Chuck_DL_Query * QUERY ) doc.c_str() ) ) return FALSE; + // overload constructor (float freq) + func = make_new_mfun( "void", "SqrOsc", oscx_ctor_1 ); + func->add_arg( "float", "freq" ); + func->doc = "Constructor to initialize a SqrOsc at specified frequency."; + if( !type_engine_import_mfun( env, func ) ) goto error; + + // overload constructor (float freq, float phase) + func = make_new_mfun( "void", "SqrOsc", oscx_ctor_2 ); + func->add_arg( "float", "freq" ); + func->add_arg( "float", "phase" ); + func->doc = "Constructor to initialize a SqrOsc at specified frequency and phase."; + if( !type_engine_import_mfun( env, func ) ) goto error; + func = make_new_mfun( "float", "width", sqrosc_ctrl_width ); func->doc = "set width of duty cycle (always 0.5)."; if( !type_engine_import_mfun( env, func ) ) goto error; @@ -311,7 +389,7 @@ struct Osc_Data //----------------------------------------------------------------------------- // name: osc_ctor() -// desc: ... +// desc: default cosntructor //----------------------------------------------------------------------------- CK_DLL_CTOR( osc_ctor ) { @@ -324,10 +402,51 @@ CK_DLL_CTOR( osc_ctor ) +//----------------------------------------------------------------------------- +// generic overloaded ctor( float freq ) +// to be used by subclasses of Osc +//----------------------------------------------------------------------------- +CK_DLL_MFUN( oscx_ctor_1 ) +{ + // get the data + Osc_Data * d = (Osc_Data *)OBJ_MEMBER_UINT(SELF, osc_offset_data ); + // set freq + d->freq = GET_CK_FLOAT(ARGS); + // phase increment + d->num = d->freq / d->srate; + // bound it + if( d->num >= 1.0 ) d->num -= ::floor( d->num ); +} + + + + +//----------------------------------------------------------------------------- +// generic overloaded ctor( float freq, float phase ) +// to be used by subclasses of Osc +//----------------------------------------------------------------------------- +CK_DLL_MFUN( oscx_ctor_2 ) +{ + // get the data + Osc_Data * d = (Osc_Data *)OBJ_MEMBER_UINT(SELF, osc_offset_data ); + // set freq + d->freq = GET_CK_FLOAT(ARGS); + // phase increment + d->num = d->freq / d->srate; + // bound it + if( d->num >= 1.0 ) d->num -= ::floor( d->num ); + + // set phase + d->phase = GET_CK_FLOAT(ARGS); + // bound ( this could be set arbitrarily high or low ) + if( d->phase >= 1.0 || d->phase < 0.0 ) d->phase -= floor( d->num );} + + + //----------------------------------------------------------------------------- // name: osc_dtor() -// desc: ... +// desc: destructor //----------------------------------------------------------------------------- CK_DLL_DTOR( osc_dtor ) { @@ -522,7 +641,7 @@ CK_DLL_TICK( triosc_tick ) // sync phase to input else if( d->sync == 1 ) { - // set freq + // set phase d->phase = in; inc_phase = FALSE; } @@ -594,7 +713,7 @@ CK_DLL_TICK( pulseosc_tick ) // sync phase to input else if( d->sync == 1 ) { - // set freq + // set phase d->phase = in; inc_phase = FALSE; } @@ -723,10 +842,10 @@ CK_DLL_CTRL( osc_ctrl_phase ) { // get data Osc_Data * d = (Osc_Data *)OBJ_MEMBER_UINT(SELF, osc_offset_data ); - // set freq + // set phase d->phase = GET_CK_FLOAT(ARGS); - //bound ( this could be set arbitrarily high or low ) - if ( d->phase >= 1.0 || d->phase < 0.0 ) d->phase -= floor( d->num ); + // bound ( this could be set arbitrarily high or low ) + if( d->phase >= 1.0 || d->phase < 0.0 ) d->phase -= floor( d->num ); // return RETURN->v_float = (t_CKFLOAT)d->phase; } @@ -757,7 +876,7 @@ CK_DLL_CTRL( osc_ctrl_width ) { // get data Osc_Data * d = (Osc_Data *)OBJ_MEMBER_UINT(SELF, osc_offset_data ); - // set freq + // set width d->width = GET_CK_FLOAT(ARGS); //bound ( this could be set arbitrarily high or low ) d->width = ck_max( 0.0, ck_min( 1.0, d->width ) ); @@ -836,7 +955,7 @@ CK_DLL_CTRL( sawosc_ctrl_width ) { // get data Osc_Data * d = (Osc_Data *)OBJ_MEMBER_UINT(SELF, osc_offset_data ); - // set freq + // set width d->width = GET_CK_FLOAT(ARGS); // bound ( this could be set arbitrarily high or low ) d->width = ( d->width < 0.5 ) ? 0.0 : 1.0; //rising or falling @@ -1311,7 +1430,7 @@ CK_DLL_CTRL( genX_lookup ) in_index = GET_NEXT_FLOAT(ARGS); // gewang: moved to here - if (in_index < 0.) in_index = -in_index; + if( in_index < 0 ) in_index = -in_index; scaled_index = in_index * (genX_tableSize - 1); //drive with phasor [0, 1] //set up interpolation parameters diff --git a/src/core/ugen_osc.h b/src/core/ugen_osc.h index 1cd1e09e4..f749388a0 100644 --- a/src/core/ugen_osc.h +++ b/src/core/ugen_osc.h @@ -57,6 +57,11 @@ CK_DLL_CGET( osc_cget_width ); CK_DLL_CTRL( osc_ctrl_sync ); CK_DLL_CGET( osc_cget_sync ); +// generic overloaded ctor( float freq ) +CK_DLL_MFUN( oscx_ctor_1 ); +// generic overloaded ctor( float freq, float phase ) +CK_DLL_MFUN( oscx_ctor_2 ); + // sinosc CK_DLL_TICK( sinosc_tick ); diff --git a/src/test/01-Basic/241-ctor-builtin.ck b/src/test/01-Basic/241-ctor-builtin.ck index fca614f5c..01554ebc3 100644 --- a/src/test/01-Basic/241-ctor-builtin.ck +++ b/src/test/01-Basic/241-ctor-builtin.ck @@ -1,5 +1,5 @@ // constructor -SinOsc foo => Gain g(.5) => dac; +SinOsc foo(440) => Gain g(.5) => dac; // test if( Math.equal(g.gain(),.5) )