Skip to content

Commit

Permalink
Add static pre-amplification to both DSP and DTK audio output.
Browse files Browse the repository at this point in the history
This branch was created specifically for GC Spider-Man, which has audio problems that cause it to be extremely loud, and to be so loud at the source that much of the audio in the game is quite clipped by the time it hits the speakers.
  • Loading branch information
Zinfidel committed Apr 6, 2021
1 parent 34a9258 commit abd9806
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions Source/Core/Core/HW/DSPHLE/UCodes/AX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ void AXUCode::SetMainLR(u32 src_addr)

void AXUCode::OutputSamples(u32 lr_addr, u32 surround_addr)
{
// MOD: Pre-amplify by some fraction to prevent clipping in the clamping function.
const double pre_amplification_factor = 0.3;

int surround_buffer[5 * 32];

for (u32 i = 0; i < 5 * 32; ++i)
Expand All @@ -506,8 +509,8 @@ void AXUCode::OutputSamples(u32 lr_addr, u32 surround_addr)
// Output samples clamped to 16 bits and interlaced RLRLRLRLRL...
for (u32 i = 0; i < 5 * 32; ++i)
{
int left = MathUtil::Clamp(m_samples_left[i], -32767, 32767);
int right = MathUtil::Clamp(m_samples_right[i], -32767, 32767);
int left = MathUtil::Clamp((int)(m_samples_left[i]*pre_amplification_factor), -32767, 32767);
int right = MathUtil::Clamp((int)(m_samples_right[i]*pre_amplification_factor), -32767, 32767);

buffer[2 * i + 0] = Common::swap16(right);
buffer[2 * i + 1] = Common::swap16(left);
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/HW/DSPHLE/UCodes/AXVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ u16 AcceleratorGetSample()
temp -= 16;

int val = (scale * temp) + ((0x400 + coef1 * acc_pb->adpcm.yn1 + coef2 * acc_pb->adpcm.yn2) >> 11);
// MOD: Prescaling here seems to ruin the quality of the samples
//val = (int)((double)val * 0.1);
val = MathUtil::Clamp(val, -0x7FFF, 0x7FFF);

acc_pb->adpcm.yn2 = acc_pb->adpcm.yn1;
Expand Down
8 changes: 7 additions & 1 deletion Source/Core/Core/HW/StreamADPCM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ static s16 ADPDecodeSample(s32 bits, s32 q, s32& hist1, s32& hist2)
hist = (hist1 * 0x62) - (hist2 * 0x37);
break;
}
hist = MathUtil::Clamp((hist + 0x20) >> 6, -0x200000, 0x1fffff);
// MOD: Removing this clamp completely relieves the DTK stream of clipping...
//hist = MathUtil::Clamp((hist + 0x20) >> 6, -0x200000, 0x1fffff);
hist = (hist + 0x20) >> 6;

s32 cur = (((s16)(bits << 12) >> (q & 0xf)) << 6) + hist;

hist2 = hist1;
hist1 = cur;

cur >>= 6;

// MOD: Reduce amplitude to 30%
cur = (s32)((double)cur * 0.3);

cur = MathUtil::Clamp(cur, -0x8000, 0x7fff);

return (s16)cur;
Expand Down

0 comments on commit abd9806

Please sign in to comment.