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 ++++++++++------- src/chips/nuked/nukedopl3.h | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) (limited to 'src/chips') 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: diff --git a/src/chips/nuked/nukedopl3.h b/src/chips/nuked/nukedopl3.h index d57cf5f..8d3318a 100644 --- a/src/chips/nuked/nukedopl3.h +++ b/src/chips/nuked/nukedopl3.h @@ -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 a41ef948c2471c1c5698142ab9faa109fe1e55fe Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Thu, 28 Jun 2018 12:21:00 +0300 Subject: License LGPL v2.1 for the complete chipset interface --- src/chips/dosbox_opl3.cpp | 20 ++++++++++++++++++++ src/chips/dosbox_opl3.h | 20 ++++++++++++++++++++ src/chips/nuked_opl3.cpp | 20 ++++++++++++++++++++ src/chips/nuked_opl3.h | 20 ++++++++++++++++++++ src/chips/nuked_opl3_v174.cpp | 20 ++++++++++++++++++++ src/chips/nuked_opl3_v174.h | 20 ++++++++++++++++++++ src/chips/opl_chip_base.h | 18 ++++++++++++++++++ 7 files changed, 138 insertions(+) (limited to 'src/chips') diff --git a/src/chips/dosbox_opl3.cpp b/src/chips/dosbox_opl3.cpp index 30fa38e..f783afe 100644 --- a/src/chips/dosbox_opl3.cpp +++ b/src/chips/dosbox_opl3.cpp @@ -1,3 +1,23 @@ +/* + * Interfaces over Yamaha OPL3 (YMF262) chip emulators + * + * Copyright (C) 2017-2018 Vitaly Novichkov (Wohlstand) + * + * 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 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 + * 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 + */ + #include "dosbox_opl3.h" #include "dosbox/dbopl.h" #include diff --git a/src/chips/dosbox_opl3.h b/src/chips/dosbox_opl3.h index 1928026..f966393 100644 --- a/src/chips/dosbox_opl3.h +++ b/src/chips/dosbox_opl3.h @@ -1,3 +1,23 @@ +/* + * Interfaces over Yamaha OPL3 (YMF262) chip emulators + * + * Copyright (C) 2017-2018 Vitaly Novichkov (Wohlstand) + * + * 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 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 + * 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 + */ + #ifndef DOSBOX_OPL3_H #define DOSBOX_OPL3_H diff --git a/src/chips/nuked_opl3.cpp b/src/chips/nuked_opl3.cpp index 48e5c17..e4f9764 100644 --- a/src/chips/nuked_opl3.cpp +++ b/src/chips/nuked_opl3.cpp @@ -1,3 +1,23 @@ +/* + * Interfaces over Yamaha OPL3 (YMF262) chip emulators + * + * Copyright (C) 2017-2018 Vitaly Novichkov (Wohlstand) + * + * 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 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 + * 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 + */ + #include "nuked_opl3.h" #include "nuked/nukedopl3.h" #include diff --git a/src/chips/nuked_opl3.h b/src/chips/nuked_opl3.h index 1b34e9a..4b14b8b 100644 --- a/src/chips/nuked_opl3.h +++ b/src/chips/nuked_opl3.h @@ -1,3 +1,23 @@ +/* + * Interfaces over Yamaha OPL3 (YMF262) chip emulators + * + * Copyright (C) 2017-2018 Vitaly Novichkov (Wohlstand) + * + * 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 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 + * 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 + */ + #ifndef NUKED_OPL3_H #define NUKED_OPL3_H diff --git a/src/chips/nuked_opl3_v174.cpp b/src/chips/nuked_opl3_v174.cpp index e24b2e7..793af93 100644 --- a/src/chips/nuked_opl3_v174.cpp +++ b/src/chips/nuked_opl3_v174.cpp @@ -1,3 +1,23 @@ +/* + * Interfaces over Yamaha OPL3 (YMF262) chip emulators + * + * Copyright (C) 2017-2018 Vitaly Novichkov (Wohlstand) + * + * 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 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 + * 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 + */ + #include "nuked_opl3_v174.h" #include "nuked/nukedopl3_174.h" #include diff --git a/src/chips/nuked_opl3_v174.h b/src/chips/nuked_opl3_v174.h index f14221f..9463a02 100644 --- a/src/chips/nuked_opl3_v174.h +++ b/src/chips/nuked_opl3_v174.h @@ -1,3 +1,23 @@ +/* + * Interfaces over Yamaha OPL3 (YMF262) chip emulators + * + * Copyright (C) 2017-2018 Vitaly Novichkov (Wohlstand) + * + * 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 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 + * 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 + */ + #ifndef NUKED_OPL3174_H #define NUKED_OPL3174_H diff --git a/src/chips/opl_chip_base.h b/src/chips/opl_chip_base.h index 879d6da..8025d03 100644 --- a/src/chips/opl_chip_base.h +++ b/src/chips/opl_chip_base.h @@ -1,3 +1,21 @@ +/* + * Copyright (C) 2017-2018 Vitaly Novichkov (Wohlstand) + * + * 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 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 + * 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 + */ + #ifndef ONP_CHIP_BASE_H #define ONP_CHIP_BASE_H -- 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/dosbox/dbopl.cpp | 22 ++++++++++++++++++++-- src/chips/dosbox/dbopl.h | 6 ++++++ src/chips/dosbox_opl3.cpp | 6 ++++++ src/chips/dosbox_opl3.h | 1 + src/chips/nuked/nukedopl3.c | 23 +++++++++++++++++++++-- src/chips/nuked/nukedopl3.h | 2 ++ src/chips/nuked/nukedopl3_174.c | 21 ++++++++++++++++++++- src/chips/nuked/nukedopl3_174.h | 2 ++ src/chips/nuked_opl3.cpp | 6 ++++++ src/chips/nuked_opl3.h | 1 + src/chips/nuked_opl3_v174.cpp | 6 ++++++ src/chips/nuked_opl3_v174.h | 1 + src/chips/opl_chip_base.h | 3 +++ 13 files changed, 95 insertions(+), 5 deletions(-) (limited to 'src/chips') diff --git a/src/chips/dosbox/dbopl.cpp b/src/chips/dosbox/dbopl.cpp index 7d78c5f..903c1bb 100644 --- a/src/chips/dosbox/dbopl.cpp +++ b/src/chips/dosbox/dbopl.cpp @@ -757,6 +757,11 @@ void Channel::WriteC0(const Chip* chip, Bit8u val) { UpdateSynth(chip); } +void Channel::WritePan(Bit8u val) { + panLeft = (Bit16u)(cos((float)val * (PI / 2.0f / 127.0f)) * 65535.0f); + panRight = (Bit16u)(sin((float)val * (PI / 2.0f / 127.0f)) * 65535.0f); +} + void Channel::UpdateSynth( const Chip* chip ) { //Select the new synth mode if ( chip->opl3Active ) { @@ -971,8 +976,8 @@ Channel* Channel::BlockTemplate( Chip* chip, Bit32u samples, Bit32s* output ) { case sm3AMFM: case sm3FMAM: case sm3AMAM: - output[ i * 2 + 0 ] += sample & maskLeft; - output[ i * 2 + 1 ] += sample & maskRight; + output[ i * 2 + 0 ] += (sample * panLeft / 65535) & maskLeft; + output[ i * 2 + 1 ] += (sample * panRight / 65535) & maskRight; break; default: break; @@ -1388,6 +1393,10 @@ void Chip::Setup( Bit32u rate ) { WriteReg( i, 0xff ); WriteReg( i, 0x0 ); } + + for ( int i = 0; i < 18; i++ ) { + chan[i].WritePan( 0x40 ); + } } static bool doneTables = false; @@ -1614,5 +1623,14 @@ void Handler::Init( Bitu rate ) { chip.Setup( static_cast(rate) ); } +void Handler::WritePan( Bit32u reg, Bit8u val ) +{ + Bitu index; + index = ((reg >> 4) & 0x10) | (reg & 0xf); + if (ChanOffsetTable[index]) { + Channel* regChan = (Channel*)(((char *)&chip) + ChanOffsetTable[index]); + regChan->WritePan(val); + } +} } //Namespace DBOPL diff --git a/src/chips/dosbox/dbopl.h b/src/chips/dosbox/dbopl.h index 73c0aa9..c265fc6 100644 --- a/src/chips/dosbox/dbopl.h +++ b/src/chips/dosbox/dbopl.h @@ -192,6 +192,9 @@ struct Channel { Bit8s maskLeft; //Sign extended values for both channel's panning Bit8s maskRight; + Bit16u panLeft; // Extended behavior, scale values for soft panning + Bit16u panRight; + //Forward the channel data to the operators of the channel void SetChanData( const Chip* chip, Bit32u data ); //Change in the chandata, check for new values and if we have to forward to operators @@ -201,6 +204,8 @@ struct Channel { void WriteB0( const Chip* chip, Bit8u val ); void WriteC0( const Chip* chip, Bit8u val ); + void WritePan( Bit8u val ); + //call this for the first channel template< bool opl3Mode > void GeneratePercussion( Chip* chip, Bit32s* output ); @@ -271,6 +276,7 @@ struct Chip { struct Handler { DBOPL::Chip chip; + void WritePan( Bit32u port, Bit8u val ); Bit32u WriteAddr( Bit32u port, Bit8u val ); void WriteReg( Bit32u addr, Bit8u val ); void GenerateArr(Bit32s *out, Bitu *samples); diff --git a/src/chips/dosbox_opl3.cpp b/src/chips/dosbox_opl3.cpp index f783afe..37f5e9c 100644 --- a/src/chips/dosbox_opl3.cpp +++ b/src/chips/dosbox_opl3.cpp @@ -61,6 +61,12 @@ void DosBoxOPL3::writeReg(uint16_t addr, uint8_t data) chip_r->WriteReg(static_cast(addr), data); } +void DosBoxOPL3::writePan(uint16_t addr, uint8_t data) +{ + DBOPL::Handler *chip_r = reinterpret_cast(m_chip); + chip_r->WritePan(static_cast(addr), data); +} + void DosBoxOPL3::nativeGenerateN(int16_t *output, size_t frames) { DBOPL::Handler *chip_r = reinterpret_cast(m_chip); diff --git a/src/chips/dosbox_opl3.h b/src/chips/dosbox_opl3.h index f966393..eb79300 100644 --- a/src/chips/dosbox_opl3.h +++ b/src/chips/dosbox_opl3.h @@ -34,6 +34,7 @@ public: void setRate(uint32_t rate) override; void reset() override; void writeReg(uint16_t addr, uint8_t data) override; + void writePan(uint16_t addr, uint8_t data) override; void nativePreGenerate() override {} void nativePostGenerate() override {} void nativeGenerateN(int16_t *output, size_t frames) override; 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; diff --git a/src/chips/nuked/nukedopl3.h b/src/chips/nuked/nukedopl3.h index 8d3318a..268e8de 100644 --- a/src/chips/nuked/nukedopl3.h +++ b/src/chips/nuked/nukedopl3.h @@ -101,6 +101,7 @@ struct _opl3_channel { Bit8u alg; Bit8u ksv; Bit16u cha, chb; + Bit16u chl, chr; Bit8u ch_num; }; @@ -153,6 +154,7 @@ void OPL3_GenerateResampled(opl3_chip *chip, Bit16s *buf); void OPL3_Reset(opl3_chip *chip, Bit32u samplerate); void OPL3_WriteReg(opl3_chip *chip, Bit16u reg, Bit8u v); void OPL3_WriteRegBuffered(opl3_chip *chip, Bit16u reg, Bit8u v); +void OPL3_WritePan(opl3_chip *chip, Bit16u reg, Bit8u v); void OPL3_GenerateStream(opl3_chip *chip, Bit16s *sndptr, Bit32u numsamples); void OPL3_GenerateStreamMix(opl3_chip *chip, Bit16s *sndptr, Bit32u numsamples); 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; diff --git a/src/chips/nuked/nukedopl3_174.h b/src/chips/nuked/nukedopl3_174.h index 240802f..cd18562 100644 --- a/src/chips/nuked/nukedopl3_174.h +++ b/src/chips/nuked/nukedopl3_174.h @@ -103,6 +103,7 @@ struct _opl3_channel { Bit8u alg; Bit8u ksv; Bit16u cha, chb; + Bit16u chl, chr; }; typedef struct _opl3_writebuf { @@ -142,6 +143,7 @@ struct _opl3_chip { void OPL3v17_Generate(opl3_chip *chip, Bit16s *buf); void OPL3v17_GenerateResampled(opl3_chip *chip, Bit16s *buf); void OPL3v17_Reset(opl3_chip *chip, Bit32u samplerate); +void OPL3v17_WritePan(opl3_chip *chip, Bit16u reg, Bit8u v); void OPL3v17_WriteReg(opl3_chip *chip, Bit16u reg, Bit8u v); void OPL3v17_WriteRegBuffered(opl3_chip *chip, Bit16u reg, Bit8u v); void OPL3v17_GenerateStream(opl3_chip *chip, Bit16s *sndptr, Bit32u numsamples); diff --git a/src/chips/nuked_opl3.cpp b/src/chips/nuked_opl3.cpp index e4f9764..bbf4a25 100644 --- a/src/chips/nuked_opl3.cpp +++ b/src/chips/nuked_opl3.cpp @@ -57,6 +57,12 @@ void NukedOPL3::writeReg(uint16_t addr, uint8_t data) OPL3_WriteRegBuffered(chip_r, addr, data); } +void NukedOPL3::writePan(uint16_t addr, uint8_t data) +{ + opl3_chip *chip_r = reinterpret_cast(m_chip); + OPL3_WritePan(chip_r, addr, data); +} + void NukedOPL3::nativeGenerate(int16_t *frame) { opl3_chip *chip_r = reinterpret_cast(m_chip); diff --git a/src/chips/nuked_opl3.h b/src/chips/nuked_opl3.h index 4b14b8b..33baf54 100644 --- a/src/chips/nuked_opl3.h +++ b/src/chips/nuked_opl3.h @@ -34,6 +34,7 @@ public: void setRate(uint32_t rate) override; void reset() override; void writeReg(uint16_t addr, uint8_t data) override; + void writePan(uint16_t addr, uint8_t data) override; void nativePreGenerate() override {} void nativePostGenerate() override {} void nativeGenerate(int16_t *frame) override; diff --git a/src/chips/nuked_opl3_v174.cpp b/src/chips/nuked_opl3_v174.cpp index 793af93..6bb06c2 100644 --- a/src/chips/nuked_opl3_v174.cpp +++ b/src/chips/nuked_opl3_v174.cpp @@ -57,6 +57,12 @@ void NukedOPL3v174::writeReg(uint16_t addr, uint8_t data) OPL3v17_WriteReg(chip_r, addr, data); } +void NukedOPL3v174::writePan(uint16_t addr, uint8_t data) +{ + opl3_chip *chip_r = reinterpret_cast(m_chip); + OPL3v17_WritePan(chip_r, addr, data); +} + void NukedOPL3v174::nativeGenerate(int16_t *frame) { opl3_chip *chip_r = reinterpret_cast(m_chip); diff --git a/src/chips/nuked_opl3_v174.h b/src/chips/nuked_opl3_v174.h index 9463a02..9eaeb19 100644 --- a/src/chips/nuked_opl3_v174.h +++ b/src/chips/nuked_opl3_v174.h @@ -34,6 +34,7 @@ public: void setRate(uint32_t rate) override; void reset() override; void writeReg(uint16_t addr, uint8_t data) override; + void writePan(uint16_t addr, uint8_t data) override; void nativePreGenerate() override {} void nativePostGenerate() override {} void nativeGenerate(int16_t *frame) override; diff --git a/src/chips/opl_chip_base.h b/src/chips/opl_chip_base.h index 8025d03..faee307 100644 --- a/src/chips/opl_chip_base.h +++ b/src/chips/opl_chip_base.h @@ -61,6 +61,9 @@ public: virtual void reset() = 0; virtual void writeReg(uint16_t addr, uint8_t data) = 0; + // extended + virtual void writePan(uint16_t addr, uint8_t data) { }; + virtual void nativePreGenerate() = 0; virtual void nativePostGenerate() = 0; virtual void nativeGenerate(int16_t *frame) = 0; -- 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 +++++++++++++++++++++++++------- src/chips/nuked/nukedopl3_174.c | 47 +++++++++++++++++++++++++++++------------ src/chips/opl_chip_base.h | 2 +- 3 files changed, 64 insertions(+), 22 deletions(-) (limited to 'src/chips') 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) 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) diff --git a/src/chips/opl_chip_base.h b/src/chips/opl_chip_base.h index faee307..723bbc9 100644 --- a/src/chips/opl_chip_base.h +++ b/src/chips/opl_chip_base.h @@ -62,7 +62,7 @@ public: virtual void writeReg(uint16_t addr, uint8_t data) = 0; // extended - virtual void writePan(uint16_t addr, uint8_t data) { }; + virtual void writePan(uint16_t addr, uint8_t data) { (void)addr; (void)data; } virtual void nativePreGenerate() = 0; virtual void nativePostGenerate() = 0; -- 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 +++-- src/chips/nuked/nukedopl3_174.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/chips') 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, 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 413cbe144e61f3b2c661cb85c0091ec79d94e1e5 Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Tue, 31 Jul 2018 00:48:11 +0300 Subject: Use the Pan Law table on DosBox emulator also --- src/chips/dosbox/dbopl.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/chips') diff --git a/src/chips/dosbox/dbopl.cpp b/src/chips/dosbox/dbopl.cpp index 903c1bb..3b0d73d 100644 --- a/src/chips/dosbox/dbopl.cpp +++ b/src/chips/dosbox/dbopl.cpp @@ -219,6 +219,29 @@ static const Bit8u KslShiftTable[4] = { 31,1,2,0 }; +// 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, + 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, + 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 +}; + //Generate a table index and table shift value using input value from a selected rate static void EnvelopeSelect( Bit8u val, Bit8u& index, Bit8u& shift ) { if ( val < 13 * 4 ) { //Rate 0 - 12 @@ -758,8 +781,8 @@ void Channel::WriteC0(const Chip* chip, Bit8u val) { } void Channel::WritePan(Bit8u val) { - panLeft = (Bit16u)(cos((float)val * (PI / 2.0f / 127.0f)) * 65535.0f); - panRight = (Bit16u)(sin((float)val * (PI / 2.0f / 127.0f)) * 65535.0f); + panLeft = PanLawTable[val & 0x7F]; + panRight = PanLawTable[0x7F - (val & 0x7F)]; } void Channel::UpdateSynth( const Chip* chip ) { -- 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 ++-- src/chips/nuked/nukedopl3_174.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/chips') 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]); } 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/dosbox/dbopl.cpp | 2 +- src/chips/nuked/nukedopl3.c | 2 +- src/chips/nuked/nukedopl3_174.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/chips') diff --git a/src/chips/dosbox/dbopl.cpp b/src/chips/dosbox/dbopl.cpp index 3b0d73d..2c00db2 100644 --- a/src/chips/dosbox/dbopl.cpp +++ b/src/chips/dosbox/dbopl.cpp @@ -220,7 +220,7 @@ static const Bit8u KslShiftTable[4] = { }; // 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, 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, 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 From e098e4285af6d565d7b603279ec6e9770ce88436 Mon Sep 17 00:00:00 2001 From: JP Cimalando Date: Tue, 31 Jul 2018 02:31:47 +0200 Subject: fix some warnings --- src/chips/dosbox/dbopl.cpp | 1 + src/chips/dosbox/dbopl.h | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/chips') diff --git a/src/chips/dosbox/dbopl.cpp b/src/chips/dosbox/dbopl.cpp index 3b0d73d..6c6ef3d 100644 --- a/src/chips/dosbox/dbopl.cpp +++ b/src/chips/dosbox/dbopl.cpp @@ -465,6 +465,7 @@ Bits Operator::TemplateVolume( ) { return vol; } //In sustain phase, but not sustaining, do regular release + /* fall through */ case RELEASE: vol += RateForward( releaseAdd );; if ( GCC_UNLIKELY(vol >= ENV_MAX) ) { diff --git a/src/chips/dosbox/dbopl.h b/src/chips/dosbox/dbopl.h index c265fc6..429735f 100644 --- a/src/chips/dosbox/dbopl.h +++ b/src/chips/dosbox/dbopl.h @@ -75,13 +75,13 @@ typedef enum { sm3AMAM, sm6Start, sm2Percussion, - sm3Percussion, + sm3Percussion } SynthMode; //Shifts for the values contained in chandata variable enum { SHIFT_KSLBASE = 16, - SHIFT_KEYCODE = 24, + SHIFT_KEYCODE = 24 }; struct Operator { @@ -91,7 +91,7 @@ public: MASK_KSR = 0x10, MASK_SUSTAIN = 0x20, MASK_VIBRATO = 0x40, - MASK_TREMOLO = 0x80, + MASK_TREMOLO = 0x80 }; typedef enum { @@ -99,7 +99,7 @@ public: RELEASE, SUSTAIN, DECAY, - ATTACK, + ATTACK } State; VolumeHandler volHandler; -- cgit v1.2.3