From c864eaa606b86e3d727491aed348d3a67dbc5655 Mon Sep 17 00:00:00 2001 From: morkt Date: Wed, 13 Dec 2017 13:25:17 +0400 Subject: [PATCH] (AdpDecoder): made re-usable. --- ArcFormats/Abogado/AudioADP.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ArcFormats/Abogado/AudioADP.cs b/ArcFormats/Abogado/AudioADP.cs index 12447ab9..e9ce9a7b 100644 --- a/ArcFormats/Abogado/AudioADP.cs +++ b/ArcFormats/Abogado/AudioADP.cs @@ -91,9 +91,20 @@ namespace GameRes.Formats.Abogado internal class AdpDecoder { - int prev_sample = 0; + int prev_sample; 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) { sample &= 0xF; @@ -103,13 +114,14 @@ namespace GameRes.Formats.Abogado quant_idx = 0; else if (quant_idx > 0x58) quant_idx = 0x58; + int step = (2 * (sample & 7) + 1) * quant >> 3; if (sample < 8) { - sample = Math.Min (0x7FFF, prev_sample + (((2 * sample + 1) * quant) >> 3)); + sample = Math.Min (0x7FFF, prev_sample + step); } else { - sample = Math.Max (-32768, prev_sample - ((2 * (sample & 7) + 1) * quant >> 3)); + sample = Math.Max (-32768, prev_sample - step); } prev_sample = sample; return (short)sample;