aboutsummaryrefslogtreecommitdiff
path: root/libopna/opnadrum.c
diff options
context:
space:
mode:
authorTakamichi Horikawa <takamichiho@gmail.com>2017-08-13 23:08:54 +0900
committerTakamichi Horikawa <takamichiho@gmail.com>2017-08-13 23:08:54 +0900
commit5a8af1f670709d6cd28ad5edda223d9ecbc03bc3 (patch)
treed8819443b937c49b5a4feb12ad54178d6f79a584 /libopna/opnadrum.c
parent11a5698d68461b91a681f37d66fad5e206969674 (diff)
added levelmeter
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) {