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

📄 mwitest.cpp

📁 西门子交换机和Dialogic语音板卡连接驱动编程示例
💻 CPP
📖 第 1 页 / 共 2 页
字号:
         // ERROR
         LOGERROR(nVoxRes1,"dx_listen FAILED");
      }
      sprintf(szBuffer,"VOX Listening to VOX ECR tslot %d",g_ChanInfo[nVoxRes2].nXmitSlot);
      TRACE(nVoxRes1,szBuffer);

      ///////////////////// ROUTE 2 //////////////////////////         
      TsInfo.sc_numts  = 1;
      TsInfo.sc_tsarrayp = &g_MsiInfo[nMSIIndex].nXmitSlot;
      // MSI to ECR Resource(2)     
      if(dx_listen(g_ChanInfo[nVoxRes2].nDevHandle,&TsInfo) == -1){
         // ERROR
         LOGERROR(nVoxRes2,"dx_listen FAILED");
      }
      sprintf(szBuffer,"VOX Listening to MSI tslot %d" ,g_MsiInfo[nMSIIndex].nXmitSlot);
      TRACE(nVoxRes2,szBuffer);

      TsInfo.sc_numts  = 1;
      TsInfo.sc_tsarrayp = &g_ChanInfo[nVoxRes1].nXmitSlot;      
      // Resource(1) to ECR Resource(2);
      if(dx_listenecr(g_ChanInfo[nVoxRes2].nDevHandle,&TsInfo) == -1) {
         // ERROR
         LOGERROR(nVoxRes2,"dx_listenecr FAILED");
      }
      sprintf(szBuffer,"VOX ECR Listening to VOX Start Chan tslot %d",g_ChanInfo[nVoxRes1].nXmitSlot);
      TRACE(nVoxRes2,szBuffer);

      ///////////////////// ROUTE 3 //////////////////////////   
      TsInfo.sc_numts  = 1;
      TsInfo.sc_tsarrayp = &g_ChanInfo[nVoxRes2].nECRXmitSlot;
      // ECR Resource(2) to Resource(3)      
      if(dx_listen(g_ChanInfo[nVoxRes3].nDevHandle,&TsInfo) == -1){
         // ERROR
         LOGERROR(nVoxRes3,"dx_listen FAILED");
      }
      sprintf(szBuffer,"VOX Listening to VOX ECR Xmit tslot %d",g_ChanInfo[nVoxRes2].nECRXmitSlot);
      TRACE(nVoxRes3,szBuffer);

      ///////////////////// ROUTE 4 //////////////////////////   
      TsInfo.sc_numts  = 1;
      TsInfo.sc_tsarrayp = &g_MsiInfo[nMSIIndex].nXmitSlot;
      // MSI to ECR Resource(4)     
      if(dx_listen(g_ChanInfo[nVoxRes4].nDevHandle,&TsInfo) == -1){
         // ERROR
         LOGERROR(nVoxRes4,"dx_listen FAILED");
      }
      sprintf(szBuffer,"VOX Listening to MSI tslot %d",g_MsiInfo[nMSIIndex].nXmitSlot);
      TRACE(nVoxRes4,szBuffer);

      // Increment all the vox resource indexes
      nVoxRes1++;
      nVoxRes2++;
      nVoxRes3++;
      nVoxRes4++;
   }
   
   return(0);
}

///////////////////////////////////////////////////////////
//          NAME: PlayFile
//   DESCRIPTION: Play the prerecorded white noise vox file
//                
//
//////////////////////////////////////////////////////////
int PlayFile(int nIndex)
{
   // Set the play mode
   unsigned short nMode = MD_ADPCM|EV_ASYNC|PM_SR6;

   TRACE(nIndex,"In PlayFile");

   g_ChanInfo[nIndex].tpt.tp_type    = IO_EOT;
   g_ChanInfo[nIndex].tpt.tp_termno  = DX_MAXTIME;
   g_ChanInfo[nIndex].tpt.tp_length  = MAXPLAYTIME*10;     
   g_ChanInfo[nIndex].tpt.tp_flags   = TF_MAXTIME;
   g_ChanInfo[nIndex].iott.io_type   = IO_MEM|IO_EOT;   
   g_ChanInfo[nIndex].iott.io_bufp   = g_pszPlayBuff;
   g_ChanInfo[nIndex].iott.io_offset = 0;
   g_ChanInfo[nIndex].iott.io_length = -1;
   
   if(ATDX_STATE(g_ChanInfo[nIndex].nDevHandle)!=CS_IDLE) {
      // Log an error
      LOGERROR(nIndex,"Invalid State");
   }

   // Begin play of white noise file 
   if(dx_play(g_ChanInfo[nIndex].nDevHandle,&g_ChanInfo[nIndex].iott,&g_ChanInfo[nIndex].tpt,nMode)==-1) {
      LOGERROR(nIndex,"EV_ASYNC PLAY Failed");
   }
   
   return(0);
}

///////////////////////////////////////////////////////////
//          NAME: RecordFile
//   DESCRIPTION: Record the white noise vox file in either
//
//
//////////////////////////////////////////////////////////
int RecordFile(int nIndex)
{
   unsigned short nMode;

   // Set the record mode for AGC/NOAGC
   if(g_TestInfo.bAGC) {
      nMode = g_TestInfo.nPCMEncoding|EV_ASYNC|PM_SR8;
   }
   else {
      nMode = g_TestInfo.nPCMEncoding|EV_ASYNC|PM_SR8|MD_NOGAIN;
   }

   TRACE(nIndex,"In RecordFile");

   g_ChanInfo[nIndex].tpt.tp_type    = IO_EOT;
   g_ChanInfo[nIndex].tpt.tp_termno  = DX_MAXTIME;
   g_ChanInfo[nIndex].tpt.tp_length  = MAXRECTIME*10;     
   g_ChanInfo[nIndex].tpt.tp_flags   = TF_MAXTIME;

   g_ChanInfo[nIndex].iott.io_type   = IO_DEV|IO_EOT;
   g_ChanInfo[nIndex].iott.io_fhandle= dx_fileopen(g_ChanInfo[nIndex].szFileName,O_RDWR|O_CREAT|O_TRUNC|O_BINARY,0666);
   g_ChanInfo[nIndex].iott.io_offset = 0;
   g_ChanInfo[nIndex].iott.io_length  = -1;

   // Check the channel state as idle
   if(ATDX_STATE(g_ChanInfo[nIndex].nDevHandle)!=CS_IDLE) {
      // Log an error
      LOGERROR(nIndex,"Invalid State");
   }

   // Begin resords
   if(dx_rec(g_ChanInfo[nIndex].nDevHandle,&g_ChanInfo[nIndex].iott,&g_ChanInfo[nIndex].tpt,nMode)==-1) {
      LOGERROR(nIndex,"EV_ASYNC record Failed");
   }   
      
   return(0);
}

///////////////////////////////////////////////////////////
//          NAME: SetHook()
//   DESCRIPTION: 
//                
//
//////////////////////////////////////////////////////////
int SetHook(int nIndex, int nHookState)
{

   TRACE(nIndex,"In SetHook");
   
   // Set the hookstate ON/OFF
   if(dx_sethook(g_ChanInfo[nIndex].nDevHandle, nHookState, EV_SYNC)==-1) {
      LOGERROR(nIndex,"Sethook Failed!");
      return(-1);
   }
   return(0);
}

///////////////////////////////////////////////////////////
//          NAME: ConvertFile2Linear
//   DESCRIPTION: 
//                
//
//////////////////////////////////////////////////////////
int ConvertFile2Linear(int nIndex)
{
   char szCmdLineBuff[80];   
   DWORD dwRet;
   BOOL bProcResult;
   STARTUPINFO info;
   PROCESS_INFORMATION prinfo;

   TRACE(nIndex,"In ConvertFile2Linear");

   info.lpReserved  = NULL;
   info.lpDesktop   = NULL;
   info.lpTitle     = NULL;
   info.cb          = sizeof(info);
   info.cbReserved2 = 0;
   info.lpReserved2 = NULL;
   info.dwFlags     = STARTF_USESHOWWINDOW;
   info.wShowWindow = SW_HIDE;

   // Build the command line for ALAW or ULAW
   if(g_TestInfo.nPCMEncoding==MD_PCM) {
      sprintf(szCmdLineBuff,"mu2lin.exe %s l%s",g_ChanInfo[nIndex].szFileName,g_ChanInfo[nIndex].szFileName);      
   }
   else {
      sprintf(szCmdLineBuff,"a2lin.exe -ia -ol %s l%s",g_ChanInfo[nIndex].szFileName,g_ChanInfo[nIndex].szFileName);
   }

   bProcResult=CreateProcess(NULL,szCmdLineBuff,NULL,NULL,FALSE,
                              CREATE_SEPARATE_WOW_VDM|NORMAL_PRIORITY_CLASS,
                              NULL,NULL,&info,&prinfo);    

   // Wait at most 30 seconds for process to end
   if(bProcResult) {
      dwRet = WaitForSingleObject(prinfo.hProcess, 30000);
      if(dwRet == WAIT_TIMEOUT) {
         LOGERROR(nIndex,"Error during xx2lin conversion");
      }    
      // Close the handles of the process and its main thread
      CloseHandle(prinfo.hProcess);         
      CloseHandle(prinfo.hThread);
   }
   else {
      LOGERROR(nIndex,"Error creating process xx2lin conversion");
   }

   return(0);
}

///////////////////////////////////////////////////////////
//          NAME: ComputeEnergy
//   DESCRIPTION: 
//                
//
//////////////////////////////////////////////////////////
float ComputeEnergy(int nIndex)
{
   float  fTotalEnergy = (float)0.0;
   short  nCurrEnergy;
   HANDLE hFileHandle = NULL;
   char   szFileName[20];
   DWORD  dwFileSizeHigh, dwFileSizeLow,dwBytesRead;
   int    nPosition, nLength;
   short  *intptr, *startptr;

   TRACE(nIndex,"In ComputeEnergy");

   // Open Linear file and read in a 16 bit integers
   sprintf(szFileName,"l%s",g_ChanInfo[nIndex].szFileName);
   hFileHandle = CreateFile(szFileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
   if(hFileHandle == INVALID_HANDLE_VALUE) {
      LOGERROR(0,"ComputeEnergy Failed on CreateFile");
   }

   // Get byte sise of the file
   dwFileSizeLow = GetFileSize(hFileHandle, &dwFileSizeHigh);

   // Allocate memory for one read of the file about 160K
   intptr = (short *)malloc(dwFileSizeLow);
   startptr = intptr;
   if(intptr == NULL) {
      LOGERROR(0,"ComputeEnergy Failed on malloc");
      CloseHandle(hFileHandle);  // Close the file handle
      return((float)0.0);
   }
  
   // Read the file
   ReadFile(hFileHandle,intptr,dwFileSizeLow,&dwBytesRead,NULL);
   if(dwFileSizeLow!=dwBytesRead) {
      LOGERROR(nIndex,"Readfile failed");
      free(startptr);            // Free the memory
      CloseHandle(hFileHandle);  // Close the file handle
      return((float)0.0);
   }

   // square and sum to obtain energy
   nLength = (int)floor((double)(dwFileSizeLow/2));
   for(nPosition=0;nPosition<nLength;nPosition++) {
      nCurrEnergy  = *intptr;
      fTotalEnergy = fTotalEnergy + (nCurrEnergy*nCurrEnergy);
      intptr++;
   }
   
   // Compute and copy the total energy average
   g_ChanInfo[nIndex].fTotalEnergy = fTotalEnergy/(dwFileSizeLow/2);

   free(startptr);            // Free the memory
   CloseHandle(hFileHandle);  // Close the file handle

   return(g_ChanInfo[nIndex].fTotalEnergy);
}

///////////////////////////////////////////////////////////
//          NAME: CompareEnergy
//   DESCRIPTION: 
//                
//
//////////////////////////////////////////////////////////
int CompareEnergy(float nNoECREnergy, float nECREnergy)
{

   TRACE(0,"In CompareEnergy");
   
   // 99% difference, .01
   if((.01)*nNoECREnergy < nECREnergy) {
      // return error
      return(1);
   }

   // return success
   return(0);
}

///////////////////////////////////////////////////////////
//          NAME: InitializeVOXChannels()
//   DESCRIPTION: 
//                
//
//////////////////////////////////////////////////////////
int static InitializeVOXChannels(int nStartChan)
{   
   int nIndex;  
   char szBuffer[80];
   CT_DEVINFO DevInfo;
   SC_TSINFO TsInfo;

   TRACE(0,"In InitializeVOXChannels");

   for(nIndex=nStartChan;nIndex<nStartChan+(g_TestInfo.nTotalChan/4);nIndex++) {   
      CHECKENDTESTFLAG;
      // Set channel offhook if necessary, once offhook always off hook
      dx_getctinfo(g_ChanInfo[nIndex].nDevHandle, &DevInfo);
      g_ChanInfo[nIndex].nNetType = DevInfo.ct_nettype;
      if(g_ChanInfo[nIndex].nNetType == CT_NTANALOG) {
         SetHook(nIndex, DX_OFFHOOK);
         // Ensure the analog interface doesn't listen to anything
         ag_unlisten(g_ChanInfo[nIndex].nDevHandle);
      }

      // Get the transmit timeslot
      TsInfo.sc_numts    = 1;      
      TsInfo.sc_tsarrayp = &g_ChanInfo[nIndex].nXmitSlot;
      if(dx_getxmitslot(g_ChanInfo[nIndex].nDevHandle,&TsInfo) == -1) {
         // ERROR
         LOGERROR(nIndex,"dx_getxmitslot FAILED");
      }      
      
      // Get the echo cancellation transmit timeslot
      TsInfo.sc_numts    = 1;
      TsInfo.sc_tsarrayp = &g_ChanInfo[nIndex].nECRXmitSlot;
      if(dx_getxmitslotecr(g_ChanInfo[nIndex].nDevHandle,&TsInfo) == -1) {
         // ERROR
         LOGERROR(nIndex,"dx_getxmitslotecr FAILED");
      }         

      // Set the driver buffer size
      if (dx_setparm(g_ChanInfo[nIndex].nDevHandle, DXCH_XFERBUFSIZE, (void*)&g_TestInfo.nDrvrBuff) != 0) {
         LOGERROR(nIndex,"dx_setparm failed with DXCH_XFERBUFSIZE");   
      }        
      sprintf(szBuffer,"Setting CH: %d DXCH_XFERBUFSIZE: %d",nIndex,g_TestInfo.nDrvrBuff);
      TRACE(nIndex,szBuffer);

      sprintf(szBuffer,"CH: %d XMIT: %d ECRXMIT %d",nIndex,g_ChanInfo[nIndex].nXmitSlot,g_ChanInfo[nIndex].nECRXmitSlot);
      TRACE(nIndex,szBuffer);

   }

   return(0);
}

///////////////////////////////////////////////////////////
//          NAME: InitializeMSIChannels()
//   DESCRIPTION: 
//                
//
//////////////////////////////////////////////////////////
int InitializeMSIChannels(void)
{
   char szDevName[10];
   char szBuffer[80];
   int nIndex;
   int nBrd, nChan, nBrdCnt;
   SC_TSINFO TsInfo;

   TRACE(0,"In InitializeMSIChannels");

   // Get the number of MSI boards
   if(sr_getboardcnt(DEV_CLASS_MSI,&nBrdCnt)==-1) {
       return(-1);
   }

   // Open the MSI channels  
   for(nIndex=1;nIndex<=16*nBrdCnt;nIndex++) {
      CHECKENDTESTFLAG;
      g_MsiInfo[nIndex].nDevHandle = -1;
      nBrd  = (int)floor((nIndex-1)/16) + 1;
      nChan = nIndex%16;
      if(nChan==0) {
          nChan = 16;
      }
      sprintf(szDevName,"msiB%dC%d",nBrd,nChan);

      if((g_MsiInfo[nIndex].nDevHandle = ms_open(szDevName, 0)) == -1) {
         // Open failure, handle error  
         LOGERROR(0,"Failed to open MSI");
      }
      else {
         // Get transmit timeslot
         sprintf(szBuffer,"Opening: %s",szDevName);
         TRACE(nIndex,szBuffer);
         TsInfo.sc_numts    = 1;
         TsInfo.sc_tsarrayp = &g_MsiInfo[nIndex].nXmitSlot;
         if(ms_getxmitslot(g_MsiInfo[nIndex].nDevHandle,&TsInfo) == -1) {
            // ERROR
            LOGERROR(0,"ms_getxmitslot FAILED");
         }

         if(ms_setvol(g_MsiInfo[nIndex].nDevHandle,VOLADJ,12)==-1) {
            // ERROR
            LOGERROR(0,"ms_setvol FAILED");
         }
      }
   }

   return(0);
}

///////////////////////////////////////////////////////////
//          NAME: OpenVOXChannels()
//   DESCRIPTION: 
//                
//
//////////////////////////////////////////////////////////
int static OpenVOXChannels()
{
   char szDevName[10];
   int nIndex, nVoxCnt;
   int nBrd, nChan;
   int nBrdCnt, nMaxChan;

   TRACE(0,"In OpenVOXChannels");

   // Get the number of virtual boards
   if(sr_getboardcnt(DEV_CLASS_VOICE,&nBrdCnt)==-1) {
       return(-1);
   }

   nMaxChan=nBrdCnt*4; 
   nVoxCnt=1;
   for(nIndex=1;nIndex<=nMaxChan;nIndex++) {   
      CHECKENDTESTFLAG;
      g_ChanInfo[nVoxCnt].nDevHandle = -1;
      nBrd  = ((nIndex-1)/4) + 1;
      nChan = nIndex%4;
      if(nChan==0) {
         nChan=4;
      }
      sprintf(szDevName,"dxxxB%dC%d",nBrd,nChan);
      sprintf(g_ChanInfo[nVoxCnt].szFileName,"B%dC%d.pcm",nBrd,nChan);

      if((g_ChanInfo[nVoxCnt].nDevHandle = dx_open(szDevName, 0)) == -1) {
         // Open failure, handle error          
         // LOGERROR(0,"dx_open failed!");         
         // May be an E1 board
      }
      else {
         TRACE(nVoxCnt,"Open VOX Device");
         nVoxCnt++;    
      }
   }
   return(0);
}

⌨️ 快捷键说明

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