Γενικά
static short qtab_721[7] = {-124,
80, 178, 246, 300, 349, 400};
/*
* Maps G.721 code word to
reconstructed scale factor normalized log
* magnitude values.
*/
static short _dqlntab[16] = {-2048,
4, 135, 213, 273, 323, 373, 425,
425, 373, 323,
273, 213, 135, 4, -2048};
/* Maps G.721 code word to log of
scale factor multiplier. */
static short _witab[16] = {-12,
18, 41, 64, 112, 198, 355, 1122,
1122, 355, 198,
112, 64, 41, 18, -12};
/*
* Maps G.721 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[16] = {0, 0,
0, 0x200, 0x200, 0x200, 0x600, 0xE00,
0xE00, 0x600,
0x200, 0x200, 0x200, 0, 0, 0};
/* Η συνάρτηση g721_encoder()
κωδικοποιεί την εισερχόμενη τιμή ενός
* γραμμικού PCM, A-law
ή Mu-law δεδομένου και επιστρέφει την
* προκύπτουσα
κωδική λέξη . Σε περίπτωση μη αναγνωρίσιμης εισόδου
*
επιστρέφει -1*/
int
g721_encoder(
int sl,
int in_coding,
struct g72x_state *state_ptr)
{
short sezi, se, sez;
/* ACCUM */
short d;
/* SUBTA */
short sr;
/* ADDB */
short y;
/* MIX */
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; /*
14-bit dynamic range */
break;
default:
return (-1);
}
sezi = predictor_zero(state_ptr);
sez = sezi >> 1;
se = (sezi + predictor_pole(state_ptr))
>> 1; /* estimated signal */
d = sl - se; /* estimation difference */
/* quantize the prediction
difference */
y = step_size(state_ptr);
/* quantizer step size */
i = quantize(d, y, qtab_721,
7); /* i = ADPCM code */
dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized est diff */
sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */
dqsez = sr + sez - se; /* pole prediction diff. */
update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
return (i);
ADPCM αποκωδικοποιητής
#include "g72x.h"
static short qtab_721[7] = {-124,
80, 178, 246, 300, 349, 400};
/*
* Maps G.721 code word to
reconstructed scale factor normalized log
* magnitude values.
*/
static short _dqlntab[16] = {-2048,
4, 135, 213, 273, 323, 373, 425,
425, 373, 323,
273, 213, 135, 4, -2048};
/* Maps G.721 code word to log of
scale factor multiplier. */
static short _witab[16] = {-12,
18, 41, 64, 112, 198, 355, 1122,
1122, 355, 198,
112, 64, 41, 18, -12};
/*
* Maps G.721 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[16] = {0, 0,
0, 0x200, 0x200, 0x200, 0x600, 0xE00,
0xE00, 0x600,
0x200, 0x200, 0x200, 0, 0, 0};
/* Η συνάρτηση g721_decoder() αποκωδικοποιεί
ένα τετράμπιτο κωδικό
* που έχει κωδικοποιηθεί
χρησιμοποιώντας κωδικοποιητή G.721 και
* επιστρέφει μια γραμμική
PCM , A-law ή Mu-law τιμή. Σε άγνωστη
* κωδική λέξη επιστρέφει
την τιμή -1.*/
int
g721_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 &= 0x0f;
/* 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);
/* dynamic quantizer step size */
dq = reconstruct(i &
0x08, _dqlntab[i], y); /* quantized diff. */
sr = (dq < 0) ? (se -
(dq & 0x3FFF)) : se + dq; /* reconst. Signal*/
dqsez = sr - se + sez;
/* pole prediction diff. */
update(4, y, _witab[i] <<
5, _fitab[i], dq, sr, dqsez, state_ptr);
switch (out_coding) {
case AUDIO_ENCODING_ALAW:
return (tandem_adjust_alaw(sr,
se, y, i, 8, qtab_721));
case AUDIO_ENCODING_ULAW:
return (tandem_adjust_ulaw(sr,
se, y, i, 8, qtab_721));
case AUDIO_ENCODING_LINEAR:
return (sr << 2);
/* sr was 14-bit dynamic range */
default:
return (-1);
}
}