rudimentary VU meters
This commit is contained in:
parent
94d378d4ce
commit
10ea0b5f65
2 changed files with 17 additions and 1 deletions
|
|
@ -11,9 +11,9 @@ todo:
|
||||||
- 8x
|
- 8x
|
||||||
- others?
|
- others?
|
||||||
- various other XM effects are missing but nonessential
|
- various other XM effects are missing but nonessential
|
||||||
- vu meters
|
|
||||||
- oscilloscopes
|
- oscilloscopes
|
||||||
</pre>
|
</pre>
|
||||||
|
<canvas id='vu' width=300 height=64></canvas>
|
||||||
<pre id='debug'>
|
<pre id='debug'>
|
||||||
</pre>
|
</pre>
|
||||||
<pre id='pattern'>
|
<pre id='pattern'>
|
||||||
|
|
|
||||||
16
xm.js
16
xm.js
|
|
@ -268,6 +268,7 @@ function audio_cb(e) {
|
||||||
dataR.fill(0);
|
dataR.fill(0);
|
||||||
var offset = 0;
|
var offset = 0;
|
||||||
var ticklen = 0|(f_smp * 2.5 / bpm);
|
var ticklen = 0|(f_smp * 2.5 / bpm);
|
||||||
|
var VU = new Float32Array(nchan);
|
||||||
|
|
||||||
while(buflen > 0) {
|
while(buflen > 0) {
|
||||||
if (cur_ticksamp >= ticklen) {
|
if (cur_ticksamp >= ticklen) {
|
||||||
|
|
@ -303,6 +304,7 @@ function audio_cb(e) {
|
||||||
continue;
|
continue;
|
||||||
var k = ch.off;
|
var k = ch.off;
|
||||||
var dk = ch.doff;
|
var dk = ch.doff;
|
||||||
|
var Vrms = 0;
|
||||||
// console.log(j, offset, ch);
|
// console.log(j, offset, ch);
|
||||||
for (var i = offset; i < offset+tickduration; i++) {
|
for (var i = offset; i < offset+tickduration; i++) {
|
||||||
if (ch.mute) break;
|
if (ch.mute) break;
|
||||||
|
|
@ -324,6 +326,7 @@ function audio_cb(e) {
|
||||||
ch.vRprev = volR;
|
ch.vRprev = volR;
|
||||||
dataL[i] += ch.vL * si;
|
dataL[i] += ch.vL * si;
|
||||||
dataR[i] += ch.vR * si;
|
dataR[i] += ch.vR * si;
|
||||||
|
Vrms += ch.vL * ch.vR * si * si;
|
||||||
k += dk;
|
k += dk;
|
||||||
if (k >= sample_end) { // TODO: implement pingpong looping
|
if (k >= sample_end) { // TODO: implement pingpong looping
|
||||||
if (loop) {
|
if (loop) {
|
||||||
|
|
@ -353,11 +356,24 @@ function audio_cb(e) {
|
||||||
}
|
}
|
||||||
ch.off = k;
|
ch.off = k;
|
||||||
ch.doff = dk;
|
ch.doff = dk;
|
||||||
|
VU[j] += Vrms;
|
||||||
}
|
}
|
||||||
offset += tickduration;
|
offset += tickduration;
|
||||||
cur_ticksamp += tickduration;
|
cur_ticksamp += tickduration;
|
||||||
buflen -= tickduration;
|
buflen -= tickduration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update VU meters
|
||||||
|
var canvas = document.getElementById("vu");
|
||||||
|
var ctx = canvas.getContext("2d");
|
||||||
|
ctx.fillStyle = '#000';
|
||||||
|
ctx.fillRect(0, 0, 300, 64);
|
||||||
|
ctx.fillStyle = '#0f0';
|
||||||
|
for (var j = 0; j < nchan; j++) {
|
||||||
|
var rms = VU[j] / e.outputBuffer.length;
|
||||||
|
var y = -Math.log(rms)*10;
|
||||||
|
ctx.fillRect(j*16, y, 15, 64-y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function eff_t0_0(ch, data) { // arpeggio
|
function eff_t0_0(ch, data) { // arpeggio
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue