+
+
+/*
+ * EA ADPCM
+ */
+#define MAX_CHAN 5
+static void DecodeAdpcmEA( decoder_t *p_dec, int16_t *p_sample,
+ uint8_t *p_buffer )
+{
+ static const uint32_t EATable[]=
+ {
+ 0x00000000, 0x000000F0, 0x000001CC, 0x00000188,
+ 0x00000000, 0x00000000, 0xFFFFFF30, 0xFFFFFF24,
+ 0x00000000, 0x00000001, 0x00000003, 0x00000004,
+ 0x00000007, 0x00000008, 0x0000000A, 0x0000000B,
+ 0x00000000, 0xFFFFFFFF, 0xFFFFFFFD, 0xFFFFFFFC
+ };
+ decoder_sys_t *p_sys = p_dec->p_sys;
+ uint8_t *p_end;
+ unsigned i_channels, c;
+ int16_t *prev, *cur;
+ int32_t c1[MAX_CHAN], c2[MAX_CHAN];
+ int8_t d[MAX_CHAN];
+
+ i_channels = p_dec->fmt_in.audio.i_channels;
+ p_end = &p_buffer[p_sys->i_block];
+
+ prev = (int16_t *)p_dec->fmt_in.p_extra;
+ cur = prev + i_channels;
+
+ for (c = 0; c < i_channels; c++)
+ {
+ uint8_t input;
+
+ input = p_buffer[c];
+ c1[c] = EATable[input >> 4];
+ c2[c] = EATable[(input >> 4) + 4];
+ d[c] = (input & 0xf) + 8;
+ }
+
+ for( p_buffer += i_channels; p_buffer < p_end ; p_buffer += i_channels)
+ {
+ for (c = 0; c < i_channels; c++)
+ {
+ int32_t spl;
+
+ spl = (p_buffer[c] >> 4) & 0xf;
+ spl = (spl << 0x1c) >> d[c];
+ spl = (spl + cur[c] * c1[c] + prev[c] * c2[c] + 0x80) >> 8;
+ CLAMP( spl, -32768, 32767 );
+ prev[c] = cur[c];
+ cur[c] = spl;
+
+ *(p_sample++) = spl;
+ }
+
+ for (c = 0; c < i_channels; c++)
+ {
+ int32_t spl;
+
+ spl = p_buffer[c] & 0xf;
+ spl = (spl << 0x1c) >> d[c];
+ spl = (spl + cur[c] * c1[c] + prev[c] * c2[c] + 0x80) >> 8;
+ CLAMP( spl, -32768, 32767 );
+ prev[c] = cur[c];
+ cur[c] = spl;
+
+ *(p_sample++) = spl;
+ }
+ }
+}