diff options
author | Takamichi Horikawa <takamichiho@gmail.com> | 2017-08-13 23:08:54 +0900 |
---|---|---|
committer | Takamichi Horikawa <takamichiho@gmail.com> | 2017-08-13 23:08:54 +0900 |
commit | 5a8af1f670709d6cd28ad5edda223d9ecbc03bc3 (patch) | |
tree | d8819443b937c49b5a4feb12ad54178d6f79a584 /libopna/opnaadpcm.c | |
parent | 11a5698d68461b91a681f37d66fad5e206969674 (diff) |
added levelmeter
Diffstat (limited to 'libopna/opnaadpcm.c')
-rw-r--r-- | libopna/opnaadpcm.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libopna/opnaadpcm.c b/libopna/opnaadpcm.c index 68dbae5..361064a 100644 --- a/libopna/opnaadpcm.c +++ b/libopna/opnaadpcm.c @@ -35,6 +35,7 @@ void opna_adpcm_reset(struct opna_adpcm *adpcm) { adpcm->prev_acc = 0; adpcm->adpcmd = 127; adpcm->out = 0; + leveldata_init(&adpcm->leveldata); } static uint32_t addr_conv(const struct opna_adpcm *adpcm, uint16_t a) { @@ -183,8 +184,14 @@ void opna_adpcm_writereg(struct opna_adpcm *adpcm, unsigned reg, unsigned val) { void opna_adpcm_mix(struct opna_adpcm *adpcm, int16_t *buf, unsigned samples) { if (!adpcm->ram) return; if (!(adpcm->control1 & C1_START)) return; + unsigned level = 0; for (unsigned i = 0; i < samples; i++) { adpcm_calc(adpcm); + { + int clevel = adpcm->out>>1; + if (clevel < 0) clevel = -clevel; + if (((unsigned)clevel) > level) level = clevel; + } if (!adpcm->masked) { int32_t lo = buf[i*2+0]; int32_t ro = buf[i*2+1]; @@ -199,6 +206,7 @@ void opna_adpcm_mix(struct opna_adpcm *adpcm, int16_t *buf, unsigned samples) { } if (!(adpcm->control1 & C1_START)) return; } + leveldata_update(&adpcm->leveldata, level); } void opna_adpcm_set_ram_256k(struct opna_adpcm *adpcm, void *ram) { |