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.

怎样缩短DM365 音频 AD 直接DA的延时



平台环境:

DM365  linux-2.6.32

AD/DA 芯片: AIC3104

用示波器测试,声音从Sound_read 直接到 Sound_write 的延时,发现在该延时与Sound_Attrs.bufSize 和 给它们的Buffer_Handle 有关。

Sound_Attrs.bufSize 越小,Buffer_Handle 越小, AD到DA的延时就越小。

鉴于我采集到的声音还要通过无线网络传输,Buffer_Handle的最小值能设为576。 当我把bufSize 都设为1时,此时的延时还有30多ms 。

为毛延时还这么大呢 ??  AD直接DA的呀,  困扰很久了!   

测试程序如下:

  • const Sound_Attrs Sound_Attrs_MONO_48_2048 = {

        48000,

        1,

        100,

        100,

        Sound_Mode_FULLDUPLEX,

        Sound_Input_MIC,

        Sound_Std_ALSA,

        2048,

    };

    #define  AUDIOBUFSIZE   576

     

    int main (int argc, char* argv[])

    {

           Buffer_Attrs            bAttrs              = Buffer_Attrs_DEFAULT;

     

           Sound_Attrs             sAttrsIn            = Sound_Attrs_MONO_48_2048;

           Sound_Handle            hSoundIn            = NULL;

           Buffer_Handle           hInBuf              = NULL;

     

           Sound_Attrs             sAttrsOut           = Sound_Attrs_MONO_48_2048;

           Sound_Handle            hSoundOut           = NULL;

           Buffer_Handle           hOutBuf             = NULL;

     

     

           Dmai_init();

     

           hInBuf = Buffer_create(AUDIOBUFSIZE, &bAttrs);

           if (hInBuf == NULL)

           {

                  printf("Failed to allocate input buffer\n");

                  exit(0);

           }

           //sAttrsIn.sampleRate=24000;//48000;//32000;

           printf("Insample %d\n",(int)sAttrsIn.sampleRate);

     

           sAttrsIn.mode = Sound_Mode_INPUT;

           sAttrsIn.bufSize   = 32;

    //       sAttrsIn.soundStd = Sound_Std_OSS;

           hSoundIn = Sound_create(&sAttrsIn);

           if (hSoundIn == NULL)

           {

                  printf("Failed to create input speech device\n");

                  exit(0);

           }

     

     

     

           hOutBuf = Buffer_create(AUDIOBUFSIZE, &bAttrs);

           if (hOutBuf == NULL)

           {

                  printf("Failed to allocate hOutBuf buffer\n");

                  exit(0);

           }

           //sAttrsIn.sampleRate=24000;//48000;//32000;

           printf("Insample %d\n",(int)sAttrsIn.sampleRate);

     

           sAttrsOut.mode = Sound_Mode_OUTPUT;

           sAttrsOut.leftGain  = 127;//VolumeMap[MyInfo.Volume];//0~127

           sAttrsOut.rightGain = 127;//VolumeMap[MyInfo.Volume];//0~127

           sAttrsOut.bufSize   = 32;

    //       sAttrsOut.soundStd = Sound_Std_OSS;

           hSoundOut = Sound_create(&sAttrsOut);

           if (hSoundOut == NULL)

           {

                  printf("Failed to create sAttrsOut speech device\n");

                  exit(0);

           }

     

     

     

           while (1)

           {

                  printf("sound read\n");

                  if (Sound_read(hSoundIn, hInBuf) < 0)

                  {

                         printf("Failed to read audio buffer\n");

                         break;

                  }

     

     

     

                  memcpy(Buffer_getUserPtr(hOutBuf),Buffer_getUserPtr(hInBuf),Buffer_getNumBytesUsed(hInBuf));

     

                  Buffer_setNumBytesUsed(hOutBuf, Buffer_getNumBytesUsed(hInBuf));

                 

                  printf("sound write  %d\n",Buffer_getNumBytesUsed(hInBuf));

                  if (Sound_write(hSoundOut, hOutBuf) < 0)

                  {

                         printf("Failed to write audio buffer\n");

                         break;

                  }

     

           }

     

     

           return 0;

    }