diff --git a/chips/beeper.h b/chips/beeper.h index 90874c0..a058c8f 100644 --- a/chips/beeper.h +++ b/chips/beeper.h @@ -32,7 +32,7 @@ extern "C" { // error-accumulation precision boost #define BEEPER_FIXEDPOINT_SCALE (16) // DC adjust buffer size -#define BEEPER_DCADJ_BUFLEN (512) +#define BEEPER_DCADJ_BUFLEN (128) // initialization parameters typedef struct { @@ -107,20 +107,20 @@ void beeper_reset(beeper_t* b) { from the chip simulation which is >0.0 gets converted to a +/- sample value) */ -static float _beeper_dcadjust(beeper_t* bp, float s) { +static void _beeper_dcadjust(beeper_t* bp, float s) { bp->dcadj_sum -= bp->dcadj_buf[bp->dcadj_pos]; bp->dcadj_sum += s; bp->dcadj_buf[bp->dcadj_pos] = s; bp->dcadj_pos = (bp->dcadj_pos + 1) & (BEEPER_DCADJ_BUFLEN-1); - return s - (bp->dcadj_sum / BEEPER_DCADJ_BUFLEN); } bool beeper_tick(beeper_t* bp) { + _beeper_dcadjust(bp, (float)bp->state * bp->volume * bp->base_volume); /* generate a new sample? */ bp->counter -= BEEPER_FIXEDPOINT_SCALE; if (bp->counter <= 0) { bp->counter += bp->period; - bp->sample = _beeper_dcadjust(bp, (float)bp->state * bp->volume * bp->base_volume); + bp->sample = bp->dcadj_sum / BEEPER_DCADJ_BUFLEN; return true; } return false;