微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > MCU和DSP > adpcm音频压缩算法源代码

adpcm音频压缩算法源代码

时间:03-23 来源: 点击:

outp = outdata;
inp = (signed char *)indata;

valpred = state->valprev;
index = state->index;
step = stepsizeTable[index];

bufferstep = 0;

for ( ; len > 0 ; len-- ) {

/* Step 1 - get the delta value */
if ( bufferstep ) {
delta = inputbuffer & 0xf;
} else {
inputbuffer = *inp++;
delta = (inputbuffer >> 4) & 0xf;
}
bufferstep = !bufferstep;

/* Step 2 - Find new index value (for later) */
index += indexTable[delta];
if ( index < 0 ) index = 0;
if ( index > 88 ) index = 88;

/* Step 3 - Separate sign and magnitude */
sign = delta & 8;
delta = delta & 7;

/* Step 4 - Compute difference and new predicted value */
/*
** Computes 'vpdiff = (delta+0.5)*step/4', but see comment
** in adpcm_coder.
*/
vpdiff = step >> 3;
if ( delta & 4 ) vpdiff += step;
if ( delta & 2 ) vpdiff += step>>1;
if ( delta & 1 ) vpdiff += step>>2;

if ( sign )
valpred -= vpdiff;
else
valpred += vpdiff;

/* Step 5 - clamp output value */
if ( valpred > 32767 )
valpred = 32767;
else if ( valpred < -32768 )
valpred = -32768;

/* Step 6 - Update step value */
step = stepsizeTable[index];

/* Step 7 - Output value */
*outp++ = valpred;
}

state->valprev = valpred;
state->index = index;
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top