From b04e6c00b0824d3dc409b48e8c3cdba5854ce3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Hillerstr=C3=B6m?= Date: Fri, 13 Nov 2015 22:06:43 +0100 Subject: [PATCH 1/4] Introduce a global volume variable --- xm.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xm.js b/xm.js index ff31034..462b42e 100644 --- a/xm.js +++ b/xm.js @@ -22,6 +22,7 @@ player.cur_row = 64; player.cur_ticksamp = 0; player.cur_tick = 6; player.xm = {}; // contains all song data +player.xm.global_volume = player.max_global_volume = 128; // exposed for testing player.nextTick = nextTick; @@ -369,8 +370,8 @@ function MixChannelIntoBuf(ch, start, end, dataL, dataR) { var volE = ch.volE / 64.0; // current volume envelope var panE = 4*(ch.panE - 32); // current panning envelope var p = panE + ch.pan - 128; // final pan - var volL = volE * (128 - p) * ch.vol / 8192.0; - var volR = volE * (128 + p) * ch.vol / 8192.0; + var volL = player.xm.global_volume * volE * (128 - p) * ch.vol / (64 * 128 * 128); + var volR = player.xm.global_volume * volE * (128 + p) * ch.vol / (64 * 128 * 128); if (volL < 0) volL = 0; if (volR < 0) volR = 0; if (volR === 0 && volL === 0) @@ -645,6 +646,7 @@ function load(arrayBuf) { player.xm.tempo = dv.getUint16(0x4c, true); player.xm.bpm = dv.getUint16(0x4e, true); player.xm.channelinfo = []; + player.xm.global_volume = player.max_global_volume; var i, j, k; @@ -915,6 +917,7 @@ function stop() { player.cur_row = 64; player.cur_songpos = -1; player.cur_ticksamp = 0; + player.xm.global_volume = player.max_global_volume; if (XMView.stop) XMView.stop(); init(); } From eff3fd1ed6dfcb72a1817ae6ebdea8748bd95d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Hillerstr=C3=B6m?= Date: Sat, 14 Nov 2015 13:04:29 +0100 Subject: [PATCH 2/4] Implement the Gxx effect --- xmeffects.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/xmeffects.js b/xmeffects.js index 5832d3d..7dffb75 100644 --- a/xmeffects.js +++ b/xmeffects.js @@ -182,6 +182,16 @@ function eff_t0_f(ch, data) { // set tempo } } +function eff_t0_g(ch, data) { // set global volume + if (data <= 0x40) { + // volume gets multiplied by 2 to match + // the initial max global volume of 128 + player.xm.global_volume = Math.max(0, data * 2); + } else { + player.xm.global_volume = player.max_global_volume; + } +} + function eff_t0_r(ch, data) { // retrigger if (data & 0x0f) ch.retrig = (ch.retrig & 0xf0) + (data & 0x0f); if (data & 0xf0) ch.retrig = (ch.retrig & 0x0f) + (data & 0xf0); @@ -234,7 +244,7 @@ player.effects_t0 = [ // effect functions on tick 0 eff_t0_d, // d eff_t0_e, // e eff_t0_f, // f - eff_unimplemented_t0, // g + eff_t0_g, // g eff_unimplemented_t0, // h eff_unimplemented_t0, // i eff_unimplemented_t0, // j @@ -273,7 +283,7 @@ player.effects_t1 = [ // effect functions on tick 1+ null, // d eff_t1_e, // e null, // f - eff_unimplemented, // g + null, // g eff_unimplemented, // h eff_unimplemented, // i eff_unimplemented, // j From 88584b9cd09d1c48cabdf959f771ea484308c607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Hillerstr=C3=B6m?= Date: Sat, 14 Nov 2015 13:04:43 +0100 Subject: [PATCH 3/4] Add test case for Gxx --- test/effects.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/effects.js b/test/effects.js index 247fec6..056c2ef 100644 --- a/test/effects.js +++ b/test/effects.js @@ -152,3 +152,25 @@ exports['test 4xy vibrato'] = function(assert) { assert.equal(p.toFixed(3), "-1.546", 'row 5 tick 1 period -1.546'); }; +exports['test Gxx global volume'] = function(assert) { + var xm = testdata.resetXMData(); + // [pat][row][channel] + // 1 channel, 3 row blank pattern + xm.patterns = [ + [ + [[48, 1, -1, 16, 0x40]], // C-4 1 -- G40 + [[48, 1, -1, 16, 0x2B]], // C-4 1 -- G2B + // test out of bounds volume + [[48, 1, -1, 16, 0x80]] // C-4 1 -- G80 + ] + ]; + XMPlayer.xm.tempo = 1; + XMPlayer.nextTick(); + // volume gets multiplied by 2 to match + // the initial max global volume of 128 + assert.equal(XMPlayer.xm.global_volume, 0x40*2, 'global volume set to 0x40'); + XMPlayer.nextTick(); + assert.equal(XMPlayer.xm.global_volume, 0x2B*2, 'global volume set to 0x2B'); + XMPlayer.nextTick(); + assert.equal(XMPlayer.xm.global_volume, 0x40*2, 'global volume set to 0x40'); +}; From 8fe05fb89d1e4ec395df63579f41ae24204bcaff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Hillerstr=C3=B6m?= Date: Sat, 14 Nov 2015 13:07:51 +0100 Subject: [PATCH 4/4] Remove Gxx from missing effects --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 0dfe25d..7dca2ce 100644 --- a/index.html +++ b/index.html @@ -74,7 +74,7 @@ todo: - missing XM effects: - E3x, E4x, E5x, E6x, E7x, E9x, EDx, EEx - 7xy - tremolo - - Gxx, Hxy, Kxx, Lxx, Pxy, Txy + - Hxy, Kxx, Lxx, Pxy, Txy - render pattern with the wider fonts for fewer channels - fix occasional rendering/audio hiccups when switching songs