⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tone.c

📁 实现成功的G.729源代码
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>

#include "tonecfg.h"
#include "dsk5416.h"
#include "dsk5416_pcm3002.h"


#include "typedef.h"
#include "intrindefs.h"
#include "ld8a.h"

#define  N   160
#pragma DATA_SECTION(dst, "dmaMem")
long int dst[N];

#pragma DATA_SECTION(src, "dmaMem1")
long int src[N];

Word16 bufferin[N/2];

Word16   *synt;

DSK5416_PCM3002_CodecHandle hCodec;
long  sine;
int   sin;
int   j;
int   k;

volatile Bool Is_new_data= FALSE;
volatile Bool WaitForDma4 = TRUE;

Word16   bad_lsf;
int Overflow; 

DSK5416_PCM3002_Config setup = {

    0x100,      // Set-Up Reg 0 - Left channel DAC attenuation
    0x1ff,      // Set-Up Reg 1 - Right channel DAC attenuation
    0x0,        // Set-Up Reg 2 - Various ctl e.g. power-down modes
    0x0         // Set-Up Reg 3 - Codec data format control
};

void DSK5416_init()
{    
    /* Reset board I/O registers to reset state */
    DSK5416_USER_REG = 0;
    DSK5416_DC_REG = 0;
    DSK5416_DM_CNTL = 0;
    DSK5416_MISC = 0;
    DSK5416_CODEC_CLK = 0;
}

void main()
{
   extern Word16   *new_speech;
   Word16   prm[PRM_SIZE];           /*Analysis parameters.                  */
   Word16   synth_buf[L_FRAME+M]; 
   Word16   parm[PRM_SIZE+1];             /* Synthesis parameters        */
   Word16   serial[SERIAL_SIZE];          /* Serial stream               */
   Word16   Az_dec[MP1*2];                /* Decoded Az for post-filter  */
   Word16   T2[2];                        /* Pitch lag for 2 subframes   */
 //  Word16   *synt;
 //  int old_intm;
 //  int i;
    Word16 *p;
    Word16 *pout;
 
 
   Uint16 eventId1;
   Uint16 eventId2;
   int i;
    // Initialize the board support library
  //  DSK5416_init();
    IRQ_globalDisable();
      
    hCodec = DSK5416_PCM3002_openCodec(0, &setup);
    DSK5416_PCM3002_setFreq( hCodec,8000);
    for (i=0; i<N; i++)  
    {dst[i]=0;
     src[i]=0;
     j=1;
     k=1;
     }
 
     //* Get Event ID associated with DMa channel 3 interrupt */
//  old_intm = IRQ_globalDisable();
 //  IRQ_globalEnable();
  eventId1 = DMA_getEventId(hDma3);
  /* Enable masking of DMA channel 3 interrupt in DMA */
  /* interrupt select register                        */
  DMA_FSET(DMPREC,INTOSEL,DMA_DMPREC_INTOSEL_CH2_CH3);
  /* Disable DMA 3 channel interrupts */
  IRQ_disable(eventId1);
  /* Clear any pending DMA channel 3 interrupts */
  IRQ_clear(eventId1); 
   /* Wrie DMA interrupt service vector */
  IRQ_map(eventId1);
  
  eventId2 = DMA_getEventId(hDma2); 
  DMA_FSET(DMPREC,INTOSEL,DMA_DMPREC_INTOSEL_CH2_CH3); 
  IRQ_disable(eventId2); 
  IRQ_clear(eventId2); 
  IRQ_map(eventId2);
  
  IRQ_enable(eventId1);
  IRQ_enable(eventId2);  
  
//  IRQ_globalDisable(); 
  DMA_start(hDma3);
  DMA_start(hDma2);                       

  /* Start DMA transfer. DMA_Handle , hDma3 is pre-Opened and created */
  /* by code automatically generated by DSPBIOS/CSL GUI configuration */
  
    Init_Pre_Process();  /* 以下为编码初始化*/
    Init_Coder_ld8a();
    Set_zero(prm, PRM_SIZE); 
   
    for (i=0; i<M; i++) 
      { synth_buf[i] = 0; }  /*以下为解码初始化*/
    synt=synth_buf+M;
    bad_lsf = 0;        /*  Initialize bad LSF indicator */
    Init_Decod_ld8a();
    Init_Post_Filter();
    Init_Post_Process();
    
 //  IRQ_globalDisable(); 

   MCBSP_start (
    C54XX_DMA_MCBSP_hMcbsp,
    MCBSP_RCV_START|MCBSP_XMIT_START, 
    0 );
   
 //  IRQ_globalRestore(old_intm); 

   MCBSP_start (
    C54XX_DMA_MCBSP_hMcbsp,
    MCBSP_SRGR_START|MCBSP_SRGR_FRAMESYNC, 
    0x200);
   while (!DSK5416_PCM3002_write16(hCodec, 0x00));

   IRQ_globalEnable();
   LOG_printf(&trace,"<kaishi>");

 while(1)
 {
 
  while(Is_new_data==1)
    {
     Is_new_data=0;
 //cod();
     LOG_printf(&trace,"<cod>"); 
     p=&bufferin[0];
      memcpy(new_speech,p,80*sizeof(Word16));
    DMA_start(hDma3);
   LOG_printf(&trace,"<cod>");
  	Pre_Process(new_speech, L_FRAME);
	 LOG_printf(&trace,"<cod1>");
    Coder_ld8a(prm);
     LOG_printf(&trace,"<cod2>");
   prm2bits_ld8k( prm, serial);
    LOG_printf(&trace,"<cod3>");
	bits2prm_ld8k( &serial[2], &parm[1]);
 //decod();
   LOG_printf(&trace,"<decod>"); 
   parm[0] = 0;           /* No frame erasure */
    for (i=2; i < SERIAL_SIZE; i++)
    if (serial[i] == 0 ) parm[0] = 1; /* frame erased     */
     parm[4] = Check_Parity_Pitch(parm[3], parm[4]);
     Decod_ld8a(parm, synt, Az_dec, T2);
     LOG_printf(&trace,"<over>"); 
   //  Post_Filter(synt, Az_dec, T2);        /* Post-filter */
     
   Post_Process(synt, L_FRAME);
    LOG_printf(&trace,"<over>"); 
    pout=synt;
    for(i=0;i<80;i++)
      {
   //  src[2*i]=((long)synt[i]);
    //   src[2*i+1]=((long)synt[i]); 
       src[2*i]=((long)pout[i]);
      src[2*i+1]=((long)pout[i]);
   
   //   src[2*i]=((long)bufferin[i]);
   //   src[2*i+1]=((long)bufferin[i]);
      }
    

    }  
      
      
  }
   DMA_stop(hDma2);
   DMA_stop(hDma3);
   DMA_close(hDma2);
   DMA_close(hDma3);
   MCBSP_close(C54XX_DMA_MCBSP_hMcbsp);
   DSK5416_PCM3002_closeCodec(hCodec);
}
 
void dma_isr(void)
{  
   int i;
   DMA_stop(hDma3);
   LOG_printf(&trace,"<DONE>");
   Is_new_data = 1;
  for (i=0; i<N/2; i++) 
  bufferin[i]=(int)L_shr((dst[2*i]),(16));
  DMA_start(hDma3);

}

void dma2_isr(void)
{  DMA_stop(hDma2);
   LOG_printf(&trace,"<DONE1>");
   WaitForDma4 = FALSE;
   DMA_start(hDma2);
}


 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -