adds DISCRETE_RCFILTER_SW to discrete sound

* this implements multiple RC networks with CD4066 switches to connect/disconnect capacitor
This commit is contained in:
Couriersud 2008-03-29 21:10:06 +00:00
parent a934d5cf95
commit 6a8fa36bcc
3 changed files with 107 additions and 2 deletions

View File

@ -91,6 +91,10 @@ struct dst_rcfilter_context
double vCap; double vCap;
}; };
struct dst_rcfilter_sw_context
{
double vCap[4];
};
/************************************************************************ /************************************************************************
* *
@ -1076,6 +1080,67 @@ static void dst_rcfilter_reset(node_description *node)
node->output = 0; node->output = 0;
} }
/************************************************************************
*
* DST_RCFILTER_SW - Usage of node_description values for switchable RC filter
*
* input[0] - Enable input value
* input[1] - input value
* input[2] - Resistor value (initialization only)
* input[3] - Capacitor Value (initialization only)
* input[4] - Voltage reference. Usually 0V.
*
************************************************************************/
#define DST_RCFILTER_SW__ENABLE (*(node->input[0]))
#define DST_RCFILTER_SW__VIN (*(node->input[1]))
#define DST_RCFILTER_SW__SWITCH (*(node->input[2]))
#define DST_RCFILTER_SW__R (*(node->input[3]))
#define DST_RCFILTER_SW__C(x) (*(node->input[4+x]))
#define CD4066_ON_RES 470
static void dst_rcfilter_sw_step(node_description *node)
{
struct dst_rcfilter_sw_context *context = node->context;
int i;
double rcexp;
double us=0, rs=0;
if(DST_RCFILTER_SW__ENABLE)
{
for (i=0;i<4;i++)
{
if ( ( (int)DST_RCFILTER_SW__SWITCH & (1<<i)) == 1)
{
us += context->vCap[i];
rs += DST_RCFILTER_SW__R;
}
}
node->output = CD4066_ON_RES / ( CD4066_ON_RES + rs) * DST_RCFILTER_SW__VIN + DST_RCFILTER_SW__R / (CD4066_ON_RES + rs) * us;
for (i=0;i<4;i++)
{
if ( ( (int)DST_RCFILTER_SW__SWITCH & (1<<i)) == 1)
{
rcexp = 1.0 - exp(-1.0 / ( CD4066_ON_RES * DST_RCFILTER_SW__C(i)) * discrete_current_context->sample_rate);
context->vCap[i] += ((node->output - context->vCap[i]) * rcexp);
}
}
}
else
{
node->output=0;
}
}
static void dst_rcfilter_sw_reset(node_description *node)
{
struct dst_rcfilter_sw_context *context = node->context;
int i;
for (i=0;i<4;i++)
context->vCap[i] = 0;
node->output = 0;
}
/* !!!!!!!!!!! NEW FILTERS for testing !!!!!!!!!!!!!!!!!!!!! */ /* !!!!!!!!!!! NEW FILTERS for testing !!!!!!!!!!!!!!!!!!!!! */

View File

@ -244,6 +244,7 @@ static const discrete_module module_list[] =
{ DST_RCINTEGRATE ,"DST_RCINTEGRATE" ,sizeof(struct dst_rcdisc_context) ,dst_rcintegrate_reset ,dst_rcintegrate_step }, { DST_RCINTEGRATE ,"DST_RCINTEGRATE" ,sizeof(struct dst_rcdisc_context) ,dst_rcintegrate_reset ,dst_rcintegrate_step },
{ DST_RCDISC_MOD ,"DST_RCDISC_MOD" ,sizeof(struct dst_rcdisc_context) ,dst_rcdisc_mod_reset ,dst_rcdisc_mod_step }, { DST_RCDISC_MOD ,"DST_RCDISC_MOD" ,sizeof(struct dst_rcdisc_context) ,dst_rcdisc_mod_reset ,dst_rcdisc_mod_step },
{ DST_RCFILTER ,"DST_RCFILTER" ,sizeof(struct dst_rcfilter_context) ,dst_rcfilter_reset ,dst_rcfilter_step }, { DST_RCFILTER ,"DST_RCFILTER" ,sizeof(struct dst_rcfilter_context) ,dst_rcfilter_reset ,dst_rcfilter_step },
{ DST_RCFILTER_SW ,"DST_RCFILTER_SW" ,sizeof(struct dst_rcfilter_sw_context) ,dst_rcfilter_sw_reset ,dst_rcfilter_sw_step },
/* For testing - seem to be buggered. Use versions not ending in N. */ /* For testing - seem to be buggered. Use versions not ending in N. */
{ DST_RCFILTERN ,"DST_RCFILTERN" ,sizeof(struct dss_filter1_context) ,dst_rcfilterN_reset ,dst_filter1_step }, { DST_RCFILTERN ,"DST_RCFILTERN" ,sizeof(struct dss_filter1_context) ,dst_rcfilterN_reset ,dst_filter1_step },
{ DST_RCDISCN ,"DST_RCDISCN" ,sizeof(struct dss_filter1_context) ,dst_rcdiscN_reset ,dst_rcdiscN_step }, { DST_RCDISCN ,"DST_RCDISCN" ,sizeof(struct dss_filter1_context) ,dst_rcdiscN_reset ,dst_rcdiscN_step },

View File

@ -2585,6 +2585,43 @@
* EXAMPLES: see Polaris * EXAMPLES: see Polaris
* *
*********************************************************************** ***********************************************************************
*
* DISCRETE_RCFILTER_SW - Multiple switchable RC filters
*
* R
* INPUT >-----------ZZZZ-+-------+----......-----> Output
* | |
* +-+ +-+
* SWITCH > Bit 0 ---->F1 | | F2 | |
* '-' ^ '-'
* Bit 1 ---------|----' |
* | |
* Bit ... --- ---
* --- C1 --- C2
* | |
* GND GND
*
*
* Declaration syntax
*
* DISCRETE_RCFILTER_SW(name of node,
* enable,
* input node (or value),
* switch node (or value),
* R in Ohms,
* C1 in Farads,
* C2 in Farads,
* C3 in Farads,
* C4 in Farads)
*
* This is a typical filter circuit in circusc or scramble.
* Switches are usually CD4066 with a "open" resistance of
* typical 470 Ohms at 5V.
* This circuit supports up to 4 filters.
*
* EXAMPLES: see circusc
*
***********************************************************************
======================================================================= =======================================================================
* from from disc_flt.c * from from disc_flt.c
* Component specific modules * Component specific modules
@ -3772,6 +3809,7 @@ enum
DST_RCINTEGRATE, /* NPN RC charge/discharge network */ DST_RCINTEGRATE, /* NPN RC charge/discharge network */
DST_RCDISC_MOD, /* Two diode mixer with Transistor and charge/discharge network */ DST_RCDISC_MOD, /* Two diode mixer with Transistor and charge/discharge network */
DST_RCFILTER, /* Simple RC Filter network */ DST_RCFILTER, /* Simple RC Filter network */
DST_RCFILTER_SW, /* Switcheable RC Filter network */
/* For testing - seem to be buggered. Use versions not ending in N. */ /* For testing - seem to be buggered. Use versions not ending in N. */
DST_RCFILTERN, /* Simple RC Filter network */ DST_RCFILTERN, /* Simple RC Filter network */
DST_RCDISCN, /* Simple RC discharge */ DST_RCDISCN, /* Simple RC discharge */
@ -3927,6 +3965,7 @@ enum
#define DISCRETE_RCINTEGRATE(NODE,ENAB,INP0,RVAL0,RVAL1,RVAL2,CVAL,vP,TYPE) { NODE, DST_RCINTEGRATE , 8, { ENAB,INP0,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC }, { ENAB,INP0,RVAL0,RVAL1,RVAL2,CVAL,vP,TYPE }, NULL, "RC Discharge 6" }, #define DISCRETE_RCINTEGRATE(NODE,ENAB,INP0,RVAL0,RVAL1,RVAL2,CVAL,vP,TYPE) { NODE, DST_RCINTEGRATE , 8, { ENAB,INP0,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC }, { ENAB,INP0,RVAL0,RVAL1,RVAL2,CVAL,vP,TYPE }, NULL, "RC Discharge 6" },
#define DISCRETE_RCDISC_MODULATED(NODE,ENAB,INP0,INP1,RVAL0,RVAL1,RVAL2,RVAL3,CVAL,VP) { NODE, DST_RCDISC_MOD , 9, { ENAB,INP0,INP1,RVAL0,RVAL1,RVAL2,RVAL3,CVAL,VP }, { ENAB,INP0,INP1,RVAL0,RVAL1,RVAL2,RVAL3,CVAL,VP }, NULL, "Modulated RC Discharge" }, #define DISCRETE_RCDISC_MODULATED(NODE,ENAB,INP0,INP1,RVAL0,RVAL1,RVAL2,RVAL3,CVAL,VP) { NODE, DST_RCDISC_MOD , 9, { ENAB,INP0,INP1,RVAL0,RVAL1,RVAL2,RVAL3,CVAL,VP }, { ENAB,INP0,INP1,RVAL0,RVAL1,RVAL2,RVAL3,CVAL,VP }, NULL, "Modulated RC Discharge" },
#define DISCRETE_RCFILTER(NODE,ENAB,INP0,RVAL,CVAL) { NODE, DST_RCFILTER , 4, { ENAB,INP0,NODE_NC,NODE_NC }, { ENAB,INP0,RVAL,CVAL }, NULL, "RC Filter" }, #define DISCRETE_RCFILTER(NODE,ENAB,INP0,RVAL,CVAL) { NODE, DST_RCFILTER , 4, { ENAB,INP0,NODE_NC,NODE_NC }, { ENAB,INP0,RVAL,CVAL }, NULL, "RC Filter" },
#define DISCRETE_RCFILTER_SW(NODE,ENAB,INP0,SW,RVAL,CVAL1,CVAL2,CVAL3,CVAL4) { NODE, DST_RCFILTER_SW, 8, { ENAB,INP0,SW,RVAL,CVAL1,CVAL2,CVAL3,CVAL4 }, { ENAB,INP0,SW,RVAL,CVAL1,CVAL2,CVAL3,CVAL4 }, NULL, "RC Filter Switch" },
#define DISCRETE_RCFILTER_VREF(NODE,ENAB,INP0,RVAL,CVAL,VREF) { NODE, DST_RCFILTER , 5, { ENAB,INP0,NODE_NC,NODE_NC,NODE_NC }, { ENAB,INP0,RVAL,CVAL,VREF }, NULL, "RC Filter to VREF" }, #define DISCRETE_RCFILTER_VREF(NODE,ENAB,INP0,RVAL,CVAL,VREF) { NODE, DST_RCFILTER , 5, { ENAB,INP0,NODE_NC,NODE_NC,NODE_NC }, { ENAB,INP0,RVAL,CVAL,VREF }, NULL, "RC Filter to VREF" },
/* For testing - seem to be buggered. Use versions not ending in N. */ /* For testing - seem to be buggered. Use versions not ending in N. */
#define DISCRETE_RCDISCN(NODE,ENAB,INP0,RVAL,CVAL) { NODE, DST_RCDISCN , 4, { ENAB,INP0,NODE_NC,NODE_NC }, { ENAB,INP0,RVAL,CVAL }, NULL, "RC Discharge (New Type)" }, #define DISCRETE_RCDISCN(NODE,ENAB,INP0,RVAL,CVAL) { NODE, DST_RCDISCN , 4, { ENAB,INP0,NODE_NC,NODE_NC }, { ENAB,INP0,RVAL,CVAL }, NULL, "RC Discharge (New Type)" },