midi文件格式及解码代码
详细介绍midi的编码格式及解码代码
midi文件格式及解码代码
类别:技术文章 来源:未知 作者:未知 关键字:midi 加入日期:2010-8-4
standard midi file format http://doc.guandang.net
dustin caldwell
the standard midi file format is a very strange beast. when viewed as a whole, it can be quite overwhelming. of course, no matter how you look at it, describing a piece of music in enough detail to be able to reproduce it accurately is no small task. so, while complicated, the structure of the midi file format is fairly intuitive when understood.
i must insert a disclaimer here that i am by no means an expert with midi nor midi files. i recently obtained a gravis ultrasound board for my pc, and upon hearing a few midi files (.mid) thought, "gee, i'd like to be able to make my own .mid files." well, many aggravating hours later, i discovered that this was no trivial task. but, i couldn't let a stupid file format stop me. (besides, i once told my wife that computers aren't really that hard to use, and i'd hate to be a hypocrite) so if any errors are found in this
information, please let me know and i will fix it. also, this document's scope does not extend to every type of midi command and every possible file configuration. it is a basic guide that should enable the reader (with a moderate investment in time) to generate a quality midi file.
详细介绍midi的编码格式及解码代码
1. overview
a midi (.mid) file contains basically 2 things, header chunks and track chunks. section 2 explains the header chunks, and section 3 explains the track chunks. a midi file contains one header chunk describing the file format, etc., and any number of track chunks. a track may be thought of in the same way as a track on a multi-track tape deck. you may assign one track to each voice, each staff, each instrument or whatever you want.
2. header chunk
the header chunk appears at the beginning of the file, and describes the file in three ways. the header chunk always looks like:
4d 54 68 64 00 00 00 06 ff ff nn nn dd dd
the ascii equivalent of the first 4 bytes is mthd. after mthd comes the 4-byte size of the header. this will always be 00 00 00 06, because the actual header information will always be 6 bytes.
ff ff is the file format. there are 3 formats:
0 - single-track
1 - multiple tracks, synchronous 2 - multiple tracks, asynchronous
single track is fairly self-explanatory - one track only. synchronous multiple tracks means that the tracks will all be vertically synchronous, or in other words, they all start at the same time, and so can represent different parts
详细介绍midi的编码格式及解码代码
in one song. asynchronous multiple tracks do not necessarily start at the same time, and can be completely asynchronous.
nn nn is the number of tracks in the midi file.
dd dd is the number of delta-time ticks per quarter note. (more about this later)
3. track chunks
the remainder of the file after the header chunk consists of track chunks. each track has one header and may contain as many midi commands as you like. the header for a track is very similar to the one for the file:
4d 54 72 6b xx xx xx xx
as with the header, the first 4 bytes has an ascii equivalent. this one is mtrk. the 4 bytes after mtrk give the length of the track (not including the track header) in bytes.
following the header are midi events. these events are identical to the actual data sent and received by midi ports on a synth with one addition. a midi event is preceded by a delta-time. a delta time is the number of ticks after which the midi event is to be executed. the number of ticks per quarter note was defined previously in the file header chunk. this delta-time is a variable-length encoded value. this format, while confusing, allows large numbers to use as many bytes as they need, without requiring small numbers to waste bytes by filling with zeros. the number is converted into 7-bit bytes, and the most-significant bit of each byte is 1 except for the last byte of the number, which has a msb of 0. this allows the number to be read one byte at a
详细介绍midi的编码格式及解码代码
time, and when you see a msb of 0, you know that it was the last (least significant) byte of the number. according to the midi spec, the entire delta- time should be at most 4 bytes long.
following the delta-time is a midi event. each midi event (except a
running midi event) has a command byte which will always have a msb of 1 (the value will be >= 128). a list of most of these commands is in appendix a. each command has different parameters and lengths, but the data that follows the command will have a msb of 0 (less than 128). the exception to this is a meta- event, which may contain data with a msb of 1. however, meta-events require a length parameter which alleviates confusion.
one subtlety which can cause confusion is running mode. this is where the actual midi command is omitted, and the last midi command issued is assumed. this means that the midi event will consist of a delta-time and the parameters that would go to the command if it were included.
4. conclusion
if this explanation has only served to confuse the issue more, the appendices contain examples which may help clarify the issue. also, 2 utilities and a graphic file should have been included with this document:
dec.exe - this utility converts a binary file (like .mid) to a tab-delimited text file containing the decimal equivalents of each byte.
rec.exe - this utility converts a tab-delimited text file of decimal values into a binary file in which each byte corresponds to one of the decimal values.
midinote.ps - this is the postscript form of a page showing note numbers with a keyboard and with the standard grand staff.
…… 此处隐藏:10850字,全部文档内容请下载后查看。喜欢就下载吧 ……相关推荐:
- [实用文档]李践-有效提升销售的12大黄金法则8-大
- [实用文档]党支部换届工作方案
- [实用文档]2013年下期电子商务专业部宣传工作计划
- [实用文档]方庄一矿通风、钻探绩效工资考核管理办
- [实用文档]项目一 认识企业物流认识企业物流
- [实用文档]MBI_Display_产品蓝图规画
- [实用文档]北京市建筑业劳务作业人员普法维权培训
- [实用文档]锅炉燃烧调整与运行优化
- [实用文档]4支付结算业务的核算
- [实用文档]米什金_货币金融学_第9版各章学习指导
- [实用文档]水泥混凝土路面硬化工程施工组织设计
- [实用文档]钢筋工程安全技术交底书
- [实用文档]关于公布华中师范大学本科毕业论文
- [实用文档]太原市园林绿化施工合同范本 2
- [实用文档]周日辅导 初中英语分类复习单项选择题(
- [实用文档]第四章 文化经纪人的管理形式 第二节
- [实用文档]学宪法讲宪法竞赛题库
- [实用文档]《数值计算方法》期末考试模拟试题二
- [实用文档]爱词霸学英语:每日一句( 十月)
- [实用文档]2014年国家公务员面试:无领导小组讨论
- 新课程主要理念和教学案例分析汇编(24
- 英国人的快乐源于幸福的家庭生活
- 七年级上册第一次月考模拟数学试卷
- 真丝及仿真丝的种类有哪些?
- 【最新】华师大版八年级数学下册第十六
- 高中英语3500个必背单词
- 我可以接受失败,但我不能接受放弃!
- 最近更新沪科版八年级物理上册期末试卷
- 绿化工作先进乡镇事迹材料
- 鲁教版九年级上册思想品德教学计划
- 英语音标的分类
- 地下室底板无梁楼盖与普通梁板结构形式
- 美容师黄金销售话术
- 雅思写作满分作文备考方法
- 血清甲状腺激素测定与高频彩色多普勒超
- 1度浅析装修对室内空气品质的影响
- 2017-2022年中国汞矿行业深度分析与投
- 计算机二级VB公共基础知识
- (何勇)秸秆禁烧_重在寻找出路
- 内外墙抹灰工程分包施工合同1




