C++でSMFを出力するメモ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#include <iostream> using namespace std; int main(){ unsigned char a[] = { 0x4D,0x54,0x68,0x64, 0x00,0x00,0x00,0x06, 0x00,0x01, 0x00,0x02, 0x00,0x30, 0x4D,0x54,0x72,0x6B,//MTrk 0x00,0x00,0x00,0x0B, 0x00,0xFF,0x51,0x03,0x07,0xA1,0x20, 0x00,0xFF,0x2F,0x00,//トラックエンド 0x4D,0x54,0x72,0x6B , 0x00,0x00,0x00,0x18 , 0x00,0x90,0x3C,0x7F , 0x30,0x3C,0x00, 0x00,0x3E,0x7F, 0x30,0x3E,0x00, 0x00,0x40,0x7f, 0x81,0x40,0x40,0x00, 0x00,0xFF,0x2F,0x00, //トラックエンド }; int j = sizeof(a) / sizeof(a[0]); //変数aの要素数を計算します。 FILE *fp; fp = fopen("/Users/******/Desktop/aaaa.mid","wb"); if(fp == NULL){ return 0; } //fpがNULLなら関数を抜ける fwrite( a , sizeof(unsigned char) , j ,fp); fclose(fp); return 0; } |
コメント