Skip to content

Commit

Permalink
adpcm: Separate panning and clock ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
negativeExponent committed Aug 15, 2024
1 parent 58cba3c commit 842d04e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
34 changes: 20 additions & 14 deletions x68k/adpcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ static uint8_t ADPCM_Playing = 0;
static uint8_t ADPCM_Clock = 0;
static int32_t ADPCM_PreCounter = 0;
static int32_t ADPCM_DifBuf = 0;
static uint8_t ADPCM_Ratio = 0;
static uint8_t ADPCM_Pan = 0;

static int32_t ADPCM_Pan = 0x00;
static int32_t OldR = 0, OldL = 0;
static int32_t Outs[8];
static int32_t OutsIp[4];
Expand Down Expand Up @@ -332,28 +333,30 @@ void ADPCM_SetVolume(uint8_t vol)
ADPCM_VolumeShift = 0;
}

void ADPCM_SetPan(int n)
void ADPCM_SetClock(uint8_t clock)
{
if ((ADPCM_Pan & 0x0c) != (n & 0x0c))
{
ADPCM_Count = 0;
ADPCM_Clock = (ADPCM_Clock & 4) | ((n >> 2) & 3);
ADPCM_ClockRate = ADPCM_Clocks[ADPCM_Clock];
}

ADPCM_Pan = n;
ADPCM_Count = 0;
ADPCM_Clock = clock | (ADPCM_Ratio & 3);
ADPCM_ClockRate = ADPCM_Clocks[ADPCM_Clock];
}

void ADPCM_SetClock(int n)
void ADPCM_SetRatio(uint8_t ratio)
{
if ((ADPCM_Clock & 4) != n)
if (ADPCM_Ratio != ratio)
{
ADPCM_Ratio = ratio;

ADPCM_Count = 0;
ADPCM_Clock = n | ((ADPCM_Pan >> 2) & 3);
ADPCM_Clock = (ADPCM_Clock & 4) | ratio;
ADPCM_ClockRate = ADPCM_Clocks[ADPCM_Clock];
}
}

void ADPCM_SetPan(uint8_t pan)
{
ADPCM_Pan = 0;
}

void ADPCM_Init(uint32_t samplerate)
{
ADPCM_WrPtr = 0;
Expand All @@ -373,7 +376,9 @@ void ADPCM_Init(uint32_t samplerate)

OldL = OldR = 0;

ADPCM_SetPan(0x0b);
ADPCM_SetPan(0x03);
ADPCM_SetRatio(0x02);

ADPCM_InitTable();
}

Expand All @@ -396,6 +401,7 @@ int ADPCM_StateContext(void *f, int writing) {
state_context_f(&ADPCM_DifBuf, sizeof(ADPCM_DifBuf));

state_context_f(&ADPCM_Pan, sizeof(ADPCM_Pan));
state_context_f(&ADPCM_Ratio, sizeof(ADPCM_Ratio));
state_context_f(&OldR, sizeof(OldR));
state_context_f(&OldL, sizeof(OldL));
state_context_f(Outs, sizeof(Outs));
Expand Down
5 changes: 3 additions & 2 deletions x68k/adpcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
void FASTCALL ADPCM_PreUpdate(int32_t clock);
void FASTCALL ADPCM_Update(int16_t *buffer, int32_t length, int16_t *pbsp, int16_t *pbep);
void ADPCM_SetVolume(uint8_t vol);
void ADPCM_SetPan(int n);
void ADPCM_SetClock(int n);
void ADPCM_SetPan(uint8_t pan);
void ADPCM_SetClock(uint8_t clock);
void ADPCM_SetRatio(uint8_t ratio);
void ADPCM_Init(uint32_t samplerate);
int ADPCM_IsReady(void);

Expand Down
5 changes: 3 additions & 2 deletions x68k/pia.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ static void PIA_SetPortC(uint32_t data)
portc = pia.PortC;
pia.PortC = data;

if ((portc & 0x0f) != (pia.PortC & 0x0f))
ADPCM_SetPan(pia.PortC & 0x0f);
ADPCM_SetPan(data & 3);

ADPCM_SetRatio((data >> 2) & 3);

if ((portc & 0x10) != (pia.PortC & 0x10))
Joystick_Write(0, (uint8_t)((data & 0x10) ? 0xff : 0x00));
Expand Down

0 comments on commit 842d04e

Please sign in to comment.