2008-07-12 05:11:18     G729 encode problem

Document created by Aaronwu Employee on Aug 7, 2013
Version 1Show Document
  • View in full screen mode

2008-07-12 05:11:18     G729 encode problem

hong li (CHINA)

Message: 58717   




    everyone, I am using  g729  library  on my bf561,  I have test the libbrary successfully,  However  there is  a  problem  which puzzles me.


why the SINEA.BIT  is larger than SINE.BIN?


the SINEA.BIT is the output file  after encoding, SINEA.BIT is in the /test_data/g729a/std_out_en


the SINE.BIN  is  the  original file   ,                     SINE.BIN is in the /test_data/g729a/std_in_en


generally  , the file after encoding  is much smaller than  the orginal file.








2008-07-13 22:28:59     Re: G729 encode problem


Message: 58731   


It may use unpaced mode - i.e, each bit is reprensented using a 16-bit word.




2008-07-14 01:00:38     Re: G729 encode problem

hong li (CHINA)

Message: 58742   




   because  we  want  to  send  the audio data by the wireless  network  and  the original audio data is too large,   therefor, the original  audio data must be compressed .


How to use the packed mode ? How to compress the original data by the libbfgots ' API?








2008-07-14 01:43:33     Re: G729 encode problem

hong li (CHINA)

Message: 58743   




I read the g729ab_test.c and find  in the test_encoder founction, the orginial data is inst_pcm_buf[80], however, the output data after encoding is inst_index_buf[82], why?


if I want to compress the data, how to set the length of inst_index_buf?


the encode founction is: G729AB_ENC(inst_g729_enc_h, inst_pcm_buf, inst_index_buf);


the founction as follow:


int test_encoder(int mode, FILE *fin, FILE *fbit, float *av_mips, int multi, int thread_id)


  G729_EncObj inst_g729_enc      __attribute__ ((aligned (4)));

  G729_enc_h  inst_g729_enc_h    __attribute__ ((aligned (4)));


  short       inst_pcm_buf[80]   __attribute__ ((aligned (4)));

  short       inst_index_buf[82] __attribute__ ((aligned (4)));

  short       result_buf[82];


  int         frame_num = 0;

  int         i = 0;

  int         len;

  int         before, time;


  memset(&inst_pcm_buf, 80 * 2, 0);

  memset(&inst_index_buf, 82 * 2, 0);


  /* Init encoder */


  inst_g729_enc_h = &inst_g729_enc;

  (*g729ab_enc_reset) (inst_g729_enc_h);

  G729AB_ENC_CONFIG(inst_g729_enc_h, G729_ENC_OUTPUTFORMAT, 1);

  G729AB_ENC_CONFIG(inst_g729_enc_h, G729_ENC_VAD, mode);


  time = 0;

  while ((fread(inst_pcm_buf, 2, 80, fin) == 80)) {

    //fprintf(stderr, "thread: %d - frame: %d\n", thread_id, frame_num);

    before = cycles();

    G729AB_ENC(inst_g729_enc_h, inst_pcm_buf, inst_index_buf);

    time += cycles() - before;


    /* simulate "hurry up and wait" of real time systems when

       testing in multi-threaded mode */


    if (multi) usleep(10000);


    /* Verify */


    if (mode) {

      len = fread_a_frame(fbit, result_buf);

    } else {

      len = fread(result_buf, sizeof(short), 82, fbit);


    for (i=0; i<len; i++) {


      if (result_buf[i] != inst_index_buf[i]) {

fprintf(stderr, "diff:%d %hx, %hx\n",

  frame_num*82 + i, inst_index_buf[i], result_buf[i]);

return -1;







  *av_mips = (float)(time/frame_num)*(FRAMES_PER_SEC/1E6);


  return 0;










2008-07-14 04:13:05     Re: G729 encode problem


Message: 58748   


If you read the README.txt in libbfgdots/g729/, you will read:


Bitstream formats:


   using 0x6b21 as SYNC word for each frame



   Packed mode:

     - g729a:



     - g729ab:

     three kinds of frames

        -- BIT_NUM = 0x0050

        -- BIT_NUM = 0x0010

        -- BIT_NUM = 0x0000


   Unpacked mode:

     each bit is encoded using a 16-bit word:

       - 0x007F for 0

       - 0x0081 for 1

To use packed format:


G729AB_ENC_CONFIG(inst_g729_enc_h, G729_ENC_OUTPUTFORMAT, 0);


to use unpacked format:


G729AB_ENC_CONFIG(inst_g729_enc_h, G729_ENC_OUTPUTFORMAT, 1);


You can refer to: uclinux-dist/user/blkfin-apps/linphone/g729_patch


for some real example of using g729 lib in linphone.


However, we tested linphone with some VoIP phones, the format of those phones is a little different. You can read the patch for details. They do not use header, and they do not use packed mode.


If your g729 decoder and encoder both uses libbfgdots, you can use the packed mode, but it may not talk with other g729 clients.




2008-07-14 21:12:52     Re: G729 encode problem

hong li (CHINA)

Message: 58772   




My encoder and decoder both uses libbfgots, because the output data is 0x007f or 0x0081, I use one bit to represent the 0x007f  or 0x0081, then, the output data is smaller than the orginial data, However, the effect of decoding is not good,  I  will try the packed mode.


Thanks your help






2008-07-18 02:13:04     Re: G729 encode problem

hong li (CHINA)

Message: 59053   




   Thanks your help , I can use the packed mode to compress the audio data  successfully