From 71ae3b5d10a12e21028dac33fb029c6246f20e53 Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Sun, 29 Oct 2023 04:54:05 +0000 Subject: [PATCH] speaker: 'mix' the current sample If multiple clicks are on the same sample, mix them together Signed-off-by: Michel Pollet --- src/mii_speaker.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mii_speaker.c b/src/mii_speaker.c index c7ffa7b..73f9016 100644 --- a/src/mii_speaker.c +++ b/src/mii_speaker.c @@ -164,9 +164,16 @@ mii_speaker_click( // fill from start of this frame to newly calculated sample_index for (; f->fill < sample_index && f->fill < s->fsize; f->fill++) f->audio[f->fill] = s->sample * s->vol_multiplier; + f->audio[sample_index] = 0; } s->sample ^= 0xffff; - f->audio[sample_index] = s->sample * s->vol_multiplier; + // if we are touching a new sample, make sure the next one is clear too. + if (!f->audio[sample_index] && sample_index < s->fsize) + f->audio[sample_index + 1] = 0; + int32_t mix = f->audio[sample_index] + (s->sample * s->vol_multiplier); + if (mix > 0x7fff) mix = 0x7fff; + else if (mix < -0x8000) mix = -0x8000; + f->audio[sample_index] = mix; }