Optimized DISCRETE_74LS624 making dkongjr and mario faster.

This commit is contained in:
Derrick Renaud 2009-09-23 00:30:30 +00:00
parent 39bedada9e
commit 66db523852
2 changed files with 21 additions and 5 deletions

View File

@ -124,6 +124,9 @@ struct dsd_ls624_context
int state; int state;
double remain; /* remaining time from last step */ double remain; /* remaining time from last step */
int out_type; int out_type;
double k1; /* precalculated cap part of formula */
double k2; /* precalculated ring part of formula */
double k3; /* another precalculated ring part of formula */
}; };
@ -1593,8 +1596,12 @@ static DISCRETE_RESET(dsd_566)
* where calculated using least square approximation. * where calculated using least square approximation.
* This approach gives a bit better results compared to the first approach. * This approach gives a bit better results compared to the first approach.
*/ */
#define LS624_F(_C, _VI, _VR) pow(10, -0.912029404 * log10(_C) + 0.243264328 * (_VI) \ /* Original formula before optimization of static values
#define LS624_F(_C, _VI, _VR) pow(10, -0.912029404 * log10(_C) + 0.243264328 * (_VI) \
- 0.091695877 * (_VR) -0.014110946 * (_VI) * (_VR) - 3.207072925) - 0.091695877 * (_VR) -0.014110946 * (_VI) * (_VR) - 3.207072925)
*/
#define LS624_F(_VI) pow(10, context->k1 + 0.243264328 * (_VI) \
+ context->k2 + context->k3 * (_VI))
static DISCRETE_STEP(dsd_ls624) static DISCRETE_STEP(dsd_ls624)
{ {
@ -1610,7 +1617,7 @@ static DISCRETE_STEP(dsd_ls624)
sample_t = node->info->sample_time; /* Change in time */ sample_t = node->info->sample_time; /* Change in time */
//dt = LS624_T(DSD_LS624__C, DSD_LS624__VRNG, DSD_LS624__VMOD) / 2.0; //dt = LS624_T(DSD_LS624__C, DSD_LS624__VRNG, DSD_LS624__VMOD) / 2.0;
dt = 1.0f / (2.0f * LS624_F(DSD_LS624__C, DSD_LS624__VMOD, DSD_LS624__VRNG)); dt = 1.0f / (2.0f * LS624_F(DSD_LS624__VMOD));
t = context->remain; t = context->remain;
en += (double) context->state * t; en += (double) context->state * t;
while (t + dt <= sample_t) while (t + dt <= sample_t)
@ -1659,6 +1666,11 @@ static DISCRETE_RESET(dsd_ls624)
context->state = 0; context->state = 0;
context->out_type = DSD_LS624__OUTTYPE; context->out_type = DSD_LS624__OUTTYPE;
/* precalculate some parts of the formula for speed */
context->k1 = -0.912029404 * log10(DSD_LS624__C);
context->k2 = -0.091695877 * (DSD_LS624__VRNG) - 3.207072925;
context->k3 = -0.014110946 * (DSD_LS624__VRNG);
/* Step the output */ /* Step the output */
DISCRETE_STEP_CALL(dsd_ls624); DISCRETE_STEP_CALL(dsd_ls624);
} }

View File

@ -303,6 +303,7 @@
* DISCRETE_555_VCO1(NODE,RESET,VIN,OPTIONS) * DISCRETE_555_VCO1(NODE,RESET,VIN,OPTIONS)
* DISCRETE_555_VCO1_CV(NODE,RESET,VIN,CTRLV,OPTIONS) * DISCRETE_555_VCO1_CV(NODE,RESET,VIN,CTRLV,OPTIONS)
* DISCRETE_566(NODE,ENAB,VMOD,R,C,OPTIONS) * DISCRETE_566(NODE,ENAB,VMOD,R,C,OPTIONS)
* DISCRETE_74LS624(NODE,ENAB,VMOD,VRNG,C,OUTTYPE)
* *
* DISCRETE_CUSTOM1(NODE,IN0,INFO) * DISCRETE_CUSTOM1(NODE,IN0,INFO)
* DISCRETE_CUSTOM2(NODE,IN0,IN1,INFO) * DISCRETE_CUSTOM2(NODE,IN0,IN1,INFO)
@ -3231,8 +3232,8 @@
* DISCRETE_74LS624(name of node, * DISCRETE_74LS624(name of node,
* enable node or static value, * enable node or static value,
* vMod node or static value, * vMod node or static value,
* vRng node or static value, * vRng static value,
* C node or static value in Farads, * C static value in Farads,
* Type of output static value) * Type of output static value)
* *
* Type of Output * Type of Output
@ -3241,6 +3242,9 @@
* DISC_LS624_OUT_COUNT_F Number of Falling edges * DISC_LS624_OUT_COUNT_F Number of Falling edges
* DISC_LS624_OUT_COUNT_R Number of Rising edges * DISC_LS624_OUT_COUNT_R Number of Rising edges
* *
*
* EXAMPLES: see Donkey Kong Jr.
*
*********************************************************************** ***********************************************************************
* *
* DISCRETE_CUSTOMx - Link to custom code * DISCRETE_CUSTOMx - Link to custom code
@ -4422,7 +4426,7 @@ enum
#define DISCRETE_555_VCO1(NODE,RESET,VIN,OPTIONS) { NODE, DSD_555_VCO1 , 3, { RESET,VIN,NODE_NC }, { RESET,VIN,-1 }, OPTIONS, "DISCRETE_555_VCO1" }, #define DISCRETE_555_VCO1(NODE,RESET,VIN,OPTIONS) { NODE, DSD_555_VCO1 , 3, { RESET,VIN,NODE_NC }, { RESET,VIN,-1 }, OPTIONS, "DISCRETE_555_VCO1" },
#define DISCRETE_555_VCO1_CV(NODE,RESET,VIN,CTRLV,OPTIONS) { NODE, DSD_555_VCO1 , 3, { RESET,VIN,CTRLV }, { RESET,VIN,CTRLV }, OPTIONS, "DISCRETE_555_VCO1_CV" }, #define DISCRETE_555_VCO1_CV(NODE,RESET,VIN,CTRLV,OPTIONS) { NODE, DSD_555_VCO1 , 3, { RESET,VIN,CTRLV }, { RESET,VIN,CTRLV }, OPTIONS, "DISCRETE_555_VCO1_CV" },
#define DISCRETE_566(NODE,ENAB,VMOD,R,C,OPTIONS) { NODE, DSD_566 , 4, { ENAB,VMOD,R,C }, { ENAB,VMOD,R,C }, OPTIONS, "DISCRETE_566" }, #define DISCRETE_566(NODE,ENAB,VMOD,R,C,OPTIONS) { NODE, DSD_566 , 4, { ENAB,VMOD,R,C }, { ENAB,VMOD,R,C }, OPTIONS, "DISCRETE_566" },
#define DISCRETE_74LS624(NODE,ENAB,VMOD,VRNG,C,OUTTYPE) { NODE, DSD_LS624 , 5, { ENAB,VMOD,VRNG,C,NODE_NC }, { ENAB,VMOD,VRNG,C, OUTTYPE }, NULL, "DISCRETE_74LS624" }, #define DISCRETE_74LS624(NODE,ENAB,VMOD,VRNG,C,OUTTYPE) { NODE, DSD_LS624 , 5, { ENAB,VMOD,NODE_NC,NODE_NC,NODE_NC }, { ENAB,VMOD,VRNG,C,OUTTYPE }, NULL, "DISCRETE_74LS624" },
/* NOP */ /* NOP */
#define DISCRETE_NOP(NODE) { NODE, DSS_NOP , 0, { 0 }, { 0 }, NULL, "DISCRETE_NOP" }, #define DISCRETE_NOP(NODE) { NODE, DSS_NOP , 0, { 0 }, { 0 }, NULL, "DISCRETE_NOP" },