# HG changeset patch # User Matti Hamalainen # Date 1349667875 -10800 # Node ID e65fed571d7a7796d26d9861da192a1cd565857b # Parent 585e0a95be36f00c7ee46ad025e1c29e20490e5f Improve vibrato implementation. Might not work in Amiga periods mode, tho. diff -r 585e0a95be36 -r e65fed571d7a jssplr.c --- a/jssplr.c Mon Oct 08 03:01:30 2012 +0300 +++ b/jssplr.c Mon Oct 08 06:44:35 2012 +0300 @@ -10,8 +10,13 @@ /* Miscellaneous tables */ -#define jmpNSineTable (256) -static int *jmpSineTable = NULL; +static const Uint8 jmpSineTab[32] = +{ + 0, 24, 49, 74, 97, 120, 141, 161, + 180, 197, 212, 224, 235, 244, 250, 253, + 255, 253, 250, 244, 235, 224, 212, 197, + 180, 161, 141, 120, 97, 74, 49, 24 +}; static const Sint16 jmpXMAmigaPeriodTab[13 * 8] = { @@ -251,20 +256,6 @@ { JSSPlayer *mp; - // Initialize global tables - if (jmpSineTable == NULL) - { - int i; - if ((jmpSineTable = dmMalloc(jmpNSineTable * sizeof(int))) == NULL) - JSSERROR(DMERR_MALLOC, NULL, "Could not allocate memory for sinus table.\n"); - - for (i = 0; i < 256; i++) - { - float f = ((float) i * M_PI * 2.0f) / 256.0f; - jmpSineTable[i] = (int) (sin(f) * 2048.0f); - } - } - // Allocate a player structure mp = dmMalloc0(sizeof(JSSPlayer)); if (mp == NULL) @@ -649,41 +640,37 @@ */ static void jmpDoTremolo(JSSPlayer * mp, JSSPlayerChannel *chn, int channel) { - int delta, pos, depth; + (void) channel; - // Check settings - if (chn->tremolo.depth == 0 || chn->tremolo.speed == 0) - return; - - // Get position of tremolo waveform - pos = chn->tremolo.pos & 255; - depth = chn->tremolo.depth; - - switch (chn->tremolo.wc & 3) + if (chn->tremolo.depth != 0 && chn->tremolo.speed != 0) { - case 0: // Sine-wave - delta = (jmpSineTable[pos] * depth) / 2048; - break; + int delta, tmp = chn->tremolo.pos & 31; - case 1: // Ramp down - delta = ((pos - 128) * depth) / 128; - break; - - case 2: // Square - delta = (((pos & 128) - 64) * depth) / 64; - break; + switch (chn->tremolo.wc & 3) + { + case 0: + delta = jmpSineTab[tmp]; + break; + case 1: + tmp <<= 3; + delta = (chn->tremolo.pos < 0) ? 255 - tmp : tmp; + break; + case 2: + delta = 255; + break; + case 3: + delta = jmpSineTab[tmp]; + break; + } - default: - return; - } + delta = (delta * chn->tremolo.depth) >> 6; + +// jmpCSetVolume(mp, chn, channel, chn->volume + (chn->tremolo.pos >= 0 ? ), FALSE); - // Set the new volume - jmpCSetVolume(mp, chn, channel, chn->volume + delta, FALSE); - - // Advance tremolo waveform position - chn->tremolo.pos += chn->tremolo.speed; - if (chn->tremolo.pos > 255) - chn->tremolo.pos = 0; + chn->tremolo.pos += chn->tremolo.speed; + if (chn->tremolo.pos > 31) + chn->tremolo.pos -= 64; + } } @@ -691,41 +678,37 @@ */ static void jmpDoVibrato(JSSPlayer * mp, JSSPlayerChannel *chn, int channel) { - int delta, pos, depth; + (void) channel; - // Check settings - if (chn->vibrato.depth == 0 || chn->vibrato.speed == 0) - return; - - // Get position of vibrato waveform - pos = chn->vibrato.pos & 255; - depth = chn->vibrato.depth; - - switch (chn->vibrato.wc & 3) + if (chn->vibrato.depth != 0 && chn->vibrato.speed != 0) { - case 0: // Sine-wave - delta = (jmpSineTable[pos] * depth) / 2048; - break; + int delta, tmp = chn->vibrato.pos & 31; - case 1: // Ramp down - delta = ((pos - 128) * depth) / 16; - break; - - case 2: // Square - delta = (((pos & 128) - 64) * depth) / 8; - break; + switch (chn->vibrato.wc & 3) + { + case 0: + delta = jmpSineTab[tmp]; + break; + case 1: + tmp <<= 3; + delta = (chn->vibrato.pos < 0) ? 255 - tmp : tmp; + break; + case 2: + delta = 255; + break; + case 3: + delta = jmpSineTab[tmp]; + break; + } - default: - return; - } + delta = ((delta * chn->vibrato.depth) >> 7) << 2; + chn->freq = chn->cfreq + (chn->vibrato.pos >= 0 ? delta : -delta); + JMPSETNDFLAGS(cdfNewFreq); - // Set the new frequency - jmpCSetPitch(mp, chn, chn->pitch + delta); - - // Advance vibrato waveform position - chn->vibrato.pos += chn->vibrato.speed; - if (chn->vibrato.pos > 255) - chn->vibrato.pos = 0; + chn->vibrato.pos += chn->vibrato.speed; + if (chn->vibrato.pos > 31) + chn->vibrato.pos -= 64; + } }