1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

G.726 ADPCM implementation

  1. Oct 13, 2004 #1
    [Urgent] G.726 ADPCM implementation

    I'm trying to implement G.726 ADPCM using the source codes released by Sun Microsystems to the public domain. I subsequently tested my program using the test vectors released by ITU but there were many errors (ie discrepancies between the ADPCM codewords generated by my prog and the ITU-given codewords).

    Can anyone who is experienced in the above implementation advise me on how can I go about debugging my program. I had spent 4 days trying to solve the problem but to no avail!!

    ps. the codes released by Sun is for the the implementation for G.721 but it is similar to what i want (ie 32kbps) so i believe it's safe to use it directly. or am i wrong?

    static short qtab_721[7] = {-124, 80, 178, 246, 300, 349, 400};

    static short _dqlntab[16] =
    {
    -2048, 4, 135, 213, 273, 323, 373, 425,
    425, 373, 323, 273, 213, 135, 4, -2048
    };

    static short _witab[16] =
    {
    -12, 18, 41, 64, 112, 198, 355, 1122,
    1122, 355, 198, 112, 64, 41, 18, -12
    };

    static short _fitab[16] =
    {
    0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00,
    0xE00, 0x600, 0x200, 0x200, 0x200, 0, 0, 0
    };

    // static short _fitab[8] = {0, 0, 0, 1, 1, 1, 3, 7};

    /*
    * Encodes the input value of linear PCM, A-law or u-law data sl and returns
    * the resulting code. -1 is returned for unknown input coding value.
    */
    int ADPCM_encoder(int sl, int in_coding, struct g72x_state *state_ptr)
    {
    short sezi, se, sez; // se is the estimated signal

    short d; // SUBTA => Compute diff signal by subtracting signal estimate
    // from input signal (or quantized reconstructed signal in decoder)
    short sr;// ADDB => Addition of quantized diff signal and signal estimate
    // to form reconstructed signal
    short y; // MIX => Form linear combination of fast and slow
    // quantizer scale factors
    short dqsez; // ADDC => Obtain sign of addition of quantized diff signal
    // and partial signal estimate
    short dq, i;

    static int count = 0;
    FILE *debugPtr;
    debugPtr = fopen("sad.txt", "a");

    switch (in_coding)
    { // linearize input sample to 14-bit PCM
    case AUDIO_ENCODING_ULAW:
    sl = ulaw2linear((unsigned char)sl) >> 2; // sl is complement of orig codeword?
    break;
    case AUDIO_ENCODING_ALAW:
    sl = alaw2linear((unsigned char)sl) >> 2;
    break;
    case AUDIO_ENCODING_LINEAR:
    sl >>= 2; // 14-bit dynamic range
    break;
    default:
    return (-1);
    }
    // **********************
    // * ADAPTIVE PREDICTOR *
    // **********************
    sezi = predictor_zero(state_ptr); // computes estimated signal
    // from 6-zero predictor

    sez = sezi >> 1; // right-shift by 1-bit
    se = (sezi + predictor_pole(state_ptr)) >> 1;// computes estimated
    // signal from 2-pole predictor
    // *********************************
    // * DIFFERENCE SIGNAL COMPUTATION *
    // *********************************
    d = sl - se; // difference between actual and estimated signal

    // **********************
    // * ADAPTIVE QUANTIZER *
    // **********************
    /* quantize the prediction difference */
    y = step_size(state_ptr); // computes quantization step size
    i = quantize(d, y, qtab_721, 7); // quantizes the estimated difference
    // and returns the ADPCM code
    // ******************************
    // * INVERSE ADAPTIVE QUANTIZER *
    // ******************************
    dq = inv_adapt_quan(i & 8, _dqlntab, y); // quantized est diff

    // ***********************************
    // * RECONSTRUCTED SIGNAL CALCULATOR *
    // ***********************************
    sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq;

    dqsez = sr + sez - se; /* pole prediction diff. */

    fprintf(debugPtr, "%6d %6d %6d %6d %6d %6d\n", sl, se, d, y, i, count++);

    update(4, y, _witab << 5, _fitab, dq, sr, dqsez, state_ptr);

    fclose(debugPtr);

    return (i); // ADPCM codeword
    }
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you help with the solution or looking for help too?
Draft saved Draft deleted



Similar Discussions: G.726 ADPCM implementation
  1. Battery implementation (Replies: 3)

Loading...