aboutsummaryrefslogtreecommitdiff
path: root/src/chips/dosbox
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/dosbox
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/dosbox')
-rw-r--r--src/chips/dosbox/dbopl.cpp22
-rw-r--r--src/chips/dosbox/dbopl.h6
2 files changed, 26 insertions, 2 deletions
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<Bit32u>(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);