diff options
author | Derrick Renaud <derrickr@mamedev.org> | 2009-10-01 23:11:53 +0000 |
---|---|---|
committer | Derrick Renaud <derrickr@mamedev.org> | 2009-10-01 23:11:53 +0000 |
commit | 27bbf65bd1f6f190eca544acf9d846db2e60ed93 (patch) | |
tree | d4caeb3d7a249fff16b225a9705eb713a4b33e5c | |
parent | b3adef6de835483e674d707c08f76ea45e3a2379 (diff) |
mario - speed optimization to mario_custom_run()
-rw-r--r-- | src/emu/sound/disc_dev.c | 4 | ||||
-rw-r--r-- | src/mame/audio/mario.c | 52 | ||||
-rw-r--r-- | src/mame/drivers/sprint8.c | 4 |
3 files changed, 47 insertions, 13 deletions
diff --git a/src/emu/sound/disc_dev.c b/src/emu/sound/disc_dev.c index f8fca735fea..b6fb4b8f96d 100644 --- a/src/emu/sound/disc_dev.c +++ b/src/emu/sound/disc_dev.c @@ -1715,7 +1715,7 @@ static DISCRETE_STEP(dsd_ls624) sample_t = node->info->sample_time; /* Change in time */ //dt = LS624_T(DSD_LS624__C, DSD_LS624__VRNG, DSD_LS624__VMOD) / 2.0; if (DSD_LS624__VMOD > 0.001) - dt = 1.0f / (2.0f * LS624_F(DSD_LS624__VMOD)); + dt = 0.5 / LS624_F(DSD_LS624__VMOD); else /* close enough to 0, so we can speed things up by no longer call pow() */ dt = context->dt_vmod_at_0; @@ -1767,7 +1767,7 @@ static DISCRETE_RESET(dsd_ls624) context->k1 = -0.912029404 * log10(DSD_LS624__C) -0.091695877 * (DSD_LS624__VRNG) - 3.207072925; context->k2 = -0.014110946 * (DSD_LS624__VRNG); - context->dt_vmod_at_0 = 1.0f / (2.0f * LS624_F(0)); + context->dt_vmod_at_0 = 0.5 / LS624_F(0); /* Step the output */ DISCRETE_STEP_CALL(dsd_ls624); diff --git a/src/mame/audio/mario.c b/src/mame/audio/mario.c index f7b92235d3c..775b6fddfe9 100644 --- a/src/mame/audio/mario.c +++ b/src/mame/audio/mario.c @@ -132,6 +132,7 @@ #define DISCRETE_LS123_INV(_N, _T, _R, _C) \ DISCRETE_ONESHOTR(_N, 0, _T, TTL_HIGH, (0.25 * (_R) * (_C) * (1.0+700./(_R))), DISC_ONESHOT_RETRIG | DISC_ONESHOT_REDGE | DISC_OUT_ACTIVE_LOW) +/* speed optimization */ /* pow(10, x) = exp(ln(10)*x) */ #define pow10(x) exp(2.30258509299404568401*(x)) @@ -139,8 +140,9 @@ * where calculated using least square approximation. * This approach gives a bit better results compared to the first approach. */ -#define LS624_F(_C, _VI, _VR) pow10( -0.912029404 * log10(_C) + 0.243264328 * (_VI) \ - - 0.091695877 * (_VR) -0.014110946 * (_VI) * (_VR) - 3.207072925) +//#define LS624_F(_C, _VI, _VR) pow10( -0.912029404 * log10(_C) + 0.243264328 * (_VI) \ +// - 0.091695877 * (_VR) -0.014110946 * (_VI) * (_VR) - 3.207072925) +#define LS624_F(_in, _num) pow10(context->k1_##_num + 0.243264328 * (_in) + context->k2_##_num * (_in)) /************************************************************************ * @@ -188,16 +190,34 @@ struct mario_custom_run_context double remain2; double vc3; double r1_c3; + double k1_1; + double k2_1; + double k1_2; + double k2_2; + double exponent_c3; + double dt_in1_at_0; + double dt_in2_at_0; }; static DISCRETE_STEP( mario_custom_run ) { struct mario_custom_run_context *context = (struct mario_custom_run_context *)node->context; - double t1 = 0.5 / LS624_F(MARIO_CUSTOM_C1, MARIO_CUSTOM_IN1, RUN_VCO_VOLTAGE); - double t2 = 0.5 / LS624_F(MARIO_CUSTOM_C2, MARIO_CUSTOM_IN2, RUN_VCO_VOLTAGE); double sample_t = node->info->sample_time; - double vn, t; + double vn, exponent, t = 0; + int update_exponent = 0; + double t1, t2; + + if (MARIO_CUSTOM_IN1 > 0.001) + t1 = 0.5 / LS624_F(MARIO_CUSTOM_IN1, 1); + else + /* close enough to 0, so we can speed things up by no longer call pow() */ + t1 = context->dt_in1_at_0; + + if (MARIO_CUSTOM_IN2 > 0.001) + t2 = 0.5 / LS624_F(MARIO_CUSTOM_IN2, 2); + else + t2 = context->dt_in2_at_0; //if (MARIO_CUSTOM_VOUT) // printf("%f %f %f %f\n", MARIO_CUSTOM_IN1, MARIO_CUSTOM_IN2, 0.5 / t1, 0.5 / t2); @@ -211,6 +231,7 @@ static DISCRETE_STEP( mario_custom_run ) if (context->remain1 < sample_t) { t = context->remain1; + update_exponent = 1; context->state1 ^= 1; sample_t -= context->remain1; context->remain2 -= context->remain1; @@ -218,7 +239,6 @@ static DISCRETE_STEP( mario_custom_run ) } else { - t = sample_t; context->remain1 -= sample_t; context->remain2 -= sample_t; sample_t = 0.0f; @@ -229,6 +249,7 @@ static DISCRETE_STEP( mario_custom_run ) if (context->remain2 < sample_t) { t = context->remain2; + update_exponent = 1; context->state2 ^= 1; sample_t -= context->remain2; context->remain1 -= context->remain2; @@ -236,14 +257,17 @@ static DISCRETE_STEP( mario_custom_run ) } else { - t = sample_t; context->remain1 -= sample_t; context->remain2 -= sample_t; sample_t = 0.0f; } } - context->vc3 += (vn - context->vc3) * (1.0 - exp(- t / context->r1_c3)); + if (update_exponent) + exponent = RC_CHARGE_EXP_DT(context->r1_c3, t); + else + exponent = context->exponent_c3; + context->vc3 += (vn - context->vc3) * exponent; } node->output[0] = context->vc3; } @@ -257,8 +281,18 @@ static DISCRETE_RESET( mario_custom_run ) context->state1 = 0; context->state2 = 0; context->vc3 = 0; - context->r1_c3 = (MARIO_CUSTOM_R1 * MARIO_CUSTOM_C3); + context->r1_c3 = MARIO_CUSTOM_R1 * MARIO_CUSTOM_C3; node->output[0] = 0; + + /* precalculate some parts of the formulas for speed */ + context->k1_1 = -0.912029404 * log10(MARIO_CUSTOM_C1) -0.091695877 * (RUN_VCO_VOLTAGE) - 3.207072925; + context->k2_1 = -0.014110946 * (RUN_VCO_VOLTAGE); + context->k1_2 = -0.912029404 * log10(MARIO_CUSTOM_C2) -0.091695877 * (RUN_VCO_VOLTAGE) - 3.207072925; + context->k2_2 = -0.014110946 * (RUN_VCO_VOLTAGE); + context->exponent_c3 = RC_CHARGE_EXP(context->r1_c3); + + context->dt_in1_at_0 = 0.5 / LS624_F(0, 1); + context->dt_in2_at_0 = 0.5 / LS624_F(0, 2); } static const discrete_custom_info mario_custom_run_info = diff --git a/src/mame/drivers/sprint8.c b/src/mame/drivers/sprint8.c index 05e53bd8d80..5b166db8ce1 100644 --- a/src/mame/drivers/sprint8.c +++ b/src/mame/drivers/sprint8.c @@ -484,8 +484,8 @@ static MACHINE_DRIVER_START( sprint8 ) MDRV_SOUND_CONFIG_DISCRETE(sprint8) MDRV_SOUND_ROUTE(0, "speaker_1_2", 1.0) MDRV_SOUND_ROUTE(1, "speaker_3_7", 1.0) - MDRV_SOUND_ROUTE(3, "speaker_5_6", 1.0) - MDRV_SOUND_ROUTE(4, "speaker_4_8", 1.0) + MDRV_SOUND_ROUTE(2, "speaker_5_6", 1.0) + MDRV_SOUND_ROUTE(3, "speaker_4_8", 1.0) #else MDRV_SPEAKER_STANDARD_MONO("speaker") |