Ios 在Objective C中使用简单的midi文件编写器
我正在用Objective C编写一个程序来生成一个MIDI文件。作为测试,我要求它编写一个文件,播放一个音符,然后停止一个delta滴答 但是我试着用Logic和Sibelius打开它,他们都说文件已经损坏了 这是文件的十六进制读数Ios 在Objective C中使用简单的midi文件编写器,ios,objective-c,hex,midi,Ios,Objective C,Hex,Midi,我正在用Objective C编写一个程序来生成一个MIDI文件。作为测试,我要求它编写一个文件,播放一个音符,然后停止一个delta滴答 但是我试着用Logic和Sibelius打开它,他们都说文件已经损坏了 这是文件的十六进制读数 4D 54 68 64 00 00 00 06 00 01 00 01 00 40 - MThd header 4D 54 72 6B 00 00 00 0D - MTrk - with length of 13 as 32bit
4D 54 68 64 00 00 00 06 00 01 00 01 00 40 - MThd header
4D 54 72 6B 00 00 00 0D - MTrk - with length of 13 as 32bit hex [00 00 00 0D]
81 00 90 48 64 82 00 80 48 64 - the track
delta noteOn delta noteOff
FF 2F 00 - end of file
这是我写delta时间和写笔记的程序-
- (void) appendNote:(int)note state:(BOOL)on isMelody:(BOOL)melodyNote{ // generate a MIDI note and add it to the 'track' NSData object
char c[3];
if( on ){
c[0] = 0x90;
c[2] = volume;
} else {
c[0] = 0x80;
c[2] = lastVolume;
}
c[1] = note;
[track appendBytes:&c length:3];
}
-(void)writeVarTime:(int)值{//生成MIDI增量时间并将其添加到“track”NSData对象中
charc[2];
如果(值<128){
c[0]=数值;
[跟踪追加字节:&c长度:1];
}否则{
c[0]=值/128 | 0x80;
c[1]=值%128;
[跟踪追加字节:&c长度:2];
}
}
有没有聪明的MIDI大师可以判断出这个MIDI文件有什么问题?EOF事件的增量时间缺失。谢谢!好了。。现在我想知道如何为MTRK长度创建一个32位十六进制值,这有点困难。。
- (void) writeVarTime:(int)value{ // generate a MIDI delta time and add it to the 'track' NSData object
char c[2];
if( value < 128 ){
c[0] = value;
[track appendBytes:&c length:1];
} else {
c[0] = value/128 | 0x80;
c[1] = value % 128;
[track appendBytes:&c length:2];
}