From 0d01b5d902f5ae6c6904246721a6f1d7573b6926 Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Thu, 28 Jun 2018 12:20:18 +0300 Subject: NukeYkt has allowed to license his emulator under LGPL 2.1+ --- src/chips/nuked/nukedopl3.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/chips/nuked/nukedopl3.c') diff --git a/src/chips/nuked/nukedopl3.c b/src/chips/nuked/nukedopl3.c index 87d3212..fe2313c 100644 --- a/src/chips/nuked/nukedopl3.c +++ b/src/chips/nuked/nukedopl3.c @@ -1,16 +1,19 @@ /* * Copyright (C) 2013-2018 Alexey Khokholov (Nuke.YKT) * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Nuked OPL3 emulator. * Thanks: -- cgit v1.2.3 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.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/chips/nuked/nukedopl3.c') diff --git a/src/chips/nuked/nukedopl3.c b/src/chips/nuked/nukedopl3.c index fe2313c..94b1f9d 100644 --- a/src/chips/nuked/nukedopl3.c +++ b/src/chips/nuked/nukedopl3.c @@ -36,6 +36,10 @@ #define RSM_FRAC 10 +#ifndef PI +#define PI 3.14159265358979323846 +#endif + /* Channel types */ enum { @@ -1071,7 +1075,7 @@ void OPL3_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++) @@ -1100,7 +1104,7 @@ void OPL3_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++) @@ -1232,6 +1236,8 @@ void OPL3_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 = 0xffff; + chip->channel[channum].chr = 0xffff; chip->channel[channum].ch_num = channum; OPL3_ChannelSetupAlg(&chip->channel[channum]); } @@ -1241,6 +1247,19 @@ void OPL3_Reset(opl3_chip *chip, Bit32u samplerate) chip->vibshift = 1; } +static void OPL3_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 OPL3_WritePan(opl3_chip *chip, Bit16u reg, Bit8u v) +{ + Bit8u high = (reg >> 8) & 0x01; + Bit8u regm = reg & 0xff; + OPL3_ChannelWritePan(&chip->channel[9 * high + (regm & 0x0f)], v); +} + void OPL3_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.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'src/chips/nuked/nukedopl3.c') diff --git a/src/chips/nuked/nukedopl3.c b/src/chips/nuked/nukedopl3.c index 94b1f9d..41f4ca3 100644 --- a/src/chips/nuked/nukedopl3.c +++ b/src/chips/nuked/nukedopl3.c @@ -36,10 +36,6 @@ #define RSM_FRAC 10 -#ifndef PI -#define PI 3.14159265358979323846 -#endif - /* Channel types */ enum { @@ -181,6 +177,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 */ @@ -1236,8 +1257,8 @@ void OPL3_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 = 0xffff; - chip->channel[channum].chr = 0xffff; + chip->channel[channum].chl = 46052; + chip->channel[channum].chr = 46052; chip->channel[channum].ch_num = channum; OPL3_ChannelSetupAlg(&chip->channel[channum]); } @@ -1249,8 +1270,8 @@ void OPL3_Reset(opl3_chip *chip, Bit32u samplerate) static void OPL3_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 OPL3_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.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/chips/nuked/nukedopl3.c') diff --git a/src/chips/nuked/nukedopl3.c b/src/chips/nuked/nukedopl3.c index 41f4ca3..ca10479 100644 --- a/src/chips/nuked/nukedopl3.c +++ b/src/chips/nuked/nukedopl3.c @@ -190,8 +190,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.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/chips/nuked/nukedopl3.c') diff --git a/src/chips/nuked/nukedopl3.c b/src/chips/nuked/nukedopl3.c index ca10479..80a8975 100644 --- a/src/chips/nuked/nukedopl3.c +++ b/src/chips/nuked/nukedopl3.c @@ -1258,8 +1258,8 @@ void OPL3_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; chip->channel[channum].ch_num = channum; OPL3_ChannelSetupAlg(&chip->channel[channum]); } -- 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.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/chips/nuked/nukedopl3.c') diff --git a/src/chips/nuked/nukedopl3.c b/src/chips/nuked/nukedopl3.c index 80a8975..267e67a 100644 --- a/src/chips/nuked/nukedopl3.c +++ b/src/chips/nuked/nukedopl3.c @@ -181,7 +181,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