[問題] 用C讀取MIDI的資料

看板C_and_CPP (C/C++)作者 (= =)時間15年前 (2011/05/11 20:20), 編輯推噓0(009)
留言9則, 3人參與, 最新討論串1/1
目前我已經大致了解MIDI的意思也寫出了可以判斷是不是MIDI的程式 和為format幾 (我的程式只要可以提取出主旋律TRACK中的音就可以了) 我寫出下面這個程式 #include <stdlib.h> #include <stdio.h> #include <string.h> typedef unsigned int UINT32; typedef unsigned short UINT16; typedef unsigned char BYTE; typedef unsigned char UINT8; UINT8 *Track_ptr[MAX_TRACKS]; int main(int argc, char *argv[]) { FILE *fp; BYTE *buf; int i; int c; int b[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; BYTE d,type; BYTE *track_p; UINT32 TrackTick; UINT32 size; UINT16 TrackNum; //Track 使用Track數量 UINT16 TimeFormat; //開啟檔案並讀入buf fp = fopen("C:\\00.mid", "rb"); fseek(fp, 0, SEEK_END); size = ftell(fp); fseek(fp, 0, SEEK_SET); buf = (unsigned char *)malloc(size); fread(buf,size, 1, fp); fclose(fp); //檢查檔頭是否為MThd if( buf[0] != 0x4d&buf[1] != 0x54&buf[2] != 0x68&buf[3] != 0x64) { printf("this File is not Midi\n"); } //判斷format if( buf[9] == 0x00) { printf("File Format is 0\n"); } if( buf[9] == 0x01) { printf("File Format is 1\n"); } if( buf[9] == 0x02) { printf("File Format is 2\n"); } for( i=0; i<=size; i++){ for(c=0;c<16;c++){ if( buf[i] ==(144+b[c])){ printf("note on and channel is %d\t",c); printf("code is %0X \n",buf[i+1]); } } for(c=0;c<16;c++){ if( buf[i] ==(128+b[c])){ printf("note off and channel is %d\t",c); printf("code is %0X \n",buf[i+1]); } } } system("pause"); return 0; } 我現在是讓它全部跑一次檔案的數據 然後取出為9X(16進位) 但我這個程式出現一個問題 可能會提取到TICK 若92 62 為TICK的資料 那可能就提取到TICK 但我現在對如何取出TICK一頭霧水 可以請版上的高手給點建議嗎 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.38.5.233

05/12 08:25, , 1F
我是不會midi觀念,可是你是不是把&和&&搞混阿.把&改成
05/12 08:25, 1F

05/12 08:26, , 2F
&&試試看吧
05/12 08:26, 2F

05/12 10:50, , 3F
謝謝你的建議 只是還是卡在相同 地方
05/12 10:50, 3F

05/12 10:51, , 5F
上為MIDI格式介紹
05/12 10:51, 5F

05/12 11:09, , 6F
先把程式碼排整齊吧......
05/12 11:09, 6F

05/12 11:49, , 7F
意思是不知道tick的觀念嗎?有點不想看了,一堆英文
05/12 11:49, 7F


05/12 12:00, , 9F
這個有中文網站教你該如何計算
05/12 12:00, 9F
文章代碼(AID): #1Dodyh7N (C_and_CPP)
文章代碼(AID): #1Dodyh7N (C_and_CPP)