From 0e47b13d833b3a7e5f826b2af59f6cea2debf28a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Hillerstr=C3=B6m?= Date: Sat, 21 Nov 2015 02:26:04 +0100 Subject: [PATCH] Implement all vibrato waveforms --- xmeffects.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/xmeffects.js b/xmeffects.js index 27d2eda..dad153d 100644 --- a/xmeffects.js +++ b/xmeffects.js @@ -65,7 +65,7 @@ function eff_t0_4(ch, data) { // vibrato } function eff_t1_4(ch) { // vibrato - ch.periodoffset = Math.sin(ch.vibratopos * Math.PI / 32) * ch.vibratodepth; + ch.periodoffset = getVibratoDelta(ch.vibratotype, ch.vibratopos) * ch.vibratodepth; if (isNaN(ch.periodoffset)) { console.log("vibrato periodoffset NaN?", ch.vibratopos, ch.vibratospeed, ch.vibratodepth); @@ -75,6 +75,24 @@ function eff_t1_4(ch) { // vibrato ch.vibratopos &= 63; } +function getVibratoDelta(type, x) { + var delta = 0; + switch (type & 0x03) { + case 1: // sawtooth (ramp-down) + delta = ((1 + x * 2 / 64) % 2) - 1; + break; + case 2: // square + case 3: // random (in FT2 these two are the same) + delta = x < 32 ? 1 : -1; + break; + case 0: + default: // sine + delta = Math.sin(x * Math.PI / 32); + break; + } + return delta; +} + function eff_t1_5(ch) { // portamento + volume slide eff_t1_a(ch); eff_t1_3(ch);