#include "adx.h" #include "../util.h" void decode_adx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) { int i=first_sample; int32_t sample_count; int32_t scale = read_16bitBE(stream->offset,stream->streamfile) + 1; int32_t hist1 = stream->adpcm_history1_32; int32_t hist2 = stream->adpcm_history2_32; int coef1 = stream->adpcm_coef[0]; int coef2 = stream->adpcm_coef[1]; for (i=first_sample,sample_count=0; ioffset+2+i/2,stream->streamfile); outbuf[sample_count] = clamp16( (i&1? get_low_nibble_signed(sample_byte): get_high_nibble_signed(sample_byte) ) * scale + ((coef1 * hist1 + coef2 * hist2) >> 12) ); hist2 = hist1; hist1 = outbuf[sample_count]; } stream->adpcm_history1_32 = hist1; stream->adpcm_history2_32 = hist2; }