aboutsummaryrefslogtreecommitdiff
path: root/src/chips/nuked/nukedopl3.c
diff options
context:
space:
mode:
authorChristopher Snowhill <kode54@gmail.com>2018-07-29 20:52:26 -0700
committerChristopher Snowhill <kode54@gmail.com>2018-07-29 20:52:26 -0700
commit0f69d504792776967b61f8987ad458c48b4a322f (patch)
tree0884f6008b6433b3f25d454884d8c9f6b9f7fac1 /src/chips/nuked/nukedopl3.c
parentb5a38c540d5a2b5b6750a49eb25ca3c7388b099c (diff)
downloadlibADLMIDI-0f69d504792776967b61f8987ad458c48b4a322f.tar.gz
libADLMIDI-0f69d504792776967b61f8987ad458c48b4a322f.tar.bz2
libADLMIDI-0f69d504792776967b61f8987ad458c48b4a322f.zip
Implemented optional soft panning support for the included chip emulators, disabled by default.
Diffstat (limited to 'src/chips/nuked/nukedopl3.c')
-rw-r--r--src/chips/nuked/nukedopl3.c23
1 files changed, 21 insertions, 2 deletions
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;