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

📄 test.c.bak

📁 YAMAHA的铃音芯片的测试程序
💻 BAK
字号:

#include "predef.h"
#include "pccdef.h"
#include "B_FileIO.h"

u32 get4b(u8 *buf);
u16 makeCRC(u32 n, u8 *c);
u8 get_timebase(u8 index);

int file_test()
{
  u8 i;
  char filename[20];
  u8 buf[20000],channel_state[16];
  u8 timebase;
  u32 file_chunk,file_size,rfile_size,chunkID,chunk_size;
  u16 wCalc_CRC, wFile_CRC;
  FILE *fp;

  printf_uart2("\n Please input the SMAF file name:");
  scanf("%s",filename);
  if((fp = Fopen(filename,"rb")) == NULL)        
  {
	printf_uart2("Can't open the MMF file!\n");
	return 0;
  }
 
  Fread(buf,1,20000,fp);                     /* load file data to buffer */
  file_chunk = get4b(buf);                    
  file_size = get4b(buf+num);
  rfile_size = file_size+8; 
  printf_uart2("\nThe real file size = 0x%x",rfile_size);
  if(rfile_size > 20000) 
  {
  	printf_uart2("\nThe file is too big!  EXIT!");
  	return 0;
  }
  
  if(file_chunk != 0x4D4D4D44)                 /* only "MMMD" can be supported */ 
  {	
  	printf_uart2("\nUnknow type! Exit!");
    return 0;
  }  
  
  /* CRC check */
  wFile_CRC = (u16)((buf[file_size - 2+8] << 8) + buf[file_size - 1+8]);              
  wCalc_CRC = makeCRC(rfile_size,&buf[0]);
    
  if (wCalc_CRC != wFile_CRC) 
  {
   printf_uart2("\nCRC Check Error!");
   return 0;              
  }
  
  /* Contents Info Chunk */
  chunkID = get4b(buf+num);
  if(chunkID != 0x434E5449) 
  {
  	printf_uart2("\nNo Contents Info Chunk(CNTI)!  EXIT!");
  	return 0;
  }
  chunk_size = get4b(buf+num);
  
  /* Optional Data Chunk */
  num += chunk_size;
  chunkID = get4b(buf+num);
  chunk_size = get4b(buf+num);
  if(chunkID != 0x4F504441) 
  {
  	printf_uart2("\nNO Optional Data Chunk(opda)!");
  	num -= 8;
  }	
	else  num += chunk_size;

  /* Score Track Chunk */
  chunkID = get4b(buf+num);
  if(chunkID != 0x4D545205) 
  {
  	printf_uart2("\nNo Score Track Chunk(MTR0x5)!  EXIT!");
  	return 0;
  }	
  chunk_size = get4b(buf+num);

  /* Score track chunk information */
  if((buf[num] != 0x02) || (buf[num+1] != 0x0))  /* Only No Compress and Stream can pass */
  {
  	printf_uart2("\nThe format type can't be supported! Exit!");
  	return 0;
  }
  if(buf[num+2] != buf[num+3])
  {
  	printf_uart2("\nTimebaseD != TimebaseG!  Exit!");
  	return 0;
  }
  timebase = get_timebase(buf[num+2]);
  if(timebase == 0) 
  {
  	printf_uart2("\nThe timebase can't be supported! Exit!");
  	return 0;
  } 
  else printf_uart2("\ntimebase = %d", timebase);
  
  /* Get channel status */
  for(i = 0;i < 16;i++)                  
  {
  	channel_state[i] = buf[num+4+i];
  	printf_uart2("\nChannel %d state = 0x%x", i, channel_state[i]);
  }
  num += 20;
  
  /* Score track chunk---Sub Chunk */
  for(i = 0; i < 4; i++)
  {
  	if(num >= (rfile_size-2)) break;
  	
  	chunkID = get4b(buf+num);
  	switch(chunkID)
  	{
  	  case 0x4D747375:                             
  		  chunk_size = get4b(buf+num);
  		  printf_uart2("\nMstu chunk size=0x%x", chunk_size);
  		  Exclusive_check(&buf[num], chunk_size);                                               
  		  num += chunk_size; 
  		  break;
  	  case 0x4D737049:                              
  		  chunk_size = get4b(buf+num);
  		  printf_uart2("\nMspI chunk size=0x%x",chunk_size);         
  		  MspI_check(&buf[num], chunk_size);
  		  /*printf_uart2("\nfinal START = 0x%x", pstart);
          printf_uart2("\nfinal STOP = 0x%x", pstop);*/
  		  num += chunk_size;
  		  break;
  	  case 0x4D747371:                             
  		  chunk_size = get4b(buf+num);
  		  printf_uart2("\nMtsq chunk size=0x%x",chunk_size);
  		  /*Event_check(&buf[num],chunk_size);*/
  		  num += chunk_size;
  		  break;
      case 0x4D747370:                              
  		  chunk_size = get4b(buf+num);
  		  num += chunk_size;
  		  printf_uart2("\nMtsp chunk size=0x%x",chunk_size);
  		  break;
      default: 
    	  printf_uart2("\nNo specificated data chunk!");
    	  break; 
    }
  }    
  return 1;
}   

u32 get4b(u8 *buff)
{
	u32 result;
	
	result = ((u32)*buff << 24) | ((u32)*(buff+1) << 16) | 
           ((u32)*(buff+2) << 8) | ((u32)*(buff+3));
  num += 4;
  
  return result;
} 
        
u16 makeCRC(u32 n, u8 *c)
{
    u16 res;
    u16 crc;
    u8  data0;

    res  = 0xFFFFU;
    crc  = 0;

    while( --n >= 2 )
    {
        data0 = *c++;
        res = (u16)((res << 8) ^ crctable[(u8)(res >> 8) ^ data0]);
        crc = (u16)((crc << 8) | data0);
    }

    return (u16)(~res & 0xFFFFU);
}

u8 get_timebase(u8 index)
{
    switch( index ) 
    {
        case 0x00: return  0;
        case 0x01: return  0;
        case 0x02: return  4;
        case 0x03: return  5;
        case 0x10: return 10;
        case 0x11: return 20;
        case 0x12: return 40;
        case 0x13: return 50;
        default:   return  0;                   /* ERROR */
    }
}

⌨️ 快捷键说明

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