Skip to content

Commit

Permalink
SPU: Zero out upper ADPCM filters
Browse files Browse the repository at this point in the history
Also in CD-ROM.
  • Loading branch information
stenzek committed Nov 24, 2024
1 parent 40a1bee commit b71b7b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
13 changes: 5 additions & 8 deletions src/core/cdrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ union XA_ADPCMBlockHeader
u8 bits;

BitField<u8, u8, 0, 4> shift;
BitField<u8, u8, 4, 2> filter;
BitField<u8, u8, 4, 4> filter;

// For both 4bit and 8bit ADPCM, reserved shift values 13..15 will act same as shift=9).
u8 GetShift() const
Expand Down Expand Up @@ -3415,11 +3415,8 @@ s16 CDROM::SaturateVolume(s32 volume)
template<bool IS_STEREO, bool IS_8BIT>
void CDROM::DecodeXAADPCMChunks(const u8* chunk_ptr, s16* samples)
{
static constexpr std::array<s8, 16> s_xa_adpcm_filter_table_pos = {
{0, 60, 115, 98, 122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};

static constexpr std::array<s8, 16> s_xa_adpcm_filter_table_neg = {
{0, 0, -52, -55, -60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
static constexpr std::array<s8, 16> filter_table_pos = {{0, 60, 115, 98, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
static constexpr std::array<s8, 16> filter_table_neg = {{0, 0, -52, -55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};

// The data layout is annoying here. Each word of data is interleaved with the other blocks, requiring multiple
// passes to decode the whole chunk.
Expand All @@ -3440,8 +3437,8 @@ void CDROM::DecodeXAADPCMChunks(const u8* chunk_ptr, s16* samples)
const XA_ADPCMBlockHeader block_header{headers_ptr[block]};
const u8 shift = block_header.GetShift();
const u8 filter = block_header.GetFilter();
const s32 filter_pos = s_xa_adpcm_filter_table_pos[filter];
const s32 filter_neg = s_xa_adpcm_filter_table_neg[filter];
const s32 filter_pos = filter_table_pos[filter];
const s32 filter_neg = filter_table_neg[filter];

s16* out_samples_ptr =
IS_STEREO ? &samples[(block / 2) * (WORDS_PER_BLOCK * 2) + (block % 2)] : &samples[block * WORDS_PER_BLOCK];
Expand Down
8 changes: 4 additions & 4 deletions src/core/spu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ struct ADPCMBlock
u8 bits;

BitField<u8, u8, 0, 4> shift;
BitField<u8, u8, 4, 3> filter;
BitField<u8, u8, 4, 4> filter;
} shift_filter;
ADPCMFlags flags;
u8 data[NUM_SAMPLES_PER_ADPCM_BLOCK / 2];
Expand All @@ -201,7 +201,7 @@ struct ADPCMBlock
return (shift > 12) ? 9 : shift;
}

u8 GetFilter() const { return std::min<u8>(shift_filter.filter, 4); }
u8 GetFilter() const { return shift_filter.shift; }

u8 GetNibble(u32 index) const { return (data[index / 2] >> ((index % 2) * 4)) & 0x0F; }
};
Expand Down Expand Up @@ -1877,8 +1877,8 @@ void SPU::Voice::TickADSR()

void SPU::Voice::DecodeBlock(const ADPCMBlock& block)
{
static constexpr std::array<s32, 5> filter_table_pos = {{0, 60, 115, 98, 122}};
static constexpr std::array<s32, 5> filter_table_neg = {{0, 0, -52, -55, -60}};
static constexpr std::array<s8, 16> filter_table_pos = {{0, 60, 115, 98, 122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
static constexpr std::array<s8, 16> filter_table_neg = {{0, 0, -52, -55, -60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};

// store samples needed for interpolation
current_block_samples[2] = current_block_samples[NUM_SAMPLES_FROM_LAST_ADPCM_BLOCK + NUM_SAMPLES_PER_ADPCM_BLOCK - 1];
Expand Down

0 comments on commit b71b7b4

Please sign in to comment.