From 90faeafbc4419de4d163cf0fed009960eee75ab8 Mon Sep 17 00:00:00 2001 From: Ian Curtis Date: Fri, 1 Feb 2019 21:02:02 +0000 Subject: [PATCH] Fix the audio in sega rally2. The game has packed separate tracks into the left and right audio channels. Selecting the correct track fixes the garbled mess. (Spindizzi) --- Src/Model3/DSB.cpp | 63 ++++++++++++++++++++++++++++++++++++++++------ Src/Model3/DSB.h | 3 +++ 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/Src/Model3/DSB.cpp b/Src/Model3/DSB.cpp index 322cce1..f0f0336 100644 --- a/Src/Model3/DSB.cpp +++ b/Src/Model3/DSB.cpp @@ -780,15 +780,23 @@ void CDSB2::WriteMPEGFIFO(UINT8 byte) //mixer_set_stereo_pan(0, MIXER_PAN_RIGHT, MIXER_PAN_LEFT); mpegState = ST_IDLE; break; - /* + case ST_GOTA0: // ch 0 mono - mixer_set_stereo_volume(0, 0, 255); - printf("ch 0 mono\n"); - mixer_set_stereo_pan(0, MIXER_PAN_CENTER, MIXER_PAN_CENTER); + //mixer_set_stereo_volume(0, 0, 255); + //printf("ch 0 mono\n"); + //mixer_set_stereo_pan(0, MIXER_PAN_CENTER, MIXER_PAN_CENTER); + + if (byte == 0) { + audioChannel = AudioChannel::stereo; + } + else { + audioChannel = AudioChannel::channel0; + } + mpegState = ST_IDLE; break; - */ + case ST_GOTA4: // dayto2pe plays advertise tune from this state by writing 0x75 mpegState = ST_IDLE; if (byte == 0x75) @@ -810,10 +818,21 @@ void CDSB2::WriteMPEGFIFO(UINT8 byte) //printf("ch 1 mono\n"); //mixer_set_stereo_volume(0, 255, 0); //mixer_set_stereo_pan(0, MIXER_PAN_CENTER, MIXER_PAN_CENTER); + if (byte == 0) { + audioChannel = AudioChannel::stereo; + } + else { + audioChannel = AudioChannel::channel1; + } mpegState = ST_IDLE; break; case ST_GOTB4: mpegState = ST_IDLE; + if (byte == 0x96) + { + MPEG_StopPlaying(); + playing = 0; + } break; case ST_GOTB5: mpegState = ST_IDLE; @@ -831,19 +850,30 @@ void CDSB2::WriteMPEGFIFO(UINT8 byte) * when only setting two (in-game) */ case ST_GOTB6: // rear left(?) volume + volume[0] = byte; + mpegState = ST_IDLE; + break; case ST_GOTB0: // left volume volume[0] = byte; //printf("Set L Volume: %02X\n", byte); mpegState = ST_IDLE; break; case ST_GOTA7: // rear right(?) volume + volume[1] = byte; + mpegState = ST_IDLE; + break; case ST_GOTA1: // right volume - case ST_GOTA0: + volume[1] = byte; + mpegState = ST_IDLE; + break; + /*case ST_GOTA0: volume[1] = byte; //printf("Set R Volume: %02X\n", byte); mpegState = ST_IDLE; - break; + break;*/ case ST_GOTB2: + mpegState = ST_IDLE; + break; case ST_GOTA3: mpegState = ST_IDLE; break; @@ -1016,7 +1046,23 @@ void CDSB2::RunFrame(INT16 *audioL, INT16 *audioR) // Decode MPEG for this frame INT16 *mpegFill[2] = { &mpegL[retainedSamples], &mpegR[retainedSamples] }; MPEG_Decode(mpegFill, 32000/60-retainedSamples+2); - retainedSamples = Resampler.UpSampleAndMix(audioL, audioR, mpegL, mpegR, volume[0], volume[1], 44100/60, 32000/60+2, 44100, 32000); + //retainedSamples = Resampler.UpSampleAndMix(audioL, audioR, mpegL, mpegR, volume[0], volume[1], 44100/60, 32000/60+2, 44100, 32000); + switch (audioChannel) + { + case AudioChannel::stereo: + retainedSamples = Resampler.UpSampleAndMix(audioL, audioR, mpegL, mpegR, volume[0], volume[1], 44100 / 60, 32000 / 60 + 2, 44100, 32000); + break; + case AudioChannel::channel0: + retainedSamples = Resampler.UpSampleAndMix(audioL, audioR, mpegR, mpegR, volume[0], volume[0], 44100 / 60, 32000 / 60 + 2, 44100, 32000); + break; + case AudioChannel::channel1: + retainedSamples = Resampler.UpSampleAndMix(audioL, audioR, mpegL, mpegL, volume[1], volume[1], 44100 / 60, 32000 / 60 + 2, 44100, 32000); + break; + default: + //retainedSamples = Resampler.UpSampleAndMix(audioL, audioR, mpegL, mpegR, volume[0], volume[1], 44100 / 60, 32000 / 60 + 2, 44100, 32000); + break; + } + } void CDSB2::Reset(void) @@ -1172,6 +1218,7 @@ bool CDSB2::Init(const UINT8 *progROMPtr, const UINT8 *mpegROMPtr) M68KAttachBus(this); M68KSetIRQCallback(NULL); // use default behavior (autovector, clear interrupt) M68KGetContext(&M68K); + // MPEG decoder if (OKAY != MPEG_Init()) diff --git a/Src/Model3/DSB.h b/Src/Model3/DSB.h index 0addf51..0c3c3bf 100644 --- a/Src/Model3/DSB.h +++ b/Src/Model3/DSB.h @@ -308,6 +308,9 @@ private: // M68K CPU M68KCtx M68K; + + enum class AudioChannel { stereo, channel0, channel1 }; + AudioChannel audioChannel = AudioChannel::stereo; };