speaker: 'mix' the current sample

If multiple clicks are on the same sample, mix them together

Signed-off-by: Michel Pollet <buserror@gmail.com>
This commit is contained in:
Michel Pollet 2023-10-29 04:54:05 +00:00
parent abc119b0b7
commit 71ae3b5d10

View File

@ -164,9 +164,16 @@ mii_speaker_click(
// fill from start of this frame to newly calculated sample_index // fill from start of this frame to newly calculated sample_index
for (; f->fill < sample_index && f->fill < s->fsize; f->fill++) for (; f->fill < sample_index && f->fill < s->fsize; f->fill++)
f->audio[f->fill] = s->sample * s->vol_multiplier; f->audio[f->fill] = s->sample * s->vol_multiplier;
f->audio[sample_index] = 0;
} }
s->sample ^= 0xffff; 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;
} }