DSPRelated.com
Forums

ADPCM ITU C code

Started by Meenakshi Matai June 14, 2004
Hello,

I am working on implementing the G.726 ADPCM algorithm.

In the C code obtained from ITU, there's a function called "update". It
is present in the "g72x.c" file.
The first few lines of the function look like this:
ylint = (short int)state_ptr->yl >> 15; /* exponent part of yl */
ylfrac = (state_ptr->yl >> 10) & 0x1F; /* fractional part of yl */
thr1 = (32 + ylfrac) << ylint; /* threshold */
thr2 = (ylint > 9) ? 31 << 10 : thr1; /* limit thr2 to 31 << 10 */
dqthr = (thr2 + (thr2 >> 1)) >> 1; /* dqthr = 0.75 * thr2 */
if (state_ptr->td == 0) /* signal supposed voice */
tr = 0;
else if (mag <= dqthr) /* supposed data, but small mag */
tr = 0; /* treated as voice */
else /* signal is data (modem) */
tr = 1; For people who have seen this function (from ITU) earlier, I have a
question.
If I am trying to do a PC simulation of this ADPCM algorithm, then what
happens when the variable "ylint" is negative.
How does it effect the left shift in this line:
thr1 = (32 + ylfrac) << ylint; /* threshold */

The above part of the code causes
"tr=1" which causes all my variables to reset and start all over from
the beginning.
I tried to modify the code, such that when "ylint" is negative, it
actually does a right shift.
That corrects the problem of reset.

But yet I see that my output is bound by certain limits. The output is
not able to catch up if the input amplitude is high. It is able to
reproduce the nature in which the input varies, but it is much smaller
in amplitude. The output looks like the input scaled down in amplitude.

Could somebody please let me know if they have seen similar problems
with the ITU ADPCM code.
Are there any changes/ modifications to the code that might help me.

Thanks in advance for your help,
Meenakshi.