aboutsummaryrefslogtreecommitdiff
path: root/libopna/opnadrum.c
diff options
context:
space:
mode:
Diffstat (limited to 'libopna/opnadrum.c')
-rw-r--r--libopna/opnadrum.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/libopna/opnadrum.c b/libopna/opnadrum.c
index 1a298af..c3e8d38 100644
--- a/libopna/opnadrum.c
+++ b/libopna/opnadrum.c
@@ -23,6 +23,7 @@ void opna_drum_reset(struct opna_drum *drum) {
drum->drums[d].level = 0;
drum->drums[d].left = false;
drum->drums[d].right = false;
+ leveldata_init(&drum->drums[d].leveldata);
}
drum->total_level = 0;
drum->mask = 0;
@@ -81,6 +82,7 @@ void opna_drum_set_rom(struct opna_drum *drum, void *romptr) {
}
void opna_drum_mix(struct opna_drum *drum, int16_t *buf, int samples) {
+ unsigned levels[6] = {0};
for (int i = 0; i < samples; i++) {
int32_t lo = buf[i*2+0];
int32_t ro = buf[i*2+1];
@@ -91,6 +93,8 @@ void opna_drum_mix(struct opna_drum *drum, int16_t *buf, int samples) {
unsigned level = (drum->drums[d].level^0x1f) + (drum->total_level^0x3f);
co *= 15 - (level&7);
co >>= 1+(level>>3);
+ unsigned outlevel = co > 0 ? co : -co;
+ if (outlevel > levels[d]) levels[d] = outlevel;
if (!(drum->mask & (1u << d))) {
if (drum->drums[d].left) lo += co;
if (drum->drums[d].right) ro += co;
@@ -109,6 +113,9 @@ void opna_drum_mix(struct opna_drum *drum, int16_t *buf, int samples) {
buf[i*2+0] = lo;
buf[i*2+1] = ro;
}
+ for (int d = 0; d < 6; d++) {
+ leveldata_update(&drum->drums[d].leveldata, levels[d]);
+ }
}
void opna_drum_writereg(struct opna_drum *drum, unsigned reg, unsigned val) {