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/opnassg.c | |
parent | 11a5698d68461b91a681f37d66fad5e206969674 (diff) |
added levelmeter
Diffstat (limited to 'libopna/opnassg.c')
-rw-r--r-- | libopna/opnassg.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libopna/opnassg.c b/libopna/opnassg.c index 86d9c9a..d92a8b8 100644 --- a/libopna/opnassg.c +++ b/libopna/opnassg.c @@ -134,6 +134,9 @@ void opna_ssg_resampler_reset(struct opna_ssg_resampler *resampler) { resampler->buf[i] = 0; } resampler->index = 0; + for (int c = 0; c < 3; c++) { + leveldata_init(&resampler->leveldata[c]); + } } void opna_ssg_writereg(struct opna_ssg *ssg, unsigned reg, unsigned val) { @@ -286,6 +289,7 @@ void opna_ssg_mix_55466( } } } + unsigned level[3] = {0}; for (int i = 0; i < samples; i++) { { int ssg_samples = ((resampler->index + 9)>>1) - ((resampler->index)>>1); @@ -305,6 +309,12 @@ void opna_ssg_mix_55466( opna_ssg_sinc_calc_func(resampler->index, resampler->buf, outbuf); for (int ch = 0; ch < 3; ch++) { if (oscillo) oscillo[ch].buf[offset+i] = outbuf[ch] >> 15; + int32_t nlevel = outbuf[ch]; + nlevel >>= 16; + nlevel *= 13000; + nlevel >>= 14; + if (nlevel < 0) nlevel = -nlevel; + if (((unsigned)nlevel) > level[ch]) level[ch] = nlevel; if (!(ssg->mask & (1<<ch))) sample += outbuf[ch] >> 2; } sample >>= 16; @@ -322,5 +332,8 @@ void opna_ssg_mix_55466( buf[i*2+0] = lo; buf[i*2+1] = ro; } + for (int c = 0; c < 3; c++) { + leveldata_update(&resampler->leveldata[c], level[c]); + } } #undef BUFINDEX |