From b40451593114bc08a03a8c9db5263b20dc043b67 Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Thu, 4 Jul 2024 14:57:14 +0100 Subject: [PATCH 1/3] Sample at every tick --- chips/beeper.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chips/beeper.h b/chips/beeper.h index b301e9b5..b0343d0f 100644 --- a/chips/beeper.h +++ b/chips/beeper.h @@ -116,11 +116,12 @@ static float _beeper_dcadjust(beeper_t* bp, float s) { } 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; From 7778cc959b645ab751f5daba78211a8041833d81 Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Thu, 4 Jul 2024 14:57:25 +0100 Subject: [PATCH 2/3] Remove unnecessary return value --- chips/beeper.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/chips/beeper.h b/chips/beeper.h index b0343d0f..e207861e 100644 --- a/chips/beeper.h +++ b/chips/beeper.h @@ -107,12 +107,11 @@ 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) { From 268d5da58155f05967d18ab7fc599c9869977684 Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Thu, 4 Jul 2024 14:57:37 +0100 Subject: [PATCH 3/3] Reduce the buffer size --- chips/beeper.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chips/beeper.h b/chips/beeper.h index e207861e..a058c8ff 100644 --- a/chips/beeper.h +++ b/chips/beeper.h @@ -20,7 +20,7 @@ 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source - distribution. + distribution. */ #include #include @@ -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 {