mirror of
https://github.com/libretro/mame2003-plus-libretro.git
synced 2024-11-24 00:39:52 +00:00
Hopefully this will fix the build errors
This commit is contained in:
parent
99dfc6d319
commit
dd43fddb29
@ -132,3 +132,103 @@ filter* filter_lp_fir_alloc(double freq, int order) {
|
|||||||
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void filter2_setup(int type, double fc, double d, double gain,
|
||||||
|
struct filter2_context *filter)
|
||||||
|
{
|
||||||
|
double w; /* cutoff freq, in radians/sec */
|
||||||
|
double w_squared;
|
||||||
|
double den; /* temp variable */
|
||||||
|
double two_over_T = 2*Machine->sample_rate;
|
||||||
|
double two_over_T_squared = two_over_T * two_over_T;
|
||||||
|
|
||||||
|
/* calculate digital filter coefficents */
|
||||||
|
/*w = 2.0*M_PI*fc; no pre-warping */
|
||||||
|
w = Machine->sample_rate*2.0*tan(M_PI*fc/Machine->sample_rate); /* pre-warping */
|
||||||
|
w_squared = w*w;
|
||||||
|
|
||||||
|
den = two_over_T_squared + d*w*two_over_T + w_squared;
|
||||||
|
|
||||||
|
filter->a1 = 2.0*(-two_over_T_squared + w_squared)/den;
|
||||||
|
filter->a2 = (two_over_T_squared - d*w*two_over_T + w_squared)/den;
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case FILTER_LOWPASS:
|
||||||
|
filter->b0 = filter->b2 = w_squared/den;
|
||||||
|
filter->b1 = 2.0*(filter->b0);
|
||||||
|
break;
|
||||||
|
case FILTER_BANDPASS:
|
||||||
|
filter->b0 = d*w*two_over_T/den;
|
||||||
|
filter->b1 = 0.0;
|
||||||
|
filter->b2 = -(filter->b0);
|
||||||
|
break;
|
||||||
|
case FILTER_HIGHPASS:
|
||||||
|
filter->b0 = filter->b2 = two_over_T_squared/den;
|
||||||
|
filter->b1 = -2.0*(filter->b0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
logerror("filter2_setup() - Invalid filter type for 2nd order filter.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
filter->b0 *= gain;
|
||||||
|
filter->b1 *= gain;
|
||||||
|
filter->b2 *= gain;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Reset the input/output voltages to 0. */
|
||||||
|
void filter2_reset(struct filter2_context *filter)
|
||||||
|
{
|
||||||
|
filter->x0 = 0;
|
||||||
|
filter->x1 = 0;
|
||||||
|
filter->x2 = 0;
|
||||||
|
filter->y0 = 0;
|
||||||
|
filter->y1 = 0;
|
||||||
|
filter->y2 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Step the filter. */
|
||||||
|
void filter2_step(struct filter2_context *filter)
|
||||||
|
{
|
||||||
|
filter->y0 = -filter->a1 * filter->y1 - filter->a2 * filter->y2 +
|
||||||
|
filter->b0 * filter->x0 + filter->b1 * filter->x1 + filter->b2 * filter->x2;
|
||||||
|
filter->x2 = filter->x1;
|
||||||
|
filter->x1 = filter->x0;
|
||||||
|
filter->y2 = filter->y1;
|
||||||
|
filter->y1 = filter->y0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Setup a filter2 structure based on an op-amp multipole bandpass circuit. */
|
||||||
|
void filter_opamp_m_bandpass_setup(double r1, double r2, double r3, double c1, double c2,
|
||||||
|
struct filter2_context *filter)
|
||||||
|
{
|
||||||
|
double r_in, fc, d, gain;
|
||||||
|
|
||||||
|
if (r1 == 0)
|
||||||
|
{
|
||||||
|
logerror("filter_opamp_m_bandpass_setup() - r1 can not be 0");
|
||||||
|
return; /* Filter can not be setup. Undefined results. */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r2 == 0)
|
||||||
|
{
|
||||||
|
gain = 1;
|
||||||
|
r_in = r1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gain = r2 / (r1 + r2);
|
||||||
|
r_in = 1.0 / (1.0/r1 + 1.0/r2);
|
||||||
|
}
|
||||||
|
|
||||||
|
fc = 1.0 / (2 * M_PI * sqrt(r_in * r3 * c1 * c2));
|
||||||
|
d = (c1 + c2) / sqrt(r3 / r_in * c1 * c2);
|
||||||
|
gain *= -r3 / r_in * c2 / (c1 + c2);
|
||||||
|
|
||||||
|
filter2_setup(FILTER_BANDPASS, fc, d, gain, filter);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user