ima_adpcm_state_t decode_ima_adpcm_u8_i16(unsigned char* input, short* output, int input_length, ima_adpcm_state_t state) { int k=0; for(int i=0;i<input_length;i++) { output[k++]=ImaAdpcmDecode(input[i]&0xf,&state); output[k++]=ImaAdpcmDecode( (input[i]>>4)&0xf,&state); } return state; }
void decode_ima_adpcm_e8_i16(unsigned char* input, short* output, int input_length, ima_adpcm_state_t *state) { state->pos_clamp = +32767; state->neg_clamp = -32768; int i, k=0; for (i=0; i<input_length; i++) { output[k++] = ImaAdpcmDecode(input[i]&0xf, state); output[k++] = ImaAdpcmDecode((input[i]>>4)&0xf, state); } }
void decode_ima_adpcm_e8_u8(unsigned char* input, unsigned char* output, int input_length, ima_adpcm_state_t *state) { // not +127 / -128 because unsigned state->pos_clamp = 255; state->neg_clamp = 0; int i, k=0; for (i=0; i<input_length; i++) { output[k++] = ImaAdpcmDecode(input[i]&0xf, state); output[k++] = ImaAdpcmDecode((input[i]>>4)&0xf, state); } }
static inline unsigned char ImaAdpcmEncode(short sample, ima_adpcm_state_t* state) { int diff = sample - state->previousValue; int step = _stepSizeTable[state->index]; int deltaCode = 0; // Set sign bit if (diff < 0) { deltaCode = 8; diff = -diff; } // This is essentially deltaCode = (diff<<2)/step, // except the roundoff is handled differently. if ( diff >= step ) { deltaCode |= 4; diff -= step; } step >>= 1; if ( diff >= step ) { deltaCode |= 2; diff -= step; } step >>= 1; if ( diff >= step ) { deltaCode |= 1; diff -= step; } ImaAdpcmDecode(deltaCode,state); // update state return deltaCode; }