# HG changeset patch # User reimar # Date 1215857320 0 # Node ID 7aa646bb75899efe1e8b42a264133d2d2d719a65 # Parent 6a283385441b25a5f90cfe4afe7c5c416f513d31 Simplify and clamp coefficient index for MS ADPCM diff -r 6a283385441b -r 7aa646bb7589 libmpcodecs/ad_msadpcm.c --- a/libmpcodecs/ad_msadpcm.c Sat Jul 12 09:23:14 2008 +0000 +++ b/libmpcodecs/ad_msadpcm.c Sat Jul 12 10:08:40 2008 +0000 @@ -91,10 +91,21 @@ return CONTROL_UNKNOWN; } +static inline int check_coeff(uint8_t c) { + if (c > 6) { + mp_msg(MSGT_DECAUDIO, MSGL_WARN, + "MS ADPCM: coefficient (%d) out of range (should be [0..6])\n", + c); + c = 6; + } + return c; +} + static int ms_adpcm_decode_block(unsigned short *output, unsigned char *input, int channels, int block_size) { int current_channel = 0; + int coeff_idx; int idelta[2]; int sample1[2]; int sample2[2]; @@ -112,21 +123,15 @@ return -1; // fetch the header information, in stereo if both channels are present - if (input[stream_ptr] > 6) - mp_msg(MSGT_DECAUDIO, MSGL_WARN, - "MS ADPCM: coefficient (%d) out of range (should be [0..6])\n", - input[stream_ptr]); - coeff1[0] = ms_adapt_coeff1[input[stream_ptr]]; - coeff2[0] = ms_adapt_coeff2[input[stream_ptr]]; + coeff_idx = check_coeff(input[stream_ptr]); + coeff1[0] = ms_adapt_coeff1[coeff_idx]; + coeff2[0] = ms_adapt_coeff2[coeff_idx]; stream_ptr++; if (channels == 2) { - if (input[stream_ptr] > 6) - mp_msg(MSGT_DECAUDIO, MSGL_WARN, - "MS ADPCM: coefficient (%d) out of range (should be [0..6])\n", - input[stream_ptr]); - coeff1[1] = ms_adapt_coeff1[input[stream_ptr]]; - coeff2[1] = ms_adapt_coeff2[input[stream_ptr]]; + coeff_idx = check_coeff(input[stream_ptr]); + coeff1[1] = ms_adapt_coeff1[coeff_idx]; + coeff2[1] = ms_adapt_coeff2[coeff_idx]; stream_ptr++; }