From 0f69d504792776967b61f8987ad458c48b4a322f Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sun, 29 Jul 2018 20:52:26 -0700 Subject: Implemented optional soft panning support for the included chip emulators, disabled by default. --- src/chips/nuked/nukedopl3_174.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/chips/nuked/nukedopl3_174.c') diff --git a/src/chips/nuked/nukedopl3_174.c b/src/chips/nuked/nukedopl3_174.c index 99eab16..a8b1f40 100644 --- a/src/chips/nuked/nukedopl3_174.c +++ b/src/chips/nuked/nukedopl3_174.c @@ -34,7 +34,11 @@ #define RSM_FRAC 10 -/* Channel types */ +#ifndef PI +#define PI 3.14159265358979323846 +#endif + + /* Channel types */ enum { ch_2op = 0, @@ -1222,6 +1226,8 @@ void OPL3v17_Reset(opl3_chip *chip, Bit32u samplerate) chip->channel[channum].chtype = ch_2op; chip->channel[channum].cha = ~0; chip->channel[channum].chb = ~0; + chip->channel[channum].chl = ~0; + chip->channel[channum].chr = ~0; OPL3_ChannelSetupAlg(&chip->channel[channum]); } chip->noise = 0x306600; @@ -1230,6 +1236,19 @@ void OPL3v17_Reset(opl3_chip *chip, Bit32u samplerate) chip->vibshift = 1; } +static void OPL3v17_ChannelWritePan(opl3_channel *channel, Bit8u data) +{ + channel->chl = (Bit16u)(cos((float)data * (PI / 2.0f / 127.0f)) * 65535.0f); + channel->chr = (Bit16u)(sin((float)data * (PI / 2.0f / 127.0f)) * 65535.0f); +} + +void OPL3v17_WritePan(opl3_chip *chip, Bit16u reg, Bit8u v) +{ + Bit8u high = (reg >> 8) & 0x01; + Bit8u regm = reg & 0xff; + OPL3v17_ChannelWritePan(&chip->channel[9 * high + (regm & 0x0f)], v); +} + void OPL3v17_WriteReg(opl3_chip *chip, Bit16u reg, Bit8u v) { Bit8u high = (reg >> 8) & 0x01; -- cgit v1.2.3 From 6d48a253fe63b5e18ee03dd8c1f090323182f219 Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Mon, 30 Jul 2018 19:42:28 +0300 Subject: [Experimental] Partially apply fixes to kode54's pull request --- src/chips/nuked/nukedopl3_174.c | 47 +++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'src/chips/nuked/nukedopl3_174.c') diff --git a/src/chips/nuked/nukedopl3_174.c b/src/chips/nuked/nukedopl3_174.c index a8b1f40..23857c9 100644 --- a/src/chips/nuked/nukedopl3_174.c +++ b/src/chips/nuked/nukedopl3_174.c @@ -34,11 +34,7 @@ #define RSM_FRAC 10 -#ifndef PI -#define PI 3.14159265358979323846 -#endif - - /* Channel types */ +/* Channel types */ enum { ch_2op = 0, @@ -233,6 +229,31 @@ static const Bit8u ch_slot[18] = { 0, 1, 2, 6, 7, 8, 12, 13, 14, 18, 19, 20, 24, 25, 26, 30, 31, 32 }; +/* + * Pan law table + */ + +static Bit16u panlawtable[] = +{ + 65535, 65529, 65514, 65489, 65454, 65409, 65354, 65289, + 65214, 65129, 65034, 64929, 64814, 64689, 64554, 64410, + 64255, 64091, 63917, 63733, 63540, 63336, 63123, 62901, + 62668, 62426, 62175, 61914, 61644, 61364, 61075, 60776, + 60468, 60151, 59825, 59489, 59145, 58791, 58428, 58057, + 57676, 57287, 56889, 56482, 56067, 55643, 55211, 54770, + 54320, 53863, 53397, 52923, 52441, 51951, 51453, 50947, + 50433, 49912, 49383, 48846, 48302, 47750, 47191, 46625, + 46052, /* Center */ + 45472, 44885, 44291, 43690, 43083, 42469, 41848, 41221, + 40588, 39948, 39303, 38651, 37994, 37330, 36661, 35986, + 35306, 34621, 33930, 33234, 32533, 31827, 31116, 30400, + 29680, 28955, 28225, 27492, 26754, 26012, 25266, 24516, + 23762, 23005, 22244, 21480, 20713, 19942, 19169, 18392, + 17613, 16831, 16046, 15259, 14469, 13678, 12884, 12088, + 11291, 10492, 9691, 8888, 8085, 7280, 6473, 5666, + 4858, 4050, 3240, 2431, 1620, 810, 0 +}; + /* * Envelope generator */ @@ -1086,7 +1107,7 @@ void OPL3v17_Generate(opl3_chip *chip, Bit16s *buf) { accm += *chip->channel[ii].out[jj]; } - chip->mixbuff[0] += (Bit16s)(accm & chip->channel[ii].cha); + chip->mixbuff[0] += (Bit16s)((accm * chip->channel[ii].chl / 65535) & chip->channel[ii].cha); } for (ii = 15; ii < 18; ii++) @@ -1125,7 +1146,7 @@ void OPL3v17_Generate(opl3_chip *chip, Bit16s *buf) { accm += *chip->channel[ii].out[jj]; } - chip->mixbuff[1] += (Bit16s)(accm & chip->channel[ii].chb); + chip->mixbuff[1] += (Bit16s)((accm * chip->channel[ii].chr / 65535) & chip->channel[ii].chb); } for (ii = 33; ii < 36; ii++) @@ -1224,10 +1245,10 @@ void OPL3v17_Reset(opl3_chip *chip, Bit32u samplerate) chip->channel[channum].out[2] = &chip->zeromod; chip->channel[channum].out[3] = &chip->zeromod; chip->channel[channum].chtype = ch_2op; - chip->channel[channum].cha = ~0; - chip->channel[channum].chb = ~0; - chip->channel[channum].chl = ~0; - chip->channel[channum].chr = ~0; + chip->channel[channum].cha = 0xffff; + chip->channel[channum].chb = 0xffff; + chip->channel[channum].chl = 46052; + chip->channel[channum].chr = 46052; OPL3_ChannelSetupAlg(&chip->channel[channum]); } chip->noise = 0x306600; @@ -1238,8 +1259,8 @@ void OPL3v17_Reset(opl3_chip *chip, Bit32u samplerate) static void OPL3v17_ChannelWritePan(opl3_channel *channel, Bit8u data) { - channel->chl = (Bit16u)(cos((float)data * (PI / 2.0f / 127.0f)) * 65535.0f); - channel->chr = (Bit16u)(sin((float)data * (PI / 2.0f / 127.0f)) * 65535.0f); + channel->chl = panlawtable[data & 0x7F]; + channel->chr = panlawtable[0x7F - (data & 0x7F)]; } void OPL3v17_WritePan(opl3_chip *chip, Bit16u reg, Bit8u v) -- cgit v1.2.3 From 8f8dd36a3734b2bb75af275522b399a900b1b9e3 Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Tue, 31 Jul 2018 00:34:16 +0300 Subject: NukedOPL3: Guarantee that center pan will be equal on both 63 and 64 values --- src/chips/nuked/nukedopl3_174.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/chips/nuked/nukedopl3_174.c') diff --git a/src/chips/nuked/nukedopl3_174.c b/src/chips/nuked/nukedopl3_174.c index 23857c9..c7812ae 100644 --- a/src/chips/nuked/nukedopl3_174.c +++ b/src/chips/nuked/nukedopl3_174.c @@ -242,8 +242,9 @@ static Bit16u panlawtable[] = 60468, 60151, 59825, 59489, 59145, 58791, 58428, 58057, 57676, 57287, 56889, 56482, 56067, 55643, 55211, 54770, 54320, 53863, 53397, 52923, 52441, 51951, 51453, 50947, - 50433, 49912, 49383, 48846, 48302, 47750, 47191, 46625, - 46052, /* Center */ + 50433, 49912, 49383, 48846, 48302, 47750, 47191, + 46340, /* Center left */ + 46340, /* Center right */ 45472, 44885, 44291, 43690, 43083, 42469, 41848, 41221, 40588, 39948, 39303, 38651, 37994, 37330, 36661, 35986, 35306, 34621, 33930, 33234, 32533, 31827, 31116, 30400, -- cgit v1.2.3 From 34f42407a2a2e90c2ba45e9e70c86529bd67c418 Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Tue, 31 Jul 2018 01:03:42 +0300 Subject: Fix the initial panning state --- src/chips/nuked/nukedopl3_174.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/chips/nuked/nukedopl3_174.c') diff --git a/src/chips/nuked/nukedopl3_174.c b/src/chips/nuked/nukedopl3_174.c index c7812ae..2f7d874 100644 --- a/src/chips/nuked/nukedopl3_174.c +++ b/src/chips/nuked/nukedopl3_174.c @@ -1248,8 +1248,8 @@ void OPL3v17_Reset(opl3_chip *chip, Bit32u samplerate) chip->channel[channum].chtype = ch_2op; chip->channel[channum].cha = 0xffff; chip->channel[channum].chb = 0xffff; - chip->channel[channum].chl = 46052; - chip->channel[channum].chr = 46052; + chip->channel[channum].chl = 46340; + chip->channel[channum].chr = 46340; OPL3_ChannelSetupAlg(&chip->channel[channum]); } chip->noise = 0x306600; -- cgit v1.2.3 From af214cc7ebf2eed2788cea58cb658285adfe528b Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Tue, 31 Jul 2018 02:58:54 +0300 Subject: Added missing `const` to pan-law tables --- src/chips/nuked/nukedopl3_174.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/chips/nuked/nukedopl3_174.c') diff --git a/src/chips/nuked/nukedopl3_174.c b/src/chips/nuked/nukedopl3_174.c index 2f7d874..8f818d4 100644 --- a/src/chips/nuked/nukedopl3_174.c +++ b/src/chips/nuked/nukedopl3_174.c @@ -233,7 +233,7 @@ static const Bit8u ch_slot[18] = { * Pan law table */ -static Bit16u panlawtable[] = +static const Bit16u panlawtable[] = { 65535, 65529, 65514, 65489, 65454, 65409, 65354, 65289, 65214, 65129, 65034, 64929, 64814, 64689, 64554, 64410, -- cgit v1.2.3