Guest User

Untitled

a guest
Dec 11th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. typedef unsigned int UINT32;
  6. typedef unsigned short UINT16;
  7. typedef unsigned char BYTE;
  8. typedef unsigned char UINT8;
  9.  
  10. UINT8 *Track_ptr[MAX_TRACKS];
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14. FILE *fp;
  15. BYTE *buf;
  16. int i;
  17. int a;
  18. BYTE d,type;
  19. BYTE *track_p;
  20. UINT32 TrackTick;
  21. UINT32 size;
  22. UINT16 TrackNum; //Track 使用Track數量
  23. UINT16 TimeFormat;
  24.  
  25. //開啟檔案並讀入buf
  26. fp = fopen("C:\\456.mid", "rb");
  27. fseek(fp, 0, SEEK_END);
  28. size = ftell(fp);
  29. fseek(fp, 0, SEEK_SET);
  30.  
  31. buf = (unsigned char *)malloc(size);
  32.  
  33. fread(buf,1 , size, fp);
  34. fclose(fp);
  35. //檢查檔頭是否為MThd
  36. if( buf[0] != 0x4d&buf[1] != 0x54&buf[2] != 0x68&buf[3] != 0x64)
  37. {
  38. printf("this File is not Midi\n");
  39. }
  40.  
  41. //判斷format
  42. if( buf[9] == 0x00)
  43. {
  44. printf("File Format is 0\n");
  45. TrackNum=buf[11];
  46. printf(" TrackNumber is %d\n",buf[11]);
  47. }
  48. if( buf[9] == 0x01)
  49. {
  50. printf("File Format is 1\n");
  51. TrackNum=buf[11];
  52. printf("TrackNumber is %d\n",buf[11]);
  53. }
  54. if( buf[9] == 0x02)
  55. {
  56. printf("File Format is 2\n");
  57. TrackNum=buf[11];
  58. printf("TrackNumber is %d\n",buf[11]);
  59. }
  60.  
  61. for(i=0;i<100;i++)
  62. {
  63. printf("%4d",buf[i]);
  64. }
  65. system("pause");
  66. return 0;
  67. }
Add Comment
Please, Sign In to add comment