mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-24 03:44:13 +08:00
(AdpDecoder): made re-usable.
This commit is contained in:
parent
45e086583c
commit
c864eaa606
@ -91,9 +91,20 @@ namespace GameRes.Formats.Abogado
|
|||||||
|
|
||||||
internal class AdpDecoder
|
internal class AdpDecoder
|
||||||
{
|
{
|
||||||
int prev_sample = 0;
|
int prev_sample;
|
||||||
int quant_idx = 0;
|
int quant_idx = 0;
|
||||||
|
|
||||||
|
public AdpDecoder (int init_sample = 0)
|
||||||
|
{
|
||||||
|
prev_sample = init_sample;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset (short s, int q)
|
||||||
|
{
|
||||||
|
prev_sample = s;
|
||||||
|
quant_idx = q;
|
||||||
|
}
|
||||||
|
|
||||||
public short DecodeSample (int sample)
|
public short DecodeSample (int sample)
|
||||||
{
|
{
|
||||||
sample &= 0xF;
|
sample &= 0xF;
|
||||||
@ -103,13 +114,14 @@ namespace GameRes.Formats.Abogado
|
|||||||
quant_idx = 0;
|
quant_idx = 0;
|
||||||
else if (quant_idx > 0x58)
|
else if (quant_idx > 0x58)
|
||||||
quant_idx = 0x58;
|
quant_idx = 0x58;
|
||||||
|
int step = (2 * (sample & 7) + 1) * quant >> 3;
|
||||||
if (sample < 8)
|
if (sample < 8)
|
||||||
{
|
{
|
||||||
sample = Math.Min (0x7FFF, prev_sample + (((2 * sample + 1) * quant) >> 3));
|
sample = Math.Min (0x7FFF, prev_sample + step);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sample = Math.Max (-32768, prev_sample - ((2 * (sample & 7) + 1) * quant >> 3));
|
sample = Math.Max (-32768, prev_sample - step);
|
||||||
}
|
}
|
||||||
prev_sample = sample;
|
prev_sample = sample;
|
||||||
return (short)sample;
|
return (short)sample;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user