[問題] 用C讀取MIDI的資料
目前我已經大致了解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
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, , 4F
05/12 10:51, 4F
→
05/12 10:51, , 5F
05/12 10:51, 5F
→
05/12 11:09, , 6F
05/12 11:09, 6F
→
05/12 11:49, , 7F
05/12 11:49, 7F
→
05/12 11:59, , 8F
05/12 11:59, 8F
→
05/12 12:00, , 9F
05/12 12:00, 9F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章