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 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/chips/dosbox/dbopl.cpp') 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 -- 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/dosbox/dbopl.cpp') 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 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/chips/dosbox/dbopl.cpp') 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, -- 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 + 1 file changed, 1 insertion(+) (limited to 'src/chips/dosbox/dbopl.cpp') 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) ) { -- cgit v1.2.3