Make bs2b_cross_feed inline

This commit is contained in:
Chris Robinson 2014-06-10 12:46:58 -07:00
parent d0fac3fe1d
commit dfded9595c
2 changed files with 35 additions and 45 deletions

View File

@ -32,16 +32,6 @@
#define M_PI 3.14159265358979323846 #define M_PI 3.14159265358979323846
#endif #endif
/* Single pole IIR filter.
* O[n] = a0*I[n] + a1*I[n-1] + b1*O[n-1]
*/
/* Lowpass filter */
#define lo_filter(in, out_1) (bs2b->a0_lo*(in) + bs2b->b1_lo*(out_1))
/* Highboost filter */
#define hi_filter(in, in_1, out_1) (bs2b->a0_hi*(in) + bs2b->a1_hi*(in_1) + bs2b->b1_hi*(out_1))
/* Set up all data. */ /* Set up all data. */
static void init(struct bs2b *bs2b) static void init(struct bs2b *bs2b)
{ {
@ -49,7 +39,7 @@ static void init(struct bs2b *bs2b)
double G_lo, G_hi; double G_lo, G_hi;
double x; double x;
if ((bs2b->srate > 192000) || (bs2b->srate < 2000)) if(bs2b->srate > 192000 || bs2b->srate < 2000)
bs2b->srate = BS2B_DEFAULT_SRATE; bs2b->srate = BS2B_DEFAULT_SRATE;
switch(bs2b->level) switch(bs2b->level)
@ -151,35 +141,4 @@ void bs2b_clear(struct bs2b *bs2b)
memset(&bs2b->last_sample, 0, sizeof(bs2b->last_sample)); memset(&bs2b->last_sample, 0, sizeof(bs2b->last_sample));
} /* bs2b_clear */ } /* bs2b_clear */
void bs2b_cross_feed(struct bs2b *bs2b, float *sample) extern inline void bs2b_cross_feed(struct bs2b *bs2b, float *restrict samples);
{
/* Lowpass filter */
bs2b->last_sample.lo[0] = lo_filter(sample[0], bs2b->last_sample.lo[0]);
bs2b->last_sample.lo[1] = lo_filter(sample[1], bs2b->last_sample.lo[1]);
/* Highboost filter */
bs2b->last_sample.hi[0] = hi_filter(sample[0], bs2b->last_sample.asis[0], bs2b->last_sample.hi[0]);
bs2b->last_sample.hi[1] = hi_filter(sample[1], bs2b->last_sample.asis[1], bs2b->last_sample.hi[1]);
bs2b->last_sample.asis[0] = sample[0];
bs2b->last_sample.asis[1] = sample[1];
/* Crossfeed */
sample[0] = (float)(bs2b->last_sample.hi[0] + bs2b->last_sample.lo[1]);
sample[1] = (float)(bs2b->last_sample.hi[1] + bs2b->last_sample.lo[0]);
/* Bass boost cause allpass attenuation */
sample[0] *= bs2b->gain;
sample[1] *= bs2b->gain;
/* Clipping of overloaded samples */
#if 0
if (sample[0] > 1.0)
sample[0] = 1.0;
if (sample[0] < -1.0)
sample[0] = -1.0;
if (sample[1] > 1.0)
sample[1] = 1.0;
if (sample[1] < -1.0)
sample[1] = -1.0;
#endif
} /* bs2b_cross_feed */

View File

@ -96,8 +96,39 @@ void bs2b_clear(struct bs2b *bs2b);
* Returns crossfided samle by sample pointer. * Returns crossfided samle by sample pointer.
*/ */
/* sample poits to floats */ /* sample points to floats */
void bs2b_cross_feed(struct bs2b *bs2b, float *sample); inline void bs2b_cross_feed(struct bs2b *bs2b, float *restrict samples)
{
/* Single pole IIR filter.
* O[n] = a0*I[n] + a1*I[n-1] + b1*O[n-1]
*/
/* Lowpass filter */
#define lo_filter(in, out_1) (bs2b->a0_lo*(in) + bs2b->b1_lo*(out_1))
/* Highboost filter */
#define hi_filter(in, in_1, out_1) (bs2b->a0_hi*(in) + bs2b->a1_hi*(in_1) + bs2b->b1_hi*(out_1))
/* Lowpass filter */
bs2b->last_sample.lo[0] = lo_filter(samples[0], bs2b->last_sample.lo[0]);
bs2b->last_sample.lo[1] = lo_filter(samples[1], bs2b->last_sample.lo[1]);
/* Highboost filter */
bs2b->last_sample.hi[0] = hi_filter(samples[0], bs2b->last_sample.asis[0], bs2b->last_sample.hi[0]);
bs2b->last_sample.hi[1] = hi_filter(samples[1], bs2b->last_sample.asis[1], bs2b->last_sample.hi[1]);
bs2b->last_sample.asis[0] = samples[0];
bs2b->last_sample.asis[1] = samples[1];
/* Crossfeed */
samples[0] = (float)(bs2b->last_sample.hi[0] + bs2b->last_sample.lo[1]);
samples[1] = (float)(bs2b->last_sample.hi[1] + bs2b->last_sample.lo[0]);
/* Bass boost cause allpass attenuation */
samples[0] *= bs2b->gain;
samples[1] *= bs2b->gain;
#undef hi_filter
#undef lo_filter
} /* bs2b_cross_feed */
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */