📄 g726_16.c
字号:
/* * g726_16.c * * Description: * * g726_16_encoder(), g726_16_decoder() * * These routines comprise an implementation of the CCITT G.723 24 Kbps * ADPCM coding algorithm. Essentially, this implementation is identical to * the bit level description except for a few deviations which take advantage * of workstation attributes, such as hardware 2's complement arithmetic. * */#include "g72x.h"/* * Maps G.726_16 code word to reconstructed scale factor normalized log * magnitude values. */static short _dqlntab[4] = {-116, 365, 365, -116};/* Maps G.723_16 code word to log of scale factor multiplier. */static short _witab[4] = {-127, 14, 14, -127};/* * Maps G.723_16 code words to a set of values whose long and short * term averages are computed and then compared to give an indication * how stationary (steady state) the signal is. */static short _fitab[4] = {0, 0xE00, 0xE00, 0};static short qtab_726_16[1] = {261};/* * g726_16_encoder() * * Encodes a linear PCM, A-law or u-law input sample and returns its 2-bit code. * Returns -1 if invalid input coding value. */intg726_16_encoder( int sl, int in_coding, struct g72x_state *state_ptr){ short sei, sezi, se, sez; /* ACCUM */ short d; /* SUBTA */ short y; /* MIX */ short sr; /* ADDB */ short dqsez; /* ADDC */ short dq, i; switch (in_coding) { /* linearize input sample to 14-bit PCM */ case AUDIO_ENCODING_ALAW: sl = alaw2linear(sl) >> 2; break; case AUDIO_ENCODING_ULAW: sl = ulaw2linear(sl) >> 2; break; case AUDIO_ENCODING_LINEAR: sl >>= 2; /* sl of 14-bit dynamic range */ break; default: return (-1); } sezi = predictor_zero(state_ptr); sez = sezi >> 1; sei = sezi + predictor_pole(state_ptr); se = sei >> 1; /* se = estimated signal */ d = sl - se; /* d = estimation diff. */ /* quantize prediction difference d */ y = step_size(state_ptr); /* quantizer step size */ i = quantize(d, y, qtab_726_16, 1); /* i = ADPCM code */ dq = reconstruct(i & 2, _dqlntab[i], y); /* quantized diff. */ sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconstructed signal */ dqsez = sr + sez - se; /* pole prediction diff. */ update(1, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr); return (i);}/* * g726_16_decoder() * * Decodes a 2-bit CCITT G.726_16 ADPCM code and returns * the resulting 16-bit linear PCM, A-law or u-law sample value. * -1 is returned if the output coding is unknown. */intg726_16_decoder( int i, int out_coding, struct g72x_state *state_ptr){ short sezi, sei, sez, se; /* ACCUM */ short y; /* MIX */ short sr; /* ADDB */ short dq; short dqsez; i &= 0x03; /* mask to get proper bits */ sezi = predictor_zero(state_ptr); sez = sezi >> 1; sei = sezi + predictor_pole(state_ptr); se = sei >> 1; /* se = estimated signal */ y = step_size(state_ptr); /* adaptive quantizer step size */ dq = reconstruct(i & 0x02, _dqlntab[i], y); /* unquantize pred diff */ sr = (dq < 0) ? (se - (dq & 0x3FFF)) : (se + dq); /* reconst. signal */ dqsez = sr - se + sez; /* pole prediction diff. */ update(3, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr); switch (out_coding) { case AUDIO_ENCODING_ALAW: return (tandem_adjust_alaw(sr, se, y, i, 4, qtab_726_16)); case AUDIO_ENCODING_ULAW: return (tandem_adjust_ulaw(sr, se, y, i, 4, qtab_726_16)); case AUDIO_ENCODING_LINEAR: return (sr << 2); /* sr was of 14-bit dynamic range */ default: return (-1); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -