Skip to content

Commit

Permalink
Merge branch 'leiradel-always_sample'
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Jul 4, 2024
2 parents 2b9889b + 5268da0 commit 3dee6d2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions chips/beeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3dee6d2

Please sign in to comment.