mirror of
https://github.com/libretro/beetle-pce-fast-libretro.git
synced 2024-11-26 17:40:40 +00:00
OKIADPCMEncoder
This commit is contained in:
parent
ea1b6ab280
commit
ec42102685
@ -108,54 +108,4 @@ class OKIADPCM_Decoder
|
||||
int32 CurSample;
|
||||
int32 StepSizeIndex;
|
||||
};
|
||||
|
||||
template <OKIADPCM_Chip CHIP_TYPE>
|
||||
class OKIADPCM_Encoder
|
||||
{
|
||||
public:
|
||||
|
||||
OKIADPCM_Encoder()
|
||||
{
|
||||
Accum = 0x800;
|
||||
StepSizeIndex = 0;
|
||||
}
|
||||
|
||||
~OKIADPCM_Encoder()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uint8 EncodeSample(uint16 in_sample)
|
||||
{
|
||||
uint8 nibble = 0;
|
||||
int32 sample_delta = in_sample - Accum;
|
||||
int piece;
|
||||
|
||||
piece = (abs(sample_delta) * 4 / OKIADPCM_StepSizes[StepSizeIndex]);
|
||||
if(piece > 0x7)
|
||||
piece = 0x7;
|
||||
|
||||
nibble = ((uint32)(sample_delta >> 31) & 0x8) | piece;
|
||||
|
||||
// Update Accum and StepSizeIndex!
|
||||
Accum += OKIADPCM_DeltaTable[StepSizeIndex][nibble];
|
||||
StepSizeIndex += OKIADPCM_StepIndexDeltas[nibble];
|
||||
|
||||
if(Accum > 0xFFF) Accum = 0xFFF;
|
||||
if(Accum < 0) Accum = 0;
|
||||
|
||||
if(StepSizeIndex < 0)
|
||||
StepSizeIndex = 0;
|
||||
|
||||
if(StepSizeIndex > 48)
|
||||
StepSizeIndex = 48;
|
||||
|
||||
return(nibble);
|
||||
}
|
||||
|
||||
private:
|
||||
int32 Accum;
|
||||
int32 StepSizeIndex;
|
||||
OKIADPCM_Chip ChipType;
|
||||
};
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user