Bye discrete_info. Another round of discrete rewrites. No whatsnew.

This commit is contained in:
Couriersud 2011-01-05 21:37:53 +00:00
parent 644775767f
commit dbb0cc1377
9 changed files with 306 additions and 499 deletions

View File

@ -244,7 +244,7 @@ DISCRETE_STEP(dsd_555_astbl)
* dt = R*C(log(1/(1-(Vc/Vr)))) * dt = R*C(log(1/(1-(Vc/Vr))))
*/ */
dt = node->info->sample_time; dt = node->sample_time();
/* Sometimes a switching network is used to setup the capacitance. /* Sometimes a switching network is used to setup the capacitance.
* These may select no capacitor, causing oscillation to stop. * These may select no capacitor, causing oscillation to stop.
@ -349,7 +349,7 @@ DISCRETE_STEP(dsd_555_astbl)
} }
/* Convert last switch time to a ratio */ /* Convert last switch time to a ratio */
x_time = x_time / node->info->sample_time; x_time = x_time / node->sample_time();
switch (context->output_type) switch (context->output_type)
{ {
@ -405,7 +405,7 @@ DISCRETE_RESET(dsd_555_astbl)
context->v_out_high = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high; context->v_out_high = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high;
/* setup v_charge or node */ /* setup v_charge or node */
v_charge_node = discrete_find_node(node->info, info->v_charge); v_charge_node = node->device->discrete_find_node(info->v_charge);
if (v_charge_node) if (v_charge_node)
context->v_charge_node = &(v_charge_node->output[NODE_CHILD_NODE_NUM(info->v_charge)]); context->v_charge_node = &(v_charge_node->output[NODE_CHILD_NODE_NUM(info->v_charge)]);
else else
@ -499,7 +499,7 @@ DISCRETE_STEP(dsd_555_mstbl)
return; return;
} }
dt = node->info->sample_time; dt = node->sample_time();
flip_flop = context->flip_flop; flip_flop = context->flip_flop;
trigger_type = info->options; trigger_type = info->options;
v_cap = context->cap_voltage; v_cap = context->cap_voltage;
@ -574,7 +574,7 @@ DISCRETE_STEP(dsd_555_mstbl)
if (UNEXPECTED((v_cap >= context->threshold) && !trigger)) if (UNEXPECTED((v_cap >= context->threshold) && !trigger))
{ {
dt = DSD_555_MSTBL__R * DSD_555_MSTBL__C * log(1.0 / (1.0 - ((v_cap - context->threshold) / v_diff))); dt = DSD_555_MSTBL__R * DSD_555_MSTBL__C * log(1.0 / (1.0 - ((v_cap - context->threshold) / v_diff)));
x_time = 1.0 - dt / node->info->sample_time; x_time = 1.0 - dt / node->sample_time();
v_cap = 0; v_cap = 0;
flip_flop = 0; flip_flop = 0;
context->flip_flop = 0; context->flip_flop = 0;
@ -618,7 +618,7 @@ DISCRETE_RESET(dsd_555_mstbl)
context->output_type = info->options & DISC_555_OUT_MASK; context->output_type = info->options & DISC_555_OUT_MASK;
if ((context->output_type == DISC_555_OUT_COUNT_F) || (context->output_type == DISC_555_OUT_COUNT_R)) if ((context->output_type == DISC_555_OUT_COUNT_F) || (context->output_type == DISC_555_OUT_COUNT_R))
{ {
discrete_log(node->info, "Invalid Output type in NODE_%d.\n", node->index()); node->device->discrete_log("Invalid Output type in NODE_%d.\n", node->index());
context->output_type = DISC_555_OUT_SQW; context->output_type = DISC_555_OUT_SQW;
} }
@ -727,7 +727,7 @@ DISCRETE_STEP(dsd_555_cc)
return; return;
} }
dt = node->info->sample_time; /* Change in time */ dt = node->sample_time(); /* Change in time */
v_cap = context->cap_voltage; /* Set to voltage before change */ v_cap = context->cap_voltage; /* Set to voltage before change */
v_vcharge_limit = DSD_555_CC__VIN + info->v_cc_junction; /* the max v_cap can be and still be charged by i */ v_vcharge_limit = DSD_555_CC__VIN + info->v_cc_junction; /* the max v_cap can be and still be charged by i */
/* Calculate charging current */ /* Calculate charging current */
@ -974,7 +974,7 @@ DISCRETE_STEP(dsd_555_cc)
context->cap_voltage = v_cap; context->cap_voltage = v_cap;
/* Convert last switch time to a ratio */ /* Convert last switch time to a ratio */
x_time = x_time / node->info->sample_time; x_time = x_time / node->sample_time();
switch (context->output_type) switch (context->output_type)
{ {
@ -1256,7 +1256,7 @@ DISCRETE_STEP(dsd_555_vco1)
double v_cap; /* Current voltage on capacitor, before dt */ double v_cap; /* Current voltage on capacitor, before dt */
double v_cap_next = 0; /* Voltage on capacitor, after dt */ double v_cap_next = 0; /* Voltage on capacitor, after dt */
dt = node->info->sample_time; /* Change in time */ dt = node->sample_time(); /* Change in time */
v_cap = context->cap_voltage; v_cap = context->cap_voltage;
/* Check: if the Control Voltage node is connected. */ /* Check: if the Control Voltage node is connected. */
@ -1360,7 +1360,7 @@ DISCRETE_STEP(dsd_555_vco1)
context->cap_voltage = v_cap_next; context->cap_voltage = v_cap_next;
/* Convert last switch time to a ratio. No x_time in reset. */ /* Convert last switch time to a ratio. No x_time in reset. */
x_time = x_time / node->info->sample_time; x_time = x_time / node->sample_time();
if (!DSD_555_VCO1__RESET) x_time = 0; if (!DSD_555_VCO1__RESET) x_time = 0;
switch (context->output_type) switch (context->output_type)
@ -1546,7 +1546,7 @@ DISCRETE_STEP(dsd_566)
double v_cap; /* Current voltage on capacitor, before dt */ double v_cap; /* Current voltage on capacitor, before dt */
int count_f = 0, count_r = 0; int count_f = 0, count_r = 0;
dt = node->info->sample_time; /* Change in time */ dt = node->sample_time(); /* Change in time */
v_cap = context->cap_voltage; /* Set to voltage before change */ v_cap = context->cap_voltage; /* Set to voltage before change */
/* Calculate charging current if it is in range */ /* Calculate charging current if it is in range */
@ -1619,7 +1619,7 @@ DISCRETE_STEP(dsd_566)
context->cap_voltage = v_cap; context->cap_voltage = v_cap;
/* Convert last switch time to a ratio */ /* Convert last switch time to a ratio */
x_time /= node->info->sample_time; x_time /= node->sample_time();
switch (context->out_type) switch (context->out_type)
{ {
@ -1766,7 +1766,7 @@ DISCRETE_STEP(dsd_ls624)
double freq, t1; double freq, t1;
double v_freq_2, v_freq_3, v_freq_4; double v_freq_2, v_freq_3, v_freq_4;
double t_used = context->t_used; double t_used = context->t_used;
double dt = node->info->sample_time;; double dt = node->sample_time();;
double v_freq = DSD_LS624__VMOD; double v_freq = DSD_LS624__VMOD;
double v_rng = DSD_LS624__VRNG; double v_rng = DSD_LS624__VRNG;
int count_f = 0, count_r = 0; int count_f = 0, count_r = 0;
@ -1815,7 +1815,7 @@ DISCRETE_STEP(dsd_ls624)
freq *= CAP_U(0.1) / DSD_LS624__C; freq *= CAP_U(0.1) / DSD_LS624__C;
t1 = 0.5 / freq ; t1 = 0.5 / freq ;
t_used += node->info->sample_time; t_used += node->sample_time();
do do
{ {
dt = 0; dt = 0;
@ -1829,8 +1829,8 @@ DISCRETE_STEP(dsd_ls624)
else else
count_f++; count_f++;
/* fix up any frequency increase change errors */ /* fix up any frequency increase change errors */
while(t_used > node->info->sample_time) while(t_used > node->sample_time())
t_used -= node->info->sample_time; t_used -= node->sample_time();
x_time = t_used; x_time = t_used;
dt = t_used; dt = t_used;
} }
@ -1839,7 +1839,7 @@ DISCRETE_STEP(dsd_ls624)
context->t_used = t_used; context->t_used = t_used;
/* Convert last switch time to a ratio */ /* Convert last switch time to a ratio */
x_time = x_time / node->info->sample_time; x_time = x_time / node->sample_time();
switch (context->out_type) switch (context->out_type)
{ {

View File

@ -202,15 +202,15 @@ DISCRETE_RESET(dst_crfilter)
#define DST_FILTER1__FREQ DISCRETE_INPUT(2) #define DST_FILTER1__FREQ DISCRETE_INPUT(2)
#define DST_FILTER1__TYPE DISCRETE_INPUT(3) #define DST_FILTER1__TYPE DISCRETE_INPUT(3)
static void calculate_filter1_coefficients(const discrete_info *disc_info, double fc, double type, static void calculate_filter1_coefficients(node_description *node, double fc, double type,
double *a1, double *b0, double *b1) double *a1, double *b0, double *b1)
{ {
double den, w, two_over_T; double den, w, two_over_T;
/* calculate digital filter coefficents */ /* calculate digital filter coefficents */
/*w = 2.0*M_PI*fc; no pre-warping */ /*w = 2.0*M_PI*fc; no pre-warping */
w = disc_info->sample_rate*2.0*tan(M_PI*fc/disc_info->sample_rate); /* pre-warping */ w = node->sample_rate()*2.0*tan(M_PI*fc/node->sample_rate()); /* pre-warping */
two_over_T = 2.0*disc_info->sample_rate; two_over_T = 2.0*node->sample_rate();
den = w + two_over_T; den = w + two_over_T;
*a1 = (w - two_over_T)/den; *a1 = (w - two_over_T)/den;
@ -225,7 +225,7 @@ static void calculate_filter1_coefficients(const discrete_info *disc_info, doubl
} }
else else
{ {
discrete_log(disc_info, "calculate_filter1_coefficients() - Invalid filter type for 1st order filter."); node->device->discrete_log("calculate_filter1_coefficients() - Invalid filter type for 1st order filter.");
} }
} }
@ -250,7 +250,7 @@ DISCRETE_RESET(dst_filter1)
{ {
DISCRETE_DECLARE_CONTEXT(dst_filter1) DISCRETE_DECLARE_CONTEXT(dst_filter1)
calculate_filter1_coefficients(node->info, DST_FILTER1__FREQ, DST_FILTER1__TYPE, &context->a1, &context->b0, &context->b1); calculate_filter1_coefficients(node, DST_FILTER1__FREQ, DST_FILTER1__TYPE, &context->a1, &context->b0, &context->b1);
node->output[0] = 0; node->output[0] = 0;
} }
@ -272,7 +272,7 @@ DISCRETE_RESET(dst_filter1)
#define DST_FILTER2__DAMP DISCRETE_INPUT(3) #define DST_FILTER2__DAMP DISCRETE_INPUT(3)
#define DST_FILTER2__TYPE DISCRETE_INPUT(4) #define DST_FILTER2__TYPE DISCRETE_INPUT(4)
static void calculate_filter2_coefficients(const discrete_info *disc_info, static void calculate_filter2_coefficients(node_description *node,
double fc, double d, double type, double fc, double d, double type,
double *a1, double *a2, double *a1, double *a2,
double *b0, double *b1, double *b2) double *b0, double *b1, double *b2)
@ -280,12 +280,12 @@ static void calculate_filter2_coefficients(const discrete_info *disc_info,
double w; /* cutoff freq, in radians/sec */ double w; /* cutoff freq, in radians/sec */
double w_squared; double w_squared;
double den; /* temp variable */ double den; /* temp variable */
double two_over_T = 2 * disc_info->sample_rate; double two_over_T = 2 * node->sample_rate();
double two_over_T_squared = two_over_T * two_over_T; double two_over_T_squared = two_over_T * two_over_T;
/* calculate digital filter coefficents */ /* calculate digital filter coefficents */
/*w = 2.0*M_PI*fc; no pre-warping */ /*w = 2.0*M_PI*fc; no pre-warping */
w = disc_info->sample_rate * 2.0 * tan(M_PI * fc / disc_info->sample_rate); /* pre-warping */ w = node->sample_rate() * 2.0 * tan(M_PI * fc / node->sample_rate()); /* pre-warping */
w_squared = w * w; w_squared = w * w;
den = two_over_T_squared + d*w*two_over_T + w_squared; den = two_over_T_squared + d*w*two_over_T + w_squared;
@ -311,7 +311,7 @@ static void calculate_filter2_coefficients(const discrete_info *disc_info,
} }
else else
{ {
discrete_log(disc_info, "calculate_filter2_coefficients() - Invalid filter type for 2nd order filter."); node->device->discrete_log("calculate_filter2_coefficients() - Invalid filter type for 2nd order filter.");
} }
} }
@ -339,7 +339,7 @@ DISCRETE_RESET(dst_filter2)
{ {
DISCRETE_DECLARE_CONTEXT(dst_filter2) DISCRETE_DECLARE_CONTEXT(dst_filter2)
calculate_filter2_coefficients(node->info, DST_FILTER2__FREQ, DST_FILTER2__DAMP, DST_FILTER2__TYPE, calculate_filter2_coefficients(node, DST_FILTER2__FREQ, DST_FILTER2__DAMP, DST_FILTER2__TYPE,
&context->a1, &context->a2, &context->a1, &context->a2,
&context->b0, &context->b1, &context->b2); &context->b0, &context->b1, &context->b2);
node->output[0] = 0; node->output[0] = 0;
@ -532,7 +532,7 @@ DISCRETE_RESET(dst_op_amp_filt)
double d = (info->c1 + info->c2) / sqrt(info->rF / context->rTotal * info->c1 * info->c2); double d = (info->c1 + info->c2) / sqrt(info->rF / context->rTotal * info->c1 * info->c2);
double gain = -info->rF / context->rTotal * info->c2 / (info->c1 + info->c2); double gain = -info->rF / context->rTotal * info->c2 / (info->c1 + info->c2);
calculate_filter2_coefficients(node->info, fc, d, DISC_FILTER_BANDPASS, calculate_filter2_coefficients(node, fc, d, DISC_FILTER_BANDPASS,
&context->a1, &context->a2, &context->a1, &context->a2,
&context->b0, &context->b1, &context->b2); &context->b0, &context->b1, &context->b2);
context->b0 *= gain; context->b0 *= gain;
@ -665,7 +665,7 @@ DISCRETE_STEP(dst_rcdisc)
if (DST_RCDISC__ENABLE) if (DST_RCDISC__ENABLE)
{ {
node->output[0] = DST_RCDISC__IN * exp(context->t / context->exponent0); node->output[0] = DST_RCDISC__IN * exp(context->t / context->exponent0);
context->t += node->info->sample_time; context->t += node->sample_time();
} else } else
{ {
context->state = 0; context->state = 0;
@ -872,17 +872,17 @@ DISCRETE_RESET( dst_rcdisc4)
/* some error checking. */ /* some error checking. */
if (DST_RCDISC4__R1 <= 0 || DST_RCDISC4__R2 <= 0 || DST_RCDISC4__C1 <= 0 || (DST_RCDISC4__R3 <= 0 && context->type == 1)) if (DST_RCDISC4__R1 <= 0 || DST_RCDISC4__R2 <= 0 || DST_RCDISC4__C1 <= 0 || (DST_RCDISC4__R3 <= 0 && context->type == 1))
{ {
discrete_log(node->info, "Invalid component values in NODE_%d.\n", node->index()); node->device->discrete_log("Invalid component values in NODE_%d.\n", node->index());
return; return;
} }
if (DST_RCDISC4__VP < 3) if (DST_RCDISC4__VP < 3)
{ {
discrete_log(node->info, "vP must be >= 3V in NODE_%d.\n", node->index()); node->device->discrete_log("vP must be >= 3V in NODE_%d.\n", node->index());
return; return;
} }
if (DST_RCDISC4__TYPE < 1 || DST_RCDISC4__TYPE > 3) if (DST_RCDISC4__TYPE < 1 || DST_RCDISC4__TYPE > 3)
{ {
discrete_log(node->info, "Invalid circuit type in NODE_%d.\n", node->index()); node->device->discrete_log("Invalid circuit type in NODE_%d.\n", node->index());
return; return;
} }
@ -1357,7 +1357,7 @@ DISCRETE_RESET(dst_rcintegrate)
DISCRETE_DECLARE_CONTEXT(dst_rcintegrate) DISCRETE_DECLARE_CONTEXT(dst_rcintegrate)
double r; double r;
double dt = node->info->sample_time; double dt = node->sample_time();
context->type = DST_RCINTEGRATE__TYPE; context->type = DST_RCINTEGRATE__TYPE;
@ -1433,7 +1433,7 @@ DISCRETE_RESET(dst_sallen_key)
fatalerror("Unknown sallen key filter type"); fatalerror("Unknown sallen key filter type");
} }
calculate_filter2_coefficients(node->info, freq, 1.0 / q, DISC_FILTER_LOWPASS, calculate_filter2_coefficients(node, freq, 1.0 / q, DISC_FILTER_LOWPASS,
&context->a1, &context->a2, &context->a1, &context->a2,
&context->b0, &context->b1, &context->b2); &context->b0, &context->b1, &context->b2);
node->output[0] = 0; node->output[0] = 0;
@ -1581,8 +1581,8 @@ DISCRETE_RESET(dst_rcdisc2N)
f1 = 1.0 / (2 * M_PI * DST_RCDISC2N__R0 * DST_RCDISC2N__C); f1 = 1.0 / (2 * M_PI * DST_RCDISC2N__R0 * DST_RCDISC2N__C);
f2 = 1.0 / (2 * M_PI * DST_RCDISC2N__R1 * DST_RCDISC2N__C); f2 = 1.0 / (2 * M_PI * DST_RCDISC2N__R1 * DST_RCDISC2N__C);
calculate_filter1_coefficients(node->info, f1, DISC_FILTER_LOWPASS, &context->a1_0, &context->b0_0, &context->b1_0); calculate_filter1_coefficients(node, f1, DISC_FILTER_LOWPASS, &context->a1_0, &context->b0_0, &context->b1_0);
calculate_filter1_coefficients(node->info, f2, DISC_FILTER_LOWPASS, &context->a1_1, &context->b0_1, &context->b1_1); calculate_filter1_coefficients(node, f2, DISC_FILTER_LOWPASS, &context->a1_1, &context->b0_1, &context->b1_1);
/* Initialize the object */ /* Initialize the object */
node->output[0] = 0; node->output[0] = 0;

View File

@ -112,7 +112,7 @@ DISCRETE_RESET(dss_adjustment)
double min, max; double min, max;
context->port = node->info->device->machine->m_portlist.find((const char *)node->custom_data()); context->port = node->device->machine->m_portlist.find((const char *)node->custom_data());
if (context->port == NULL) if (context->port == NULL)
fatalerror("DISCRETE_ADJUSTMENT - NODE_%d has invalid tag", node->index()); fatalerror("DISCRETE_ADJUSTMENT - NODE_%d has invalid tag", node->index());
@ -242,7 +242,7 @@ DISCRETE_START(dss_input_stream)
{ {
DISCRETE_DECLARE_CONTEXT(dss_input) DISCRETE_DECLARE_CONTEXT(dss_input)
//assert(DSS_INPUT_STREAM__STREAM < node->info->input_list.count()); assert(DSS_INPUT_STREAM__STREAM < node->info->m_input_list.count());
context->is_stream = TRUE; context->is_stream = TRUE;
/* Stream out number is set during start */ /* Stream out number is set during start */
@ -252,12 +252,12 @@ DISCRETE_START(dss_input_stream)
context->ptr = NULL; context->ptr = NULL;
//context->data = 0; //context->data = 0;
if (node->block_type() == DSS_INPUT_BUFFER) if (node->module->type == DSS_INPUT_BUFFER)
{ {
context->is_buffered = TRUE; context->is_buffered = TRUE;
context->buffer_stream = stream_create(node->info->device, 0, 1, node->info->sample_rate, (void *) node, buffer_stream_update); context->buffer_stream = stream_create(node->device, 0, 1, node->sample_rate(), (void *) node, buffer_stream_update);
stream_set_input(node->info->discrete_stream, context->stream_in_number, stream_set_input(node->device->discrete_stream, context->stream_in_number,
context->buffer_stream, 0, 1.0); context->buffer_stream, 0, 1.0);
} }
else else

View File

@ -379,11 +379,11 @@ DISCRETE_RESET(dst_dac_r1)
if (ladderLength < 2 && info->rBias == 0 && info->rGnd == 0) if (ladderLength < 2 && info->rBias == 0 && info->rGnd == 0)
{ {
/* You need at least 2 resistors for a ladder */ /* You need at least 2 resistors for a ladder */
discrete_log(node->info, "dst_dac_r1_reset - Ladder length too small"); node->device->discrete_log("dst_dac_r1_reset - Ladder length too small");
} }
if (ladderLength > DISC_LADDER_MAXRES ) if (ladderLength > DISC_LADDER_MAXRES )
{ {
discrete_log(node->info, "dst_dac_r1_reset - Ladder length exceeds DISC_LADDER_MAXRES"); node->device->discrete_log("dst_dac_r1_reset - Ladder length exceeds DISC_LADDER_MAXRES");
} }
/* /*
@ -512,7 +512,7 @@ DISCRETE_STEP(dst_divide)
if(DST_DIVIDE__DIV == 0) if(DST_DIVIDE__DIV == 0)
{ {
node->output[0 ]= DBL_MAX; /* Max out but don't break */ node->output[0 ]= DBL_MAX; /* Max out but don't break */
discrete_log(node->info, "dst_divider_step() - Divide by Zero attempted in NODE_%02d.\n",node->index()); node->device->discrete_log("dst_divider_step() - Divide by Zero attempted in NODE_%02d.\n",node->index());
} }
else else
{ {
@ -620,7 +620,7 @@ DISCRETE_STEP(dst_integrate)
i_neg = context->v_max_in / info->r1; i_neg = context->v_max_in / info->r1;
i_pos = (DST_INTEGRATE__TRG0 - OP_AMP_NORTON_VBE) / info->r2; i_pos = (DST_INTEGRATE__TRG0 - OP_AMP_NORTON_VBE) / info->r2;
if (i_pos < 0) i_pos = 0; if (i_pos < 0) i_pos = 0;
node->output[0] += (i_pos - i_neg) / node->info->sample_rate / info->c; node->output[0] += (i_pos - i_neg) / node->sample_rate() / info->c;
break; break;
case DISC_INTEGRATE_OP_AMP_2 | DISC_OP_AMP_IS_NORTON: case DISC_INTEGRATE_OP_AMP_2 | DISC_OP_AMP_IS_NORTON:
@ -629,7 +629,7 @@ DISCRETE_STEP(dst_integrate)
i_neg = dst_trigger_function(trig0, trig1, 0, info->f0) ? context->v_max_in_d / info->r1 : 0; i_neg = dst_trigger_function(trig0, trig1, 0, info->f0) ? context->v_max_in_d / info->r1 : 0;
i_pos = dst_trigger_function(trig0, trig1, 0, info->f1) ? context->v_max_in / info->r2 : 0; i_pos = dst_trigger_function(trig0, trig1, 0, info->f1) ? context->v_max_in / info->r2 : 0;
i_pos += dst_trigger_function(trig0, trig1, 0, info->f2) ? context->v_max_in_d / info->r3 : 0; i_pos += dst_trigger_function(trig0, trig1, 0, info->f2) ? context->v_max_in_d / info->r3 : 0;
node->output[0] += (i_pos - i_neg) / node->info->sample_rate / info->c; node->output[0] += (i_pos - i_neg) / node->sample_rate() / info->c;
break; break;
} }
@ -658,7 +658,7 @@ DISCRETE_RESET(dst_integrate)
v = info->v1 * info->r3 / (info->r2 + info->r3); /* vRef */ v = info->v1 * info->r3 / (info->r2 + info->r3); /* vRef */
v = info->v1 - v; /* actual charging voltage */ v = info->v1 - v; /* actual charging voltage */
i = v / info->r1; i = v / info->r1;
context->change = i / node->info->sample_rate / info->c; context->change = i / node->sample_rate() / info->c;
} }
node->output[0] = 0; node->output[0] = 0;
} }
@ -994,7 +994,7 @@ DISCRETE_STEP(dst_logic_shift)
if (context->clock_type == DISC_CLK_IS_FREQ) if (context->clock_type == DISC_CLK_IS_FREQ)
{ {
/* We need to keep clocking the internal clock even if in reset. */ /* We need to keep clocking the internal clock even if in reset. */
cycles = (context->t_left + node->info->sample_time) * ds_clock; cycles = (context->t_left + node->sample_time()) * ds_clock;
inc = (int)cycles; inc = (int)cycles;
context->t_left = (cycles - inc) / ds_clock; context->t_left = (cycles - inc) / ds_clock;
} }
@ -1324,7 +1324,7 @@ DISCRETE_RESET(dst_mixer)
context->r_node_bit_flag = 0; context->r_node_bit_flag = 0;
for (bit = 0; bit < 8; bit++) for (bit = 0; bit < 8; bit++)
{ {
r_node = discrete_find_node(node->info, info->r_node[bit]); r_node = node->device->discrete_find_node(info->r_node[bit]);
if (r_node != NULL) if (r_node != NULL)
{ {
context->r_node[bit] = &(r_node->output[NODE_CHILD_NODE_NUM(info->r_node[bit])]); context->r_node[bit] = &(r_node->output[NODE_CHILD_NODE_NUM(info->r_node[bit])]);
@ -1447,7 +1447,7 @@ DISCRETE_STEP(dst_multiplex)
else else
{ {
/* Bad address. We will leave the output alone. */ /* Bad address. We will leave the output alone. */
discrete_log(node->info, "NODE_%02d - Address = %d. Out of bounds\n", node->index(), addr); node->device->discrete_log("NODE_%02d - Address = %d. Out of bounds\n", node->index(), addr);
} }
} }
@ -1527,7 +1527,7 @@ DISCRETE_STEP(dst_oneshot)
if (UNEXPECTED(do_count)) if (UNEXPECTED(do_count))
{ {
context->countdown -= node->info->sample_time; context->countdown -= node->sample_time();
if(context->countdown <= 0.0) if(context->countdown <= 0.0)
{ {
node->output[0] = (context->type & DISC_OUT_ACTIVE_LOW) ? DST_ONESHOT__AMP : 0; node->output[0] = (context->type & DISC_OUT_ACTIVE_LOW) ? DST_ONESHOT__AMP : 0;
@ -1604,7 +1604,7 @@ DISCRETE_RESET(dst_ramp)
DISCRETE_DECLARE_CONTEXT(dst_ramp) DISCRETE_DECLARE_CONTEXT(dst_ramp)
node->output[0] = DST_RAMP__CLAMP; node->output[0] = DST_RAMP__CLAMP;
context->step = DST_RAMP__GRAD / node->info->sample_rate; context->step = DST_RAMP__GRAD / node->sample_rate();
context->dir = ((DST_RAMP__END - DST_RAMP__START) == abs(DST_RAMP__END - DST_RAMP__START)); context->dir = ((DST_RAMP__END - DST_RAMP__START) == abs(DST_RAMP__END - DST_RAMP__START));
context->last_en = 0; context->last_en = 0;
} }
@ -1646,7 +1646,7 @@ DISCRETE_STEP(dst_samphold)
if (DST_SAMPHOLD__CLOCK == 0) node->output[0] = DST_SAMPHOLD__IN0; if (DST_SAMPHOLD__CLOCK == 0) node->output[0] = DST_SAMPHOLD__IN0;
break; break;
default: default:
discrete_log(node->info, "dst_samphold_step - Invalid clocktype passed"); node->device->discrete_log("dst_samphold_step - Invalid clocktype passed");
break; break;
} }
/* Save the last value */ /* Save the last value */
@ -1832,7 +1832,7 @@ DISCRETE_STEP(dst_transform)
top = (int)number1 ^ (int)top; top = (int)number1 ^ (int)top;
break; break;
default: default:
discrete_log(node->info, "dst_transform_step - Invalid function type/variable passed: %s",(const char *)node->custom_data()); node->device->discrete_log("dst_transform_step - Invalid function type/variable passed: %s",(const char *)node->custom_data());
/* that is enough to fatalerror */ /* that is enough to fatalerror */
fatalerror("dst_transform_step - Invalid function type/variable passed: %s", (const char *)node->custom_data()); fatalerror("dst_transform_step - Invalid function type/variable passed: %s", (const char *)node->custom_data());
break; break;
@ -1947,7 +1947,7 @@ DISCRETE_RESET(dst_op_amp)
} }
else else
/* linear charge */ /* linear charge */
context->exponent = node->info->sample_rate * info->c; context->exponent = node->sample_rate() * info->c;
} }
if (info->r3 > 0) if (info->r3 > 0)

View File

@ -74,17 +74,17 @@ static void task_check(discrete_task *task, discrete_task *dest_task)
if (task->numbuffered >= DISCRETE_MAX_TASK_OUTPUTS) if (task->numbuffered >= DISCRETE_MAX_TASK_OUTPUTS)
fatalerror("dso_task_start - Number of maximum buffered nodes exceeded"); fatalerror("dso_task_start - Number of maximum buffered nodes exceeded");
task->node_buf[task->numbuffered] = auto_alloc_array(task_node->info->device->machine, double, task->node_buf[task->numbuffered] = auto_alloc_array(task_node->device->machine, double,
((task_node->info->sample_rate + STREAMS_UPDATE_FREQUENCY) / STREAMS_UPDATE_FREQUENCY)); ((task_node->sample_rate() + STREAMS_UPDATE_FREQUENCY) / STREAMS_UPDATE_FREQUENCY));
task->source[task->numbuffered] = (double *) dest_node->input[inputnum]; task->source[task->numbuffered] = (double *) dest_node->input[inputnum];
task->nodes[task->numbuffered] = discrete_find_node(task_node->info, inputnode); task->nodes[task->numbuffered] = task_node->device->discrete_find_node(inputnode);
i = task->numbuffered; i = task->numbuffered;
task->numbuffered++; task->numbuffered++;
} }
discrete_log(task_node->info, "dso_task_start - buffering %d(%d) in task %p group %d referenced by %d group %d", NODE_INDEX(inputnode), NODE_CHILD_NODE_NUM(inputnode), task, task->task_group, dest_node->index(), dest_task->task_group); task_node->device->discrete_log("dso_task_start - buffering %d(%d) in task %p group %d referenced by %d group %d", NODE_INDEX(inputnode), NODE_CHILD_NODE_NUM(inputnode), task, task->task_group, dest_node->index(), dest_task->task_group);
/* register into source list */ /* register into source list */
source = auto_alloc(dest_node->info->device->machine, discrete_source_node); source = auto_alloc(dest_node->device->machine, discrete_source_node);
dest_task->source_list.add_tail(source); dest_task->source_list.add_tail(source);
source->task = task; source->task = task;
source->output_node = i; source->output_node = i;
@ -110,7 +110,7 @@ DISCRETE_START( dso_task_start )
if (task->task_group < 0 || task->task_group >= DISCRETE_MAX_TASK_GROUPS) if (task->task_group < 0 || task->task_group >= DISCRETE_MAX_TASK_GROUPS)
fatalerror("discrete_dso_task: illegal task_group %d", task->task_group); fatalerror("discrete_dso_task: illegal task_group %d", task->task_group);
for_each(discrete_task *, dest_task, &node->info->task_list) for_each(discrete_task *, dest_task, &node->device->task_list)
{ {
if (task->task_group > dest_task.item()->task_group) if (task->task_group > dest_task.item()->task_group)
task_check(dest_task.item(), task); task_check(dest_task.item(), task);
@ -168,15 +168,15 @@ DISCRETE_START( dso_csvlog )
int log_num, node_num; int log_num, node_num;
log_num = node->same_module_index(node->info->node_list); log_num = node->device->same_module_index(*node);
context->sample_num = 0; context->sample_num = 0;
sprintf(context->name, "discrete_%s_%d.csv", node->info->device->tag(), log_num); sprintf(context->name, "discrete_%s_%d.csv", node->device->tag(), log_num);
context->csv_file = fopen(context->name, "w"); context->csv_file = fopen(context->name, "w");
/* Output some header info */ /* Output some header info */
fprintf(context->csv_file, "\"MAME Discrete System Node Log\"\n"); fprintf(context->csv_file, "\"MAME Discrete System Node Log\"\n");
fprintf(context->csv_file, "\"Log Version\", 1.0\n"); fprintf(context->csv_file, "\"Log Version\", 1.0\n");
fprintf(context->csv_file, "\"Sample Rate\", %d\n", node->info->sample_rate); fprintf(context->csv_file, "\"Sample Rate\", %d\n", node->sample_rate());
fprintf(context->csv_file, "\n"); fprintf(context->csv_file, "\n");
fprintf(context->csv_file, "\"Sample\""); fprintf(context->csv_file, "\"Sample\"");
for (node_num = 0; node_num < node->active_inputs(); node_num++) for (node_num = 0; node_num < node->active_inputs(); node_num++)
@ -216,9 +216,9 @@ DISCRETE_START( dso_wavlog )
int log_num; int log_num;
log_num = node->same_module_index(node->info->node_list); log_num = node->device->same_module_index(*node);
sprintf(context->name, "discrete_%s_%d.wav", node->info->device->tag(), log_num); sprintf(context->name, "discrete_%s_%d.wav", node->device->tag(), log_num);
context->wavfile = wav_open(context->name, node->info->sample_rate, node->active_inputs()/2); context->wavfile = wav_open(context->name, node->sample_rate(), node->active_inputs()/2);
} }
DISCRETE_STOP( dso_wavlog ) DISCRETE_STOP( dso_wavlog )

View File

@ -207,10 +207,10 @@ DISCRETE_STEP(dss_counter)
if (UNEXPECTED(context->clock_type == DISC_CLK_IS_FREQ)) if (UNEXPECTED(context->clock_type == DISC_CLK_IS_FREQ))
{ {
/* We need to keep clocking the internal clock even if disabled. */ /* We need to keep clocking the internal clock even if disabled. */
cycles = (context->t_left + node->info->sample_time) * ds_clock; cycles = (context->t_left + node->sample_time()) * ds_clock;
inc = (int)cycles; inc = (int)cycles;
context->t_left = (cycles - inc) / ds_clock; context->t_left = (cycles - inc) / ds_clock;
if (inc) x_time = context->t_left / node->info->sample_time; if (inc) x_time = context->t_left / node->sample_time();
} }
else else
{ {
@ -355,7 +355,7 @@ DISCRETE_RESET(dss_counter)
#define DSS_LFSR_NOISE__FEED DISCRETE_INPUT(4) #define DSS_LFSR_NOISE__FEED DISCRETE_INPUT(4)
#define DSS_LFSR_NOISE__BIAS DISCRETE_INPUT(5) #define DSS_LFSR_NOISE__BIAS DISCRETE_INPUT(5)
INLINE int dss_lfsr_function(const discrete_info *disc_info, int myfunc, int in0, int in1, int bitmask) INLINE int dss_lfsr_function(discrete_device *dev, int myfunc, int in0, int in1, int bitmask)
{ {
int retval; int retval;
@ -410,7 +410,7 @@ INLINE int dss_lfsr_function(const discrete_info *disc_info, int myfunc, int in0
retval = retval ^ in0; /* xor in0 */ retval = retval ^ in0; /* xor in0 */
break; break;
default: default:
discrete_log(disc_info, "dss_lfsr_function - Invalid function type passed"); dev->discrete_log("dss_lfsr_function - Invalid function type passed");
retval=0; retval=0;
break; break;
} }
@ -432,7 +432,7 @@ DISCRETE_STEP(dss_lfsr)
if (info->clock_type == DISC_CLK_IS_FREQ) if (info->clock_type == DISC_CLK_IS_FREQ)
{ {
/* We need to keep clocking the internal clock even if disabled. */ /* We need to keep clocking the internal clock even if disabled. */
cycles = (context->t_left + node->info->sample_time) / context->t_clock; cycles = (context->t_left + node->sample_time()) / context->t_clock;
inc = (int)cycles; inc = (int)cycles;
context->t_left = (cycles - inc) * context->t_clock; context->t_left = (cycles - inc) * context->t_clock;
} }
@ -476,22 +476,22 @@ DISCRETE_STEP(dss_lfsr)
fbresult = (context->lfsr_reg >> info->bitlength) & 0x01; fbresult = (context->lfsr_reg >> info->bitlength) & 0x01;
/* Stage 2 feedback combine fbresultNew with infeed bit */ /* Stage 2 feedback combine fbresultNew with infeed bit */
fbresult = dss_lfsr_function(node->info, info->feedback_function1, fbresult, noise_feed, 0x01); fbresult = dss_lfsr_function(node->device, info->feedback_function1, fbresult, noise_feed, 0x01);
/* Stage 3 first we setup where the bit is going to be shifted into */ /* Stage 3 first we setup where the bit is going to be shifted into */
fbresult = fbresult * info->feedback_function2_mask; fbresult = fbresult * info->feedback_function2_mask;
/* Then we left shift the register, */ /* Then we left shift the register, */
context->lfsr_reg = context->lfsr_reg << 1; context->lfsr_reg = context->lfsr_reg << 1;
/* Now move the fbresult into the shift register and mask it to the bitlength */ /* Now move the fbresult into the shift register and mask it to the bitlength */
context->lfsr_reg = dss_lfsr_function(node->info, info->feedback_function2, fbresult, context->lfsr_reg, (1 << info->bitlength) - 1 ); context->lfsr_reg = dss_lfsr_function(node->device, info->feedback_function2, fbresult, context->lfsr_reg, (1 << info->bitlength) - 1 );
/* Now get and store the new feedback result */ /* Now get and store the new feedback result */
/* Fetch the feedback bits */ /* Fetch the feedback bits */
fb0 = (context->lfsr_reg >> info->feedback_bitsel0) & 0x01; fb0 = (context->lfsr_reg >> info->feedback_bitsel0) & 0x01;
fb1 = (context->lfsr_reg >> info->feedback_bitsel1) & 0x01; fb1 = (context->lfsr_reg >> info->feedback_bitsel1) & 0x01;
/* Now do the combo on them */ /* Now do the combo on them */
fbresult = dss_lfsr_function(node->info, info->feedback_function0, fb0, fb1, 0x01); fbresult = dss_lfsr_function(node->device, info->feedback_function0, fb0, fb1, 0x01);
context->lfsr_reg = dss_lfsr_function(node->info, DISC_LFSR_REPLACE, context->lfsr_reg, fbresult << info->bitlength, (2 << info->bitlength) - 1); context->lfsr_reg = dss_lfsr_function(node->device, DISC_LFSR_REPLACE, context->lfsr_reg, fbresult << info->bitlength, (2 << info->bitlength) - 1);
} }
/* Now select the output bit */ /* Now select the output bit */
@ -532,7 +532,7 @@ DISCRETE_RESET(dss_lfsr)
context->out_lfsr_reg = (info->flags & DISC_LFSR_FLAG_OUTPUT_SR_SN1) ? 1 : 0; context->out_lfsr_reg = (info->flags & DISC_LFSR_FLAG_OUTPUT_SR_SN1) ? 1 : 0;
if ((info->clock_type < DISC_CLK_ON_F_EDGE) || (info->clock_type > DISC_CLK_IS_FREQ)) if ((info->clock_type < DISC_CLK_ON_F_EDGE) || (info->clock_type > DISC_CLK_IS_FREQ))
discrete_log(node->info, "Invalid clock type passed in NODE_%d\n", node->index()); node->device->discrete_log("Invalid clock type passed in NODE_%d\n", node->index());
context->last = (DSS_COUNTER__CLOCK != 0); context->last = (DSS_COUNTER__CLOCK != 0);
if (info->clock_type == DISC_CLK_IS_FREQ) context->t_clock = 1.0 / DSS_LFSR_NOISE__CLOCK; if (info->clock_type == DISC_CLK_IS_FREQ) context->t_clock = 1.0 / DSS_LFSR_NOISE__CLOCK;
@ -545,8 +545,8 @@ DISCRETE_RESET(dss_lfsr)
fb0 = (context->lfsr_reg >> info->feedback_bitsel0) & 0x01; fb0 = (context->lfsr_reg >> info->feedback_bitsel0) & 0x01;
fb1=(context->lfsr_reg >> info->feedback_bitsel1) & 0x01; fb1=(context->lfsr_reg >> info->feedback_bitsel1) & 0x01;
/* Now do the combo on them */ /* Now do the combo on them */
fbresult = dss_lfsr_function(node->info, info->feedback_function0, fb0, fb1, 0x01); fbresult = dss_lfsr_function(node->device, info->feedback_function0, fb0, fb1, 0x01);
context->lfsr_reg=dss_lfsr_function(node->info, DISC_LFSR_REPLACE, context->lfsr_reg, fbresult << info->bitlength, (2<< info->bitlength ) - 1); context->lfsr_reg=dss_lfsr_function(node->device, DISC_LFSR_REPLACE, context->lfsr_reg, fbresult << info->bitlength, (2<< info->bitlength ) - 1);
/* Now select and setup the output bit */ /* Now select and setup the output bit */
node->output[0] = (context->lfsr_reg >> info->output_bit) & 0x01; node->output[0] = (context->lfsr_reg >> info->output_bit) & 0x01;
@ -586,7 +586,7 @@ DISCRETE_STEP(dss_noise)
if(context->phase > (2.0 * M_PI)) if(context->phase > (2.0 * M_PI))
{ {
/* GCC's rand returns a RAND_MAX value of 0x7fff */ /* GCC's rand returns a RAND_MAX value of 0x7fff */
int newval = (node->info->device->machine->rand() & 0x7fff) - 16384; int newval = (node->device->machine->rand() & 0x7fff) - 16384;
/* make sure the peak to peak values are the amplitude */ /* make sure the peak to peak values are the amplitude */
node->output[0] = DSS_NOISE__AMP / 2; node->output[0] = DSS_NOISE__AMP / 2;
@ -609,7 +609,7 @@ DISCRETE_STEP(dss_noise)
/* The enable input only curtails output, phase rotation still occurs. */ /* The enable input only curtails output, phase rotation still occurs. */
/* We allow the phase to exceed 2Pi here, so we can tell when to sample the noise. */ /* We allow the phase to exceed 2Pi here, so we can tell when to sample the noise. */
context->phase += ((2.0 * M_PI * DSS_NOISE__FREQ) / node->info->sample_rate); context->phase += ((2.0 * M_PI * DSS_NOISE__FREQ) / node->sample_rate());
} }
@ -653,10 +653,10 @@ DISCRETE_STEP(dss_note)
if (context->clock_type == DISC_CLK_IS_FREQ) if (context->clock_type == DISC_CLK_IS_FREQ)
{ {
/* We need to keep clocking the internal clock even if disabled. */ /* We need to keep clocking the internal clock even if disabled. */
cycles = (context->t_left + node->info->sample_time) / context->t_clock; cycles = (context->t_left + node->sample_time()) / context->t_clock;
inc = (int)cycles; inc = (int)cycles;
context->t_left = (cycles - inc) * context->t_clock; context->t_left = (cycles - inc) * context->t_clock;
if (inc) x_time = context->t_left / node->info->sample_time; if (inc) x_time = context->t_left / node->sample_time();
} }
else else
{ {
@ -791,7 +791,7 @@ DISCRETE_STEP(dss_op_amp_osc)
int count_f = 0; int count_f = 0;
int count_r = 0; int count_r = 0;
dt = node->info->sample_time; /* Change in time */ dt = node->sample_time(); /* Change in time */
v_cap = context->v_cap; /* Set to voltage before change */ v_cap = context->v_cap; /* Set to voltage before change */
/* work out the charge currents/voltages. */ /* work out the charge currents/voltages. */
@ -1000,7 +1000,7 @@ DISCRETE_STEP(dss_op_amp_osc)
v_cap = 0; v_cap = 0;
context->v_cap = v_cap; context->v_cap = v_cap;
x_time = dt / node->info->sample_time; x_time = dt / node->sample_time();
switch (context->output_type) switch (context->output_type)
{ {
@ -1053,7 +1053,7 @@ DISCRETE_RESET(dss_op_amp_osc)
{ {
if IS_VALUE_A_NODE(*r_info_ptr) if IS_VALUE_A_NODE(*r_info_ptr)
{ {
r_node = discrete_find_node(node->info, *r_info_ptr); r_node = node->device->discrete_find_node(*r_info_ptr);
*r_context_ptr = &(r_node->output[NODE_CHILD_NODE_NUM((int)*r_info_ptr)]); *r_context_ptr = &(r_node->output[NODE_CHILD_NODE_NUM((int)*r_info_ptr)]);
} }
else else
@ -1262,7 +1262,7 @@ DISCRETE_STEP(dss_sawtoothwave)
/* boils out to */ /* boils out to */
/* phase step = (2Pi*output freq)/sample freq) */ /* phase step = (2Pi*output freq)/sample freq) */
/* Also keep the new phasor in the 2Pi range. */ /* Also keep the new phasor in the 2Pi range. */
context->phase = fmod((context->phase + ((2.0 * M_PI * DSS_SAWTOOTHWAVE__FREQ) / node->info->sample_rate)), 2.0 * M_PI); context->phase = fmod((context->phase + ((2.0 * M_PI * DSS_SAWTOOTHWAVE__FREQ) / node->sample_rate())), 2.0 * M_PI);
} }
DISCRETE_RESET(dss_sawtoothwave) DISCRETE_RESET(dss_sawtoothwave)
@ -1443,7 +1443,7 @@ DISCRETE_STEP(dss_sinewave)
/* boils out to */ /* boils out to */
/* phase step = (2Pi*output freq)/sample freq) */ /* phase step = (2Pi*output freq)/sample freq) */
/* Also keep the new phasor in the 2Pi range. */ /* Also keep the new phasor in the 2Pi range. */
context->phase=fmod((context->phase + ((2.0 * M_PI * DSS_SINEWAVE__FREQ) / node->info->sample_rate)), 2.0 * M_PI); context->phase=fmod((context->phase + ((2.0 * M_PI * DSS_SINEWAVE__FREQ) / node->sample_rate())), 2.0 * M_PI);
} }
DISCRETE_RESET(dss_sinewave) DISCRETE_RESET(dss_sinewave)
@ -1510,7 +1510,7 @@ DISCRETE_STEP(dss_squarewave)
/* boils out to */ /* boils out to */
/* phase step = (2Pi*output freq)/sample freq) */ /* phase step = (2Pi*output freq)/sample freq) */
/* Also keep the new phasor in the 2Pi range. */ /* Also keep the new phasor in the 2Pi range. */
context->phase=fmod(context->phase + ((2.0 * M_PI * DSS_SQUAREWAVE__FREQ) / node->info->sample_rate), 2.0 * M_PI); context->phase=fmod(context->phase + ((2.0 * M_PI * DSS_SQUAREWAVE__FREQ) / node->sample_rate()), 2.0 * M_PI);
} }
DISCRETE_RESET(dss_squarewave) DISCRETE_RESET(dss_squarewave)
@ -1580,7 +1580,7 @@ DISCRETE_RESET(dss_squarewfix)
{ {
DISCRETE_DECLARE_CONTEXT(dss_squarewfix) DISCRETE_DECLARE_CONTEXT(dss_squarewfix)
context->sample_step = 1.0 / node->info->sample_rate; context->sample_step = 1.0 / node->sample_rate();
context->flip_flop = 1; context->flip_flop = 1;
/* Do the intial time shift and convert freq to off/on times */ /* Do the intial time shift and convert freq to off/on times */
@ -1643,7 +1643,7 @@ DISCRETE_STEP(dss_squarewave2)
/* phase step = 2Pi/(output period/sample period) */ /* phase step = 2Pi/(output period/sample period) */
/* boils out to */ /* boils out to */
/* phase step = 2Pi/(output period*sample freq) */ /* phase step = 2Pi/(output period*sample freq) */
newphase = context->phase + ((2.0 * M_PI) / ((DSS_SQUAREWAVE2__T_OFF + DSS_SQUAREWAVE2__T_ON) * node->info->sample_rate)); newphase = context->phase + ((2.0 * M_PI) / ((DSS_SQUAREWAVE2__T_OFF + DSS_SQUAREWAVE2__T_ON) * node->sample_rate()));
/* Keep the new phasor in the 2Pi range.*/ /* Keep the new phasor in the 2Pi range.*/
context->phase = fmod(newphase, 2.0 * M_PI); context->phase = fmod(newphase, 2.0 * M_PI);
@ -1809,7 +1809,7 @@ DISCRETE_STEP(dss_inverter_osc)
+ (vI - 0.7 - vG2) / context->rp); + (vI - 0.7 - vG2) / context->rp);
} }
diff = vMix - context->v_cap; diff = vMix - context->v_cap;
diff = diff - diff * exp(-node->info->sample_time / (context->c * rMix)); diff = diff - diff * exp(-node->sample_time() / (context->c * rMix));
break; break;
case DISC_OSC_INVERTER_IS_TYPE5: case DISC_OSC_INVERTER_IS_TYPE5:
/* FIXME handle r2 = 0 */ /* FIXME handle r2 = 0 */
@ -1823,7 +1823,7 @@ DISCRETE_STEP(dss_inverter_osc)
+ (vI + 0.7 - vG2) / context->rp); + (vI + 0.7 - vG2) / context->rp);
} }
diff = vMix - context->v_cap; diff = vMix - context->v_cap;
diff = diff - diff * exp(-node->info->sample_time/(context->c * rMix)); diff = diff - diff * exp(-node->sample_time()/(context->c * rMix));
break; break;
default: default:
fatalerror("DISCRETE_INVERTER_OSC - Wrong type on NODE_%02d", node->index()); fatalerror("DISCRETE_INVERTER_OSC - Wrong type on NODE_%02d", node->index());
@ -1846,8 +1846,8 @@ DISCRETE_RESET(dss_inverter_osc)
int i; int i;
/* exponent */ /* exponent */
context->w = exp(-node->info->sample_time / (DSS_INVERTER_OSC__RC * DSS_INVERTER_OSC__C)); context->w = exp(-node->sample_time() / (DSS_INVERTER_OSC__RC * DSS_INVERTER_OSC__C));
context->wc = exp(-node->info->sample_time / ((DSS_INVERTER_OSC__RC * DSS_INVERTER_OSC__RP) / (DSS_INVERTER_OSC__RP + DSS_INVERTER_OSC__RC) * DSS_INVERTER_OSC__C)); context->wc = exp(-node->sample_time() / ((DSS_INVERTER_OSC__RC * DSS_INVERTER_OSC__RP) / (DSS_INVERTER_OSC__RP + DSS_INVERTER_OSC__RC) * DSS_INVERTER_OSC__C));
node->output[0] = 0; node->output[0] = 0;
context->v_cap = 0; context->v_cap = 0;
context->v_g2_old = 0; context->v_g2_old = 0;
@ -1906,7 +1906,7 @@ DISCRETE_STEP(dss_trianglewave)
/* boils out to */ /* boils out to */
/* phase step = (2Pi*output freq)/sample freq) */ /* phase step = (2Pi*output freq)/sample freq) */
/* Also keep the new phasor in the 2Pi range. */ /* Also keep the new phasor in the 2Pi range. */
context->phase=fmod((context->phase + ((2.0 * M_PI * DSS_TRIANGLEWAVE__FREQ) / node->info->sample_rate)), 2.0 * M_PI); context->phase=fmod((context->phase + ((2.0 * M_PI * DSS_TRIANGLEWAVE__FREQ) / node->sample_rate())), 2.0 * M_PI);
} }
DISCRETE_RESET(dss_trianglewave) DISCRETE_RESET(dss_trianglewave)

View File

@ -81,8 +81,6 @@
* *
*************************************/ *************************************/
static void init_nodes(discrete_info *info, const linked_list_entry *block_list, device_t *device);
static node_description *discrete_find_node(const discrete_info *info, int node);
//static DEVICE_RESET( discrete ); //static DEVICE_RESET( discrete );
//static STREAM_UPDATE( discrete_stream_update ); //static STREAM_UPDATE( discrete_stream_update );
static STREAM_UPDATE( buffer_stream_update ); static STREAM_UPDATE( buffer_stream_update );
@ -95,18 +93,18 @@ static int profiling = 0;
* *
*************************************/ *************************************/
static void CLIB_DECL ATTR_PRINTF(2,3) discrete_log(const discrete_info *disc_info, const char *text, ...) void CLIB_DECL ATTR_PRINTF(2,3) discrete_device::discrete_log(const char *text, ...) const
{ {
if (DISCRETE_DEBUGLOG) if (DISCRETE_DEBUGLOG)
{ {
va_list arg; va_list arg;
va_start(arg, text); va_start(arg, text);
if(disc_info->disclogfile) if(m_disclogfile)
{ {
vfprintf(disc_info->disclogfile, text, arg); vfprintf(m_disclogfile, text, arg);
fprintf(disc_info->disclogfile, "\n"); fprintf(m_disclogfile, "\n");
fflush(disc_info->disclogfile); fflush(m_disclogfile);
} }
va_end(arg); va_end(arg);
@ -119,9 +117,9 @@ static void CLIB_DECL ATTR_PRINTF(2,3) discrete_log(const discrete_info *disc_in
* *
*************************************/ *************************************/
INLINE void linked_list_tail_add(const discrete_info *info, linked_list_entry ***list_tail_ptr, const void *ptr) INLINE void linked_list_tail_add(const discrete_device *info, linked_list_entry ***list_tail_ptr, const void *ptr)
{ {
**list_tail_ptr = auto_alloc(info->device->machine, linked_list_entry); **list_tail_ptr = auto_alloc(info->machine, linked_list_entry);
(**list_tail_ptr)->ptr = ptr; (**list_tail_ptr)->ptr = ptr;
(**list_tail_ptr)->next = NULL; (**list_tail_ptr)->next = NULL;
*list_tail_ptr = &((**list_tail_ptr)->next); *list_tail_ptr = &((**list_tail_ptr)->next);
@ -138,13 +136,13 @@ INLINE int linked_list_count(const linked_list_entry *list)
return cnt; return cnt;
} }
INLINE void linked_list_add(const discrete_info *info, linked_list_entry **list, const void *ptr) INLINE void linked_list_add(const discrete_device *info, linked_list_entry **list, const void *ptr)
{ {
linked_list_entry *entry; linked_list_entry *entry;
if (*list == NULL) if (*list == NULL)
{ {
*list = auto_alloc(info->device->machine, linked_list_entry); *list = auto_alloc(info->machine, linked_list_entry);
(*list)->ptr = ptr; (*list)->ptr = ptr;
(*list)->next = NULL; (*list)->next = NULL;
} }
@ -152,7 +150,7 @@ INLINE void linked_list_add(const discrete_info *info, linked_list_entry **list,
{ {
for (entry = *list; entry != NULL && entry->next != NULL; entry = entry->next) for (entry = *list; entry != NULL && entry->next != NULL; entry = entry->next)
; ;
entry->next = auto_alloc(info->device->machine, linked_list_entry); entry->next = auto_alloc(info->machine, linked_list_entry);
entry->next->ptr = ptr; entry->next->ptr = ptr;
entry->next->next = NULL; entry->next->next = NULL;
} }
@ -333,10 +331,10 @@ INLINE void step_nodes_in_list(node_list_t &list)
* *
*************************************/ *************************************/
static node_description *discrete_find_node(const discrete_info *info, int node) node_description *discrete_device::discrete_find_node(int node)
{ {
if (node < NODE_START || node > NODE_END) return NULL; if (node < NODE_START || node > NODE_END) return NULL;
return info->indexed_node[NODE_INDEX(node)]; return m_indexed_node[NODE_INDEX(node)];
} }
/************************************* /*************************************
@ -345,7 +343,7 @@ static node_description *discrete_find_node(const discrete_info *info, int node)
* *
*************************************/ *************************************/
static void discrete_build_list(discrete_info *info, const discrete_sound_block *intf, linked_list_entry ***current) void discrete_device::discrete_build_list(const discrete_sound_block *intf, linked_list_entry ***current)
{ {
int node_count = 0; int node_count = 0;
@ -354,8 +352,8 @@ static void discrete_build_list(discrete_info *info, const discrete_sound_block
/* scan imported */ /* scan imported */
if (intf[node_count].type == DSO_IMPORT) if (intf[node_count].type == DSO_IMPORT)
{ {
discrete_log(info, "discrete_build_list() - DISCRETE_IMPORT @ NODE_%02d", NODE_INDEX(intf[node_count].node) ); discrete_log("discrete_build_list() - DISCRETE_IMPORT @ NODE_%02d", NODE_INDEX(intf[node_count].node) );
discrete_build_list(info, (discrete_sound_block *) intf[node_count].custom, current); discrete_build_list((discrete_sound_block *) intf[node_count].custom, current);
} }
else if (intf[node_count].type == DSO_REPLACE) else if (intf[node_count].type == DSO_REPLACE)
{ {
@ -365,7 +363,7 @@ static void discrete_build_list(discrete_info *info, const discrete_sound_block
if (intf[node_count].type == DSS_NULL) if (intf[node_count].type == DSS_NULL)
fatalerror("discrete_build_list: DISCRETE_REPLACE at end of node_list"); fatalerror("discrete_build_list: DISCRETE_REPLACE at end of node_list");
for (entry = info->block_list; entry != NULL; entry = entry->next) for (entry = m_block_list; entry != NULL; entry = entry->next)
{ {
discrete_sound_block *block = (discrete_sound_block *) entry->ptr; discrete_sound_block *block = (discrete_sound_block *) entry->ptr;
@ -373,7 +371,7 @@ static void discrete_build_list(discrete_info *info, const discrete_sound_block
if (block->node == intf[node_count].node) if (block->node == intf[node_count].node)
{ {
entry->ptr = (void *) &intf[node_count]; entry->ptr = (void *) &intf[node_count];
discrete_log(info, "discrete_build_list() - DISCRETE_REPLACE @ NODE_%02d", NODE_INDEX(intf[node_count].node) ); discrete_log("discrete_build_list() - DISCRETE_REPLACE @ NODE_%02d", NODE_INDEX(intf[node_count].node) );
break; break;
} }
} }
@ -387,25 +385,25 @@ static void discrete_build_list(discrete_info *info, const discrete_sound_block
linked_list_entry *entry, *last; linked_list_entry *entry, *last;
last = NULL; last = NULL;
for (entry = info->block_list; entry != NULL; last = entry, entry = entry->next) for (entry = m_block_list; entry != NULL; last = entry, entry = entry->next)
{ {
discrete_sound_block *block = (discrete_sound_block *) entry->ptr; discrete_sound_block *block = (discrete_sound_block *) entry->ptr;
if ((block->node >= intf[node_count].input_node[0]) && if ((block->node >= intf[node_count].input_node[0]) &&
(block->node <= intf[node_count].input_node[1])) (block->node <= intf[node_count].input_node[1]))
{ {
discrete_log(info, "discrete_build_list() - DISCRETE_DELETE deleted NODE_%02d", NODE_INDEX(block->node) ); discrete_log("discrete_build_list() - DISCRETE_DELETE deleted NODE_%02d", NODE_INDEX(block->node) );
if (last != NULL) if (last != NULL)
last->next = entry->next; last->next = entry->next;
else else
info->block_list = entry->next; m_block_list = entry->next;
} }
} }
} }
else else
{ {
discrete_log(info, "discrete_build_list() - adding node %d (*current %p)\n", node_count, *current); discrete_log("discrete_build_list() - adding node %d (*current %p)\n", node_count, *current);
linked_list_tail_add(info, current, &intf[node_count]); linked_list_tail_add(this, current, &intf[node_count]);
} }
node_count++; node_count++;
@ -418,13 +416,13 @@ static void discrete_build_list(discrete_info *info, const discrete_sound_block
* *
*************************************/ *************************************/
static void discrete_sanity_check(const discrete_info *info) void discrete_device::discrete_sanity_check(void)
{ {
const linked_list_entry *entry; const linked_list_entry *entry;
int node_count = 0; int node_count = 0;
discrete_log(info, "discrete_start() - Doing node list sanity check"); discrete_log("discrete_start() - Doing node list sanity check");
for (entry = info->block_list; entry != NULL; entry = entry->next) for (entry = m_block_list; entry != NULL; entry = entry->next)
{ {
discrete_sound_block *block = (discrete_sound_block *) entry->ptr; discrete_sound_block *block = (discrete_sound_block *) entry->ptr;
@ -446,7 +444,7 @@ static void discrete_sanity_check(const discrete_info *info)
node_count++; node_count++;
} }
discrete_log(info, "discrete_start() - Sanity check counted %d nodes", node_count); discrete_log("discrete_start() - Sanity check counted %d nodes", node_count);
} }
@ -455,78 +453,6 @@ static void discrete_sanity_check(const discrete_info *info)
* Master discrete system start * Master discrete system start
* *
*************************************/ *************************************/
#if 0
static DEVICE_START( discrete )
{
linked_list_entry **intf;
const discrete_sound_block *intf_start = (discrete_sound_block *)device->baseconfig().static_config();
discrete_info *info = get_safe_token(device);
char name[32];
info->device = device;
/* If a clock is specified we will use it, otherwise run at the audio sample rate. */
if (device->clock())
info->sample_rate = device->clock();
else
info->sample_rate = device->machine->sample_rate;
info->sample_time = 1.0 / info->sample_rate;
info->neg_sample_time = - info->sample_time;
info->total_samples = 0;
info->total_stream_updates = 0;
/* create the logfile */
sprintf(name, "discrete%s.log", device->tag());
if (DISCRETE_DEBUGLOG)
info->disclogfile = fopen(name, "w");
/* enable profiling */
if (getenv("DISCRETE_PROFILING"))
profiling = atoi(getenv("DISCRETE_PROFILING"));
/* Build the final block list */
info->block_list = NULL;
intf = &info->block_list;
discrete_build_list(info, intf_start, &intf);
/* first pass through the nodes: sanity check, fill in the indexed_nodes, and make a total count */
discrete_sanity_check(info);
/* Start with empty lists */
info->node_list.reset();
info->output_list.reset();
info->input_list.reset();
/* allocate memory to hold pointers to nodes by index */
info->indexed_node = auto_alloc_array_clear(device->machine, node_description *, DISCRETE_MAX_NODES);
/* initialize the node data */
init_nodes(info, info->block_list, device);
/* now go back and find pointers to all input nodes */
for_each(node_description *, node, &info->node_list)
{
node.item()->find_input_nodes();
}
/* initialize the stream(s) */
info->discrete_stream = stream_create(device,info->input_list.count(), info->output_list.count(), info->sample_rate, info, discrete_stream_update);
/* allocate a queue */
info->queue = osd_work_queue_alloc(WORK_QUEUE_FLAG_MULTI | WORK_QUEUE_FLAG_HIGH_FREQ);
/* Process nodes which have a start func */
for_each(node_description *, node, &info->node_list)
{
if (node.item()->module->start)
(*node.item()->module->start)(node.item());
}
}
#endif
/************************************* /*************************************
@ -546,7 +472,7 @@ static UINT64 list_run_time(const node_list_t &list)
return total; return total;
} }
static void display_profiling(const discrete_info *info) void discrete_device::display_profiling(void)
{ {
int count; int count;
UINT64 total; UINT64 total;
@ -554,58 +480,29 @@ static void display_profiling(const discrete_info *info)
double tt; double tt;
/* calculate total time */ /* calculate total time */
total = list_run_time(info->node_list); total = list_run_time(m_node_list);
count = info->node_list.count(); count = m_node_list.count();
/* print statistics */ /* print statistics */
printf("Total Samples : %16" I64FMT "d\n", info->total_samples); printf("Total Samples : %16" I64FMT "d\n", m_total_samples);
tresh = total / count; tresh = total / count;
printf("Threshold (mean): %16" I64FMT "d\n", tresh / info->total_samples ); printf("Threshold (mean): %16" I64FMT "d\n", tresh / m_total_samples );
for_each(node_description *, node, &info->node_list) for_each(node_description *, node, &m_node_list)
{ {
if (node.item()->run_time > tresh) if (node.item()->run_time > tresh)
printf("%3d: %20s %8.2f %10.2f\n", node.item()->index(), node.item()->module->name, (float) node.item()->run_time / (float) total * 100.0, ((float) node.item()->run_time) / (float) info->total_samples); printf("%3d: %20s %8.2f %10.2f\n", node.item()->index(), node.item()->module->name, (float) node.item()->run_time / (float) total * 100.0, ((float) node.item()->run_time) / (float) m_total_samples);
} }
/* Task information */ /* Task information */
for_each(discrete_task *, task, &info->task_list) for_each(discrete_task *, task, &task_list)
{ {
tt = list_run_time(task.item()->list); tt = list_run_time(task.item()->list);
printf("Task(%d): %8.2f %15.2f\n", task.item()->task_group, tt / (double) total * 100.0, tt / (double) info->total_samples); printf("Task(%d): %8.2f %15.2f\n", task.item()->task_group, tt / (double) total * 100.0, tt / (double) m_total_samples);
} }
printf("Average samples/stream_update: %8.2f\n", (double) info->total_samples / (double) info->total_stream_updates); printf("Average samples/stream_update: %8.2f\n", (double) m_total_samples / (double) m_total_stream_updates);
} }
#if 0
static DEVICE_STOP( discrete )
{
discrete_info *info = get_safe_token(device);
osd_work_queue_free(info->queue);
if (profiling)
{
display_profiling(info);
}
/* Process nodes which have a stop func */
for_each(node_description *, node, &info->node_list)
{
if (node.item()->module->stop)
(*node.item()->module->stop)(node.item());
}
if (DISCRETE_DEBUGLOG)
{
/* close the debug log */
if (info->disclogfile)
fclose(info->disclogfile);
info->disclogfile = NULL;
}
}
#endif
/************************************* /*************************************
@ -613,26 +510,6 @@ static DEVICE_STOP( discrete )
* Master reset of all nodes * Master reset of all nodes
* *
*************************************/ *************************************/
#if 0
static DEVICE_RESET( discrete )
{
const discrete_info *info = get_safe_token(device);
/* loop over all nodes */
for_each (node_description *, node, &info->node_list)
{
node.item()->output[0] = 0;
/* if the node has a reset function, call it */
if (node.item()->module->reset)
(*node.item()->module->reset)(node.item());
/* otherwise, just step it */
else if (node.item()->step)
(*node.item()->step)(node.item());
}
}
#endif
/************************************* /*************************************
* *
@ -699,66 +576,6 @@ static STREAM_UPDATE( buffer_stream_update )
*(ptr++) = data; *(ptr++) = data;
} }
#if 0
static STREAM_UPDATE( discrete_stream_update )
{
discrete_info *info = (discrete_info *)param;
int outputnum;
//, task_group;
if (samples == 0)
return;
/* Setup any output streams */
outputnum = 0;
for_each(node_description *, node, &info->output_list)
{
node.item()->context = (void *) outputs[outputnum];
outputnum++;
}
/* Setup any input streams */
for_each(node_description *, node, &info->input_list)
{
struct dss_input_context *context = (struct dss_input_context *) node.item()->context;
context->ptr = (stream_sample_t *) inputs[context->stream_in_number];
}
/* Setup tasks */
for_each(discrete_task *, task, &info->task_list)
{
int i;
task.item()->samples = samples;
/* unlock the thread */
task.item()->unlock();
/* set up task buffers */
for (i = 0; i < task.item()->numbuffered; i++)
task.item()->ptr[i] = task.item()->node_buf[i];
/* initialize sources */
for_each(discrete_source_node *, sn, &task.item()->source_list)
{
sn.item()->ptr = sn.item()->task->node_buf[sn.item()->output_node];
}
}
for_each(discrete_task *, task, &info->task_list)
{
/* Fire a work item for each task */
osd_work_item_queue(info->queue, task_callback, (void *) &info->task_list, WORK_ITEM_FLAG_AUTO_RELEASE);
}
osd_work_queue_wait(info->queue, osd_ticks_per_second()*10);
if (profiling)
{
info->total_samples += samples;
info->total_stream_updates++;
}
}
#endif
/************************************* /*************************************
@ -768,7 +585,7 @@ static STREAM_UPDATE( discrete_stream_update )
*************************************/ *************************************/
static void init_nodes(discrete_info *info, const linked_list_entry *block_list, device_t *device) void discrete_device::init_nodes(const linked_list_entry *block_list)
{ {
const linked_list_entry *entry; const linked_list_entry *entry;
discrete_task *task = NULL; discrete_task *task = NULL;
@ -788,8 +605,8 @@ static void init_nodes(discrete_info *info, const linked_list_entry *block_list,
/* make sure we have one simple task /* make sure we have one simple task
* No need to create a node since there are no dependencies. * No need to create a node since there are no dependencies.
*/ */
task = auto_alloc_clear(info->device->machine, discrete_task); task = auto_alloc_clear(machine, discrete_task);
info->task_list.add_tail(task); task_list.add_tail(task);
} }
/* loop over all nodes */ /* loop over all nodes */
@ -805,7 +622,7 @@ static void init_nodes(discrete_info *info, const linked_list_entry *block_list,
if (module_list[modulenum].type != block->type) if (module_list[modulenum].type != block->type)
fatalerror("init_nodes() - Unable to find discrete module type %d for NODE_%02d", block->type, NODE_INDEX(block->node)); fatalerror("init_nodes() - Unable to find discrete module type %d for NODE_%02d", block->type, NODE_INDEX(block->node));
node_description *node = auto_alloc_clear(info->device->machine, node_description(info, &module_list[modulenum], block)); node_description *node = auto_alloc_clear(machine, node_description(this, &module_list[modulenum], block));
/* keep track of special nodes */ /* keep track of special nodes */
if (block->node == NODE_SPECIAL) if (block->node == NODE_SPECIAL)
@ -814,7 +631,7 @@ static void init_nodes(discrete_info *info, const linked_list_entry *block_list,
{ {
/* Output Node */ /* Output Node */
case DSO_OUTPUT: case DSO_OUTPUT:
info->output_list.add_tail(node); m_output_list.add_tail(node);
break; break;
/* CSVlog Node for debugging */ /* CSVlog Node for debugging */
@ -829,7 +646,7 @@ static void init_nodes(discrete_info *info, const linked_list_entry *block_list,
case DSO_TASK_START: case DSO_TASK_START:
if (task != NULL) if (task != NULL)
fatalerror("init_nodes() - Nested DISCRETE_START_TASK."); fatalerror("init_nodes() - Nested DISCRETE_START_TASK.");
task = auto_alloc_clear(info->device->machine, discrete_task); task = auto_alloc_clear(machine, discrete_task);
node->context = task; node->context = task;
break; break;
@ -839,7 +656,7 @@ static void init_nodes(discrete_info *info, const linked_list_entry *block_list,
task->numbuffered = 0; task->numbuffered = 0;
task->task_group = -1; /* will be set later */ task->task_group = -1; /* will be set later */
task->source_list.reset(); task->source_list.reset();
info->task_list.add_tail(task); task_list.add_tail(task);
node->context = task; node->context = task;
//task = NULL; //task = NULL;
break; break;
@ -852,23 +669,23 @@ static void init_nodes(discrete_info *info, const linked_list_entry *block_list,
/* otherwise, make sure we are not a duplicate, and put ourselves into the indexed list */ /* otherwise, make sure we are not a duplicate, and put ourselves into the indexed list */
else else
{ {
if (info->indexed_node[NODE_INDEX(block->node)]) if (m_indexed_node[NODE_INDEX(block->node)])
fatalerror("init_nodes() - Duplicate entries for NODE_%02d", NODE_INDEX(block->node)); fatalerror("init_nodes() - Duplicate entries for NODE_%02d", NODE_INDEX(block->node));
info->indexed_node[NODE_INDEX(block->node)] = node; m_indexed_node[NODE_INDEX(block->node)] = node;
} }
/* if we are an stream input node, track that */ /* if we are an stream input node, track that */
if (block->type == DSS_INPUT_STREAM) if (block->type == DSS_INPUT_STREAM)
{ {
info->input_list.add_tail(node); m_input_list.add_tail(node);
} }
else if (block->type == DSS_INPUT_BUFFER) else if (block->type == DSS_INPUT_BUFFER)
{ {
info->input_list.add_tail(node); m_input_list.add_tail(node);
} }
/* add to node list */ /* add to node list */
info->node_list.add_tail(node); m_node_list.add_tail(node);
/* our running order just follows the order specified */ /* our running order just follows the order specified */
/* does the node step ? */ /* does the node step ? */
@ -887,7 +704,7 @@ static void init_nodes(discrete_info *info, const linked_list_entry *block_list,
} }
/* and register save state */ /* and register save state */
node->save_state(device); node->save_state(this);
} }
if (!has_tasks) if (!has_tasks)
@ -895,7 +712,7 @@ static void init_nodes(discrete_info *info, const linked_list_entry *block_list,
} }
/* if no outputs, give an error */ /* if no outputs, give an error */
if (info->output_list.count() == 0) if (m_output_list.count() == 0)
fatalerror("init_nodes() - Couldn't find an output node"); fatalerror("init_nodes() - Couldn't find an output node");
} }
@ -906,10 +723,10 @@ static void init_nodes(discrete_info *info, const linked_list_entry *block_list,
* *
*************************************/ *************************************/
node_description::node_description(const discrete_info * xinfo, const discrete_module *xmodule, const discrete_sound_block *xblock) : node_description::node_description(discrete_device * pdev, const discrete_module *xmodule, const discrete_sound_block *xblock) :
context(NULL), context(NULL),
device(pdev),
module(xmodule), module(xmodule),
info(xinfo),
run_time(0), run_time(0),
m_block(xblock) m_block(xblock)
{ {
@ -931,6 +748,7 @@ node_description::node_description(const discrete_info * xinfo, const discrete_m
/* allocate memory if necessary */ /* allocate memory if necessary */
if (module->contextsize) if (module->contextsize)
context = global_alloc_array(UINT8, module->contextsize); context = global_alloc_array(UINT8, module->contextsize);
} }
node_description::~node_description(void) node_description::~node_description(void)
@ -962,7 +780,7 @@ void node_description::find_input_nodes(void)
/* if this input is node-based, find the node in the indexed list */ /* if this input is node-based, find the node in the indexed list */
if IS_VALUE_A_NODE(inputnode) if IS_VALUE_A_NODE(inputnode)
{ {
const node_description *node_ref = info->indexed_node[NODE_INDEX(inputnode)]; const node_description *node_ref = device->m_indexed_node[NODE_INDEX(inputnode)];
if (!node_ref) if (!node_ref)
fatalerror("discrete_start - NODE_%02d referenced a non existent node NODE_%02d", index(), NODE_INDEX(inputnode)); fatalerror("discrete_start - NODE_%02d referenced a non existent node NODE_%02d", index(), NODE_INDEX(inputnode));
@ -977,7 +795,7 @@ void node_description::find_input_nodes(void)
/* warn if trying to use a node for an input that can only be static */ /* warn if trying to use a node for an input that can only be static */
if IS_VALUE_A_NODE(m_block->initial[inputnum]) if IS_VALUE_A_NODE(m_block->initial[inputnum])
{ {
discrete_log(info, "Warning - discrete_start - NODE_%02d trying to use a node on static input %d", index(), inputnum); device->discrete_log("Warning - discrete_start - NODE_%02d trying to use a node on static input %d", index(), inputnum);
/* also report it in the error log so it is not missed */ /* also report it in the error log so it is not missed */
logerror("Warning - discrete_start - NODE_%02d trying to use a node on static input %d", index(), inputnum); logerror("Warning - discrete_start - NODE_%02d trying to use a node on static input %d", index(), inputnum);
} }
@ -995,15 +813,15 @@ void node_description::find_input_nodes(void)
} }
} }
int node_description::same_module_index(const node_list_t &list) int discrete_device::same_module_index(node_description &node)
{ {
int index = 0; int index = 0;
for_each(node_description *, n, &list) for_each(node_description *, n, &m_node_list)
{ {
if (n.item() == this) if (n.item() == &node)
return index; return index;
if (n.item()->module->type == this->module->type) if (n.item()->module->type == node.module->type)
index++; index++;
} }
return -1; return -1;
@ -1121,18 +939,16 @@ discrete_device::discrete_device(running_machine &_machine, const discrete_devic
discrete_device::~discrete_device(void) discrete_device::~discrete_device(void)
{ {
discrete_info *info = &m_info; osd_work_queue_free(m_queue);
osd_work_queue_free(info->queue);
if (profiling) if (profiling)
{ {
display_profiling(info); display_profiling();
} }
/* Process nodes which have a stop func */ /* Process nodes which have a stop func */
for_each(node_description *, node, &info->node_list) for_each(node_description *, node, &m_node_list)
{ {
if (node.item()->module->stop) if (node.item()->module->stop)
(*node.item()->module->stop)(node.item()); (*node.item()->module->stop)(node.item());
@ -1141,9 +957,9 @@ discrete_device::~discrete_device(void)
if (DISCRETE_DEBUGLOG) if (DISCRETE_DEBUGLOG)
{ {
/* close the debug log */ /* close the debug log */
if (info->disclogfile) if (m_disclogfile)
fclose(info->disclogfile); fclose(m_disclogfile);
info->disclogfile = NULL; m_disclogfile = NULL;
} }
} }
@ -1158,66 +974,63 @@ void discrete_device::device_start()
linked_list_entry **intf; linked_list_entry **intf;
const discrete_sound_block *intf_start = (discrete_sound_block *) baseconfig().static_config(); const discrete_sound_block *intf_start = (discrete_sound_block *) baseconfig().static_config();
discrete_info *info = &m_info;
char name[32]; char name[32];
info->device = this;
/* If a clock is specified we will use it, otherwise run at the audio sample rate. */ /* If a clock is specified we will use it, otherwise run at the audio sample rate. */
if (this->clock()) if (this->clock())
info->sample_rate = this->clock(); m_sample_rate = this->clock();
else else
info->sample_rate = this->machine->sample_rate; m_sample_rate = this->machine->sample_rate;
info->sample_time = 1.0 / info->sample_rate; m_sample_time = 1.0 / m_sample_rate;
info->neg_sample_time = - info->sample_time; m_neg_sample_time = - m_sample_time;
info->total_samples = 0; m_total_samples = 0;
info->total_stream_updates = 0; m_total_stream_updates = 0;
/* create the logfile */ /* create the logfile */
sprintf(name, "discrete%s.log", this->tag()); sprintf(name, "discrete%s.log", this->tag());
if (DISCRETE_DEBUGLOG) if (DISCRETE_DEBUGLOG)
info->disclogfile = fopen(name, "w"); m_disclogfile = fopen(name, "w");
/* enable profiling */ /* enable profiling */
if (getenv("DISCRETE_PROFILING")) if (getenv("DISCRETE_PROFILING"))
profiling = atoi(getenv("DISCRETE_PROFILING")); profiling = atoi(getenv("DISCRETE_PROFILING"));
/* Build the final block list */ /* Build the final block list */
info->block_list = NULL; m_block_list = NULL;
intf = &info->block_list; intf = &m_block_list;
discrete_build_list(info, intf_start, &intf); discrete_build_list(intf_start, &intf);
/* first pass through the nodes: sanity check, fill in the indexed_nodes, and make a total count */ /* first pass through the nodes: sanity check, fill in the indexed_nodes, and make a total count */
discrete_sanity_check(info); discrete_sanity_check();
/* Start with empty lists */ /* Start with empty lists */
info->node_list.reset(); m_node_list.reset();
info->output_list.reset(); m_output_list.reset();
info->input_list.reset(); m_input_list.reset();
/* allocate memory to hold pointers to nodes by index */ /* allocate memory to hold pointers to nodes by index */
info->indexed_node = auto_alloc_array_clear(this->machine, node_description *, DISCRETE_MAX_NODES); m_indexed_node = auto_alloc_array_clear(this->machine, node_description *, DISCRETE_MAX_NODES);
/* initialize the node data */ /* initialize the node data */
init_nodes(info, info->block_list, this); init_nodes(m_block_list);
/* now go back and find pointers to all input nodes */ /* now go back and find pointers to all input nodes */
for_each(node_description *, node, &info->node_list) for_each(node_description *, node, &m_node_list)
{ {
node.item()->find_input_nodes(); node.item()->find_input_nodes();
} }
/* initialize the stream(s) */ /* initialize the stream(s) */
info->discrete_stream = stream_create(this,info->input_list.count(), info->output_list.count(), info->sample_rate, this, static_stream_generate); discrete_stream = stream_create(this,m_input_list.count(), m_output_list.count(), m_sample_rate, this, static_stream_generate);
/* allocate a queue */ /* allocate a queue */
info->queue = osd_work_queue_alloc(WORK_QUEUE_FLAG_MULTI | WORK_QUEUE_FLAG_HIGH_FREQ); m_queue = osd_work_queue_alloc(WORK_QUEUE_FLAG_MULTI | WORK_QUEUE_FLAG_HIGH_FREQ);
/* Process nodes which have a start func */ /* Process nodes which have a start func */
for_each(node_description *, node, &info->node_list) for_each(node_description *, node, &m_node_list)
{ {
if (node.item()->module->start) if (node.item()->module->start)
(*node.item()->module->start)(node.item()); (*node.item()->module->start)(node.item());
@ -1232,11 +1045,10 @@ void discrete_device::device_start()
void discrete_device::device_reset() void discrete_device::device_reset()
{ {
const discrete_info *info = &m_info; stream_update(discrete_stream);
stream_update(info->discrete_stream);
/* loop over all nodes */ /* loop over all nodes */
for_each (node_description *, node, &info->node_list) for_each (node_description *, node, &m_node_list)
{ {
node.item()->output[0] = 0; node.item()->output[0] = 0;
@ -1262,7 +1074,6 @@ STREAM_UPDATE( discrete_device::static_stream_generate )
void discrete_device::stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples) void discrete_device::stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{ {
discrete_info *info = &m_info;
int outputnum; int outputnum;
//, task_group; //, task_group;
@ -1270,21 +1081,21 @@ void discrete_device::stream_generate(stream_sample_t **inputs, stream_sample_t
return; return;
/* Setup any output streams */ /* Setup any output streams */
outputnum = 0; outputnum = 0;
for_each(node_description *, node, &info->output_list) for_each(node_description *, node, &m_output_list)
{ {
node.item()->context = (void *) outputs[outputnum]; node.item()->context = (void *) outputs[outputnum];
outputnum++; outputnum++;
} }
/* Setup any input streams */ /* Setup any input streams */
for_each(node_description *, node, &info->input_list) for_each(node_description *, node, &m_input_list)
{ {
struct dss_input_context *context = (struct dss_input_context *) node.item()->context; struct dss_input_context *context = (struct dss_input_context *) node.item()->context;
context->ptr = (stream_sample_t *) inputs[context->stream_in_number]; context->ptr = (stream_sample_t *) inputs[context->stream_in_number];
} }
/* Setup tasks */ /* Setup tasks */
for_each(discrete_task *, task, &info->task_list) for_each(discrete_task *, task, &task_list)
{ {
int i; int i;
@ -1303,17 +1114,17 @@ void discrete_device::stream_generate(stream_sample_t **inputs, stream_sample_t
} }
} }
for_each(discrete_task *, task, &info->task_list) for_each(discrete_task *, task, &task_list)
{ {
/* Fire a work item for each task */ /* Fire a work item for each task */
osd_work_item_queue(info->queue, task_callback, (void *) &info->task_list, WORK_ITEM_FLAG_AUTO_RELEASE); osd_work_item_queue(m_queue, task_callback, (void *) &task_list, WORK_ITEM_FLAG_AUTO_RELEASE);
} }
osd_work_queue_wait(info->queue, osd_ticks_per_second()*10); osd_work_queue_wait(m_queue, osd_ticks_per_second()*10);
if (profiling) if (profiling)
{ {
info->total_samples += samples; m_total_samples += samples;
info->total_stream_updates++; m_total_stream_updates++;
} }
} }
@ -1323,8 +1134,7 @@ void discrete_device::stream_generate(stream_sample_t **inputs, stream_sample_t
READ8_MEMBER( discrete_device::read ) READ8_MEMBER( discrete_device::read )
{ {
discrete_info *info = &m_info; node_description *node = discrete_find_node(offset);
node_description *node = discrete_find_node(info, offset);
UINT8 data = 0; UINT8 data = 0;
@ -1332,7 +1142,7 @@ READ8_MEMBER( discrete_device::read )
if (node) if (node)
{ {
/* Bring the system up to now */ /* Bring the system up to now */
stream_update(info->discrete_stream); stream_update(discrete_stream);
data = (UINT8) node->output[NODE_CHILD_NODE_NUM(offset)]; data = (UINT8) node->output[NODE_CHILD_NODE_NUM(offset)];
} }
@ -1348,8 +1158,7 @@ READ8_MEMBER( discrete_device::read )
WRITE8_MEMBER( discrete_device::write ) WRITE8_MEMBER( discrete_device::write )
{ {
discrete_info *info = &m_info; node_description *node = discrete_find_node(offset);
node_description *node = discrete_find_node(info, offset);
/* Update the node input value if it's a proper input node */ /* Update the node input value if it's a proper input node */
if (node) if (node)
@ -1384,7 +1193,7 @@ WRITE8_MEMBER( discrete_device::write )
else else
{ {
/* Bring the system up to now */ /* Bring the system up to now */
stream_update(info->discrete_stream); stream_update(discrete_stream);
context->data = new_data; context->data = new_data;
@ -1395,6 +1204,6 @@ WRITE8_MEMBER( discrete_device::write )
} }
else else
{ {
discrete_log(info, "discrete_sound_w write to non-existent NODE_%02d\n", offset-NODE_00); discrete_log("discrete_sound_w write to non-existent NODE_%02d\n", offset-NODE_00);
} }
} }

View File

@ -3477,13 +3477,13 @@
*************************************/ *************************************/
/* calculate charge exponent using discrete sample time */ /* calculate charge exponent using discrete sample time */
#define RC_CHARGE_EXP(rc) (1.0 - exp((node)->info->neg_sample_time / (rc))) #define RC_CHARGE_EXP(rc) (1.0 - exp(-(node)->sample_time() / (rc)))
/* calculate charge exponent using given sample time */ /* calculate charge exponent using given sample time */
#define RC_CHARGE_EXP_DT(rc, dt) (1.0 - exp(-(dt) / (rc))) #define RC_CHARGE_EXP_DT(rc, dt) (1.0 - exp(-(dt) / (rc)))
#define RC_CHARGE_NEG_EXP_DT(rc, dt) (1.0 - exp((dt) / (rc))) #define RC_CHARGE_NEG_EXP_DT(rc, dt) (1.0 - exp((dt) / (rc)))
/* calculate discharge exponent using discrete sample time */ /* calculate discharge exponent using discrete sample time */
#define RC_DISCHARGE_EXP(rc) (exp((node)->info->neg_sample_time / (rc))) #define RC_DISCHARGE_EXP(rc) (exp(-(node)->sample_time() / (rc)))
/* calculate discharge exponent using given sample time */ /* calculate discharge exponent using given sample time */
#define RC_DISCHARGE_EXP_DT(rc, dt) (exp(-(dt) / (rc))) #define RC_DISCHARGE_EXP_DT(rc, dt) (exp(-(dt) / (rc)))
#define RC_DISCHARGE_NEG_EXP_DT(rc, dt) (exp((dt) / (rc))) #define RC_DISCHARGE_NEG_EXP_DT(rc, dt) (exp((dt) / (rc)))
@ -3868,73 +3868,13 @@ struct _discrete_sound_block
}; };
typedef struct _discrete_sound_block discrete_sound_block; typedef struct _discrete_sound_block discrete_sound_block;
/*************************************
*
* Internal structure of a node
*
*************************************/
typedef struct _discrete_module discrete_module; typedef struct _discrete_module discrete_module;
typedef struct _discrete_info discrete_info;
class node_description; class node_description;
typedef linked_list_t<node_description *> node_list_t; typedef linked_list_t<node_description *> node_list_t;
class node_description
{
public:
node_description(const discrete_info * info, const discrete_module *module, const discrete_sound_block *block);
~node_description(void);
/* Return the node index, i.e. X from NODE(X) */
int index(void);
/* Return the node number, i.e. NODE(X) */
inline int block_node(void) { return m_block->node; }
/* Return the node type */
inline int block_type(void) { return m_block->type; }
/* Custom function specific initialisation data */
inline const void *custom_data(void) { return m_custom; }
void find_input_nodes(void);
void save_state(device_t *device);
inline int input_node(int inputnum) { return m_block->input_node[inputnum]; }
/* FIXME: this is used by csv and wav logs - going forward, ids should be explicitly passed */
int same_module_index(const node_list_t &list);
/* The node's last output value */
double output[DISCRETE_MAX_OUTPUTS];
/* Called to execute one time delta of output update */
DISCRETE_FUNC((*step));
/* Contextual information specific to this node type */
void * context;
const double * input[DISCRETE_MAX_INPUTS]; /* Addresses of Input values */
/* Number of active inputs on this node type */
inline int active_inputs(void) { return m_active_inputs; }
/* Bit Flags. 1 in bit location means input_is_node */
inline int input_is_node(void) { return m_input_is_node; };
const discrete_module *module; /* Node's module info */
const discrete_info *info; /* Points to the parent */
osd_ticks_t run_time;
protected:
private:
const discrete_sound_block *m_block; /* Points to the node's setup block. */
int m_active_inputs; /* Number of active inputs on this node type */
/* Custom function specific initialisation data */
const void * m_custom;
int m_input_is_node;
};
/************************************* /*************************************
* *
@ -4018,48 +3958,6 @@ struct _discrete_source_node
double buffer; double buffer;
}; };
struct _discrete_info
{
device_t *device;
/* emulation info */
int sample_rate;
double sample_time;
double neg_sample_time;
/* internal node tracking */
node_description **indexed_node;
/* list of all nodes */
node_list_t node_list; /* node_description * */
/* list of discrete blocks after prescan (IMPORT, DELETE, REPLACE) */
linked_list_entry *block_list; /* discrete_sound_block * */
/* tasks */
task_list_t task_list; /* discrete_task_context * */
/* the input streams */
node_list_t input_list;
/* output node tracking */
node_list_t output_list;
/* the output stream */
sound_stream *discrete_stream;
/* debugging statistics */
FILE *disclogfile;
/* parallel tasks */
osd_work_queue *queue;
/* profiling */
UINT64 total_samples;
UINT64 total_stream_updates;
};
/************************************* /*************************************
* *
* Node-specific struct types * Node-specific struct types
@ -4566,8 +4464,6 @@ enum
* *
*************************************/ *************************************/
#define MCFG_SOUND_CONFIG_DISCRETE(name) MCFG_SOUND_CONFIG(name##_discrete_interface)
#define DISCRETE_SOUND_EXTERN(name) extern const discrete_sound_block name##_discrete_interface[] #define DISCRETE_SOUND_EXTERN(name) extern const discrete_sound_block name##_discrete_interface[]
#define DISCRETE_SOUND_START(name) const discrete_sound_block name##_discrete_interface[] = { #define DISCRETE_SOUND_START(name) const discrete_sound_block name##_discrete_interface[] = {
@ -4798,6 +4694,8 @@ READ8_DEVICE_HANDLER( discrete_sound_r );
#endif #endif
#define MCFG_SOUND_CONFIG_DISCRETE(name) MCFG_SOUND_CONFIG(name##_discrete_interface)
//************************************************************************** //**************************************************************************
// TYPE DEFINITIONS // TYPE DEFINITIONS
//************************************************************************** //**************************************************************************
@ -4831,6 +4729,7 @@ protected:
class discrete_device : public device_t, public device_sound_interface class discrete_device : public device_t, public device_sound_interface
{ {
friend class discrete_device_config; friend class discrete_device_config;
friend class node_description;
// construction/destruction // construction/destruction
discrete_device(running_machine &_machine, const discrete_device_config &config); discrete_device(running_machine &_machine, const discrete_device_config &config);
@ -4841,6 +4740,18 @@ public:
//sound_stream *m_stream; //sound_stream *m_stream;
virtual ~discrete_device(void); virtual ~discrete_device(void);
/* --------------------------------- */
void CLIB_DECL ATTR_PRINTF(2,3) discrete_log(const char *text, ...) const;
node_description *discrete_find_node(int node);
/* FIXME: this is used by csv and wav logs - going forward, identifiers should be explicitly passed */
int same_module_index(node_description &node);
/* the output stream */
sound_stream *discrete_stream;
/* tasks */
task_list_t task_list; /* discrete_task_context * */
protected: protected:
// device-level overrides // device-level overrides
@ -4854,11 +4765,43 @@ protected:
// internal state // internal state
const discrete_device_config &m_config; const discrete_device_config &m_config;
/* all for now */ /* --------------------------------- */
discrete_info m_info;
void discrete_build_list(const discrete_sound_block *intf, linked_list_entry ***current);
void discrete_sanity_check(void);
void display_profiling(void);
void init_nodes(const linked_list_entry *block_list);
/* emulation info */
int m_sample_rate;
double m_sample_time;
double m_neg_sample_time;
private: private:
/* internal node tracking */
node_description **m_indexed_node;
/* list of all nodes */
node_list_t m_node_list; /* node_description * */
/* list of discrete blocks after prescan (IMPORT, DELETE, REPLACE) */
linked_list_entry *m_block_list; /* discrete_sound_block * */
/* the input streams */
node_list_t m_input_list;
/* output node tracking */
node_list_t m_output_list;
/* debugging statistics */
FILE *m_disclogfile;
/* parallel tasks */
osd_work_queue *m_queue;
/* profiling */
UINT64 m_total_samples;
UINT64 m_total_stream_updates;
}; };
@ -4866,7 +4809,62 @@ private:
// device type definition // device type definition
extern const device_type DISCRETE; extern const device_type DISCRETE;
/*************************************
*
* Internal structure of a node
*
*************************************/
class node_description
{
public:
node_description(discrete_device * pdev, const discrete_module *module, const discrete_sound_block *block);
~node_description(void);
/* Return the node index, i.e. X from NODE(X) */
int index(void);
/* Return the node number, i.e. NODE(X) */
inline int block_node(void) { return m_block->node; }
/* Custom function specific initialisation data */
inline const void *custom_data(void) { return m_custom; }
void find_input_nodes(void);
void save_state(device_t *device);
inline int input_node(int inputnum) { return m_block->input_node[inputnum]; }
/* The node's last output value */
double output[DISCRETE_MAX_OUTPUTS];
/* Called to execute one time delta of output update */
DISCRETE_FUNC((*step));
/* Contextual information specific to this node type */
void * context;
const double * input[DISCRETE_MAX_INPUTS]; /* Addresses of Input values */
/* Number of active inputs on this node type */
inline int active_inputs(void) { return m_active_inputs; }
/* Bit Flags. 1 in bit location means input_is_node */
inline int input_is_node(void) { return m_input_is_node; };
inline double sample_time(void) { return device->m_sample_time; }
inline int sample_rate(void) { return device->m_sample_rate; }
discrete_device *device; /* Points to the parent */
const discrete_module *module; /* Node's module info */
osd_ticks_t run_time;
protected:
private:
const discrete_sound_block *m_block; /* Points to the node's setup block. */
int m_active_inputs; /* Number of active inputs on this node type */
/* Custom function specific initialisation data */
const void * m_custom;
int m_input_is_node;
};
//DECLARE_LEGACY_SOUND_DEVICE(DISCRETE, discrete);
#endif /* __DISCRETE_H__ */ #endif /* __DISCRETE_H__ */

View File

@ -291,7 +291,7 @@ DISCRETE_STEP(copsnrob_custom_noise)
int last_noise1_bit = (low_byte >> 4) & 0x01; int last_noise1_bit = (low_byte >> 4) & 0x01;
int last_noise2_bit = (low_byte >> 5) & 0x01; int last_noise2_bit = (low_byte >> 5) & 0x01;
t_used += node->info->sample_time; t_used += node->sample_time();
/* This clock will never run faster then the sample rate, /* This clock will never run faster then the sample rate,
* so we do not bother to check. * so we do not bother to check.
@ -316,7 +316,7 @@ DISCRETE_STEP(copsnrob_custom_noise)
context->high_byte = high_byte; context->high_byte = high_byte;
/* Convert last switch time to a ratio */ /* Convert last switch time to a ratio */
x_time = t_used / node->info->sample_time; x_time = t_used / node->sample_time();
/* use x_time if bit changed */ /* use x_time if bit changed */
new_noise_bit = (low_byte >> 4) & 0x01; new_noise_bit = (low_byte >> 4) & 0x01;
if (last_noise1_bit != new_noise_bit) if (last_noise1_bit != new_noise_bit)
@ -431,7 +431,7 @@ DISCRETE_STEP(copsnrob_zings_555_monostable)
/* discharge the overshoot */ /* discharge the overshoot */
v_cap = v_threshold; v_cap = v_threshold;
v_cap -= v_cap * RC_CHARGE_EXP_DT(rc, x_time); v_cap -= v_cap * RC_CHARGE_EXP_DT(rc, x_time);
x_time /= node->info->sample_time; x_time /= node->sample_time();
} }
} }
else else