This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320VC5509A: TDM MCBSP Vocoder initialization value for Silence values as 0xD5

Part Number: TMS320VC5509A

Hi ,

       I am using TDM MCBSP Hardware Vocoder. For Genarating Vocoder Output Long back we have done memset with memset( &( TdmTxBuffer0[ 0 ] ), TDM_IDLE_VALUE, 2 * TDM_TS_HW0 );

       Where We keep TDM_IDLE_VALUE as 0x350.  Whith this value Silence value is genearted as 0xff. But we want A -law Silence value as 0xD5. RCR20 is initialized with 0x0019(A - law companding).

        Please let me know what value we should use to initalize vocoder for 0xD5?

Aditya

  • I am not familiar to McBSP Vocoder. I will check it for you.

  • No its not what I am asking.What should be tdm Highway init value for MCBSP TI? If Its used 0x350 what significance it has?

  • My apologies for late response. I have forwarded your question to our C5x expert.

  • Hi Aditya,

    Attached please find the A-law codec in C#. You should be able to find out the value to initalize vocoder for 0xD5.

    Best regards,

    Ming

    ----------------------------------- Cut Here ------------------------------------------

    A-law Encoding

    A-law is even worse documented than µ-law. The implementations are even worse in terms of commenting, so this took a bit longer to figure out. In the end, it is indeed similar to µ-law's implementation, despite how different the A-law C code looks from the µ-law C code.

    There is no zero trap, and the ALawEncode overloads are identical to the MuLawEncode overloads, so the only difference is the encode(short i) method, and that the MAX is 0x7fff instead of (0x7fff-0x84) like in MuLawEncoder.

    C#
    private static byte encode(int pcm)
    {
        //Get the sign bit. Shift it for later use 
        //without further modification
        int sign = (pcm & 0x8000) >> 8;
        //If the number is negative, 
        //make it positive (now it's a magnitude)
        if (sign != 0)
            pcm = -pcm;
        //The magnitude must fit in 15 bits to avoid overflow
        if (pcm > MAX) pcm = MAX;
    
        /* Finding the "exponent"
         * Bits:
         * 1 2 3 4 5 6 7 8 9 A B C D E F G
         * S 7 6 5 4 3 2 1 0 0 0 0 0 0 0 0
         * We want to find where the first 1 after the sign bit is.
         * We take the corresponding value 
         * from the second row as the exponent value.
         * (i.e. if first 1 at position 7 -> exponent = 2)
         * The exponent is 0 if the 1 is not found in bits 2 through 8.
         * This means the exponent is 0 even if the "first 1" doesn't exist.
         */
        int exponent = 7;
        //Move to the right and decrement exponent 
        //until we hit the 1 or the exponent hits 0
        for (int expMask = 0x4000; (pcm & expMask) == 0 
             && exponent>0; exponent--, expMask >>= 1) { }
    
        /* The last part - the "mantissa"
         * We need to take the four bits after the 1 we just found.
         * To get it, we shift 0x0f :
         * 1 2 3 4 5 6 7 8 9 A B C D E F G
         * S 0 0 0 0 0 1 . . . . . . . . . (say that exponent is 2)
         * . . . . . . . . . . . . 1 1 1 1
         * We shift it 5 times for an exponent of two, meaning
         * we will shift our four bits (exponent + 3) bits.
         * For convenience, we will actually just
         * shift the number, then AND with 0x0f. 
         * 
         * NOTE: If the exponent is 0:
         * 1 2 3 4 5 6 7 8 9 A B C D E F G
         * S 0 0 0 0 0 0 0 Z Y X W V U T S (we know nothing about bit 9)
         * . . . . . . . . . . . . 1 1 1 1
         * We want to get ZYXW, which means a shift of 4 instead of 3
         */
        int mantissa = (pcm >> ((exponent == 0) ? 4 : (exponent + 3))) & 0x0f;
    
        //The a-law byte bit arrangement is SEEEMMMM 
        //(Sign, Exponent, and Mantissa.)
        byte alaw = (byte)(sign | exponent << 4 | mantissa);
    
        //Last is to flip every other bit, and the sign bit (0xD5 = 1101 0101)
        return (byte)(alaw^0xD5);
    }

    Even this has only subtle differences. The mask, lack of bias, and the zero exponent weirdness are the key differences.

    A-Law Decoding

    The only difference between this and MuLawDecoder is the decode(short i) method.

    C#
    private static short decode(byte alaw)
    {
        //Invert every other bit, 
        //and the sign bit (0xD5 = 1101 0101)
        alaw ^= 0xD5;
    
        //Pull out the value of the sign bit
        int sign = alaw & 0x80;
        //Pull out and shift over the value of the exponent
        int exponent = (alaw & 0x70) >> 4;
        //Pull out the four bits of data
        int data = alaw & 0x0f;
    
        //Shift the data four bits to the left
        data <<= 4;
        //Add 8 to put the result in the middle 
        //of the range (like adding a half)
        data += 8;
        
        //If the exponent is not 0, then we know the four bits followed a 1,
        //and can thus add this implicit 1 with 0x100.
        if (exponent != 0)
            data += 0x100;
        /* Shift the bits to where they need to be: left (exponent - 1) places
         * Why (exponent - 1) ?
         * 1 2 3 4 5 6 7 8 9 A B C D E F G
         * . 7 6 5 4 3 2 1 . . . . . . . . <-- starting bit (based on exponent)
         * . . . . . . . Z x x x x 1 0 0 0 <-- our data (Z is 0 only when <BR>     * exponent is 0)
         * We need to move the one under the value of the exponent,
         * which means it must move (exponent - 1) times
         * It also means shifting is unnecessary if exponent is 0 or 1.
         */
        if (exponent > 1)
            data <<= (exponent - 1);
    
        return (short)(sign == 0 ? data : -data);
    }

    That's it for the encoders and decoders.