如何从 MIDI 文件中提取速度 [英] How to extract tempo from MIDI file

查看:114
本文介绍了如何从 MIDI 文件中提取速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 sequence.getResolution() 内置方法来提取节拍的长度(以毫秒为单位).它适用于某些歌曲,但不是全部.例如,对于歌曲sweet home alabama",它返回 384 MS 的节拍,但在现实生活中,实际节拍长度为 612 MS.这适用于无数其他歌曲,并且仅适用于我正在使用的一首歌曲.

I am using the sequence.getResolution() built in method to extract how long a beat is in milliseconds. It works for some songs but not all. For example, for the song 'sweet home alabama' it returns a beat of 384 MS, however in real life the actual beat length is 612 MS. This works for countless other songs and only works for one of the songs that I am working with.

使用java正确提取MIDI文件的bpm或节奏的任何其他方法将不胜感激

Any other way to correctly extract the bpm or tempo of a MIDI file using java would be greatly appreciated

推荐答案

速度在 MIDI 文件中自动定义.使用 javax.sound.MIDI 中的 MetaMessage 类和方法 getData() 您将获得元数据的字节.标记为 0x51 的字节保存每个轨道的每四分音符微秒测量的速度值.注意,每个 MIDI 文件通常有多个音轨;因此有多个速度签名.查看下面的 MIDI 结构链接的大纲.它解释了 MIDI 文件数据的每一部分以及所有内容的含义和位置.

The tempo is automatically defined in the MIDI file. Using the MetaMessage Class in javax.sound.MIDI and the method getData() you will obtain the bytes of metadata. The bytes labeled 0x51 holds the value of the tempo measured in microseconds per quarter note for each track. Note, each MIDI file generally has multiple tracks; hence multiple tempo signatures. Look at the outline of the MIDI structure link below. It explains each piece of the MIDI file data and where and what everything means.

这是 MIDI 结构大纲的链接:http://www.ccarh.org/courses/253/handout/smf/

Here is a link to an outline of the MIDI structure: http://www.ccarh.org/courses/253/handout/smf/

这是 MetaMessage 类的链接:https://docs.oracle.com/javase/8/docs/api/javax/sound/midi/MetaMessage.html

Here is a link to the MetaMessage Class: https://docs.oracle.com/javase/8/docs/api/javax/sound/midi/MetaMessage.html

这是标准 MIDI 文件格式的链接:https://formats.kaitai.io/standard_midi_file/index.html

Here is a link to the standard MIDI file format: https://formats.kaitai.io/standard_midi_file/index.html

简单总结:第 11 个和第 12 个字节 = 轨道数.它位于 14 字节长的报头中.接下来是一个轨道块,然后是另一个,再是第 11 个和第 12 个字节定义的另一个.每一个都有在块中的 5、6、7 和 8 个字节中定义的长度.长度衡量轨道有多少字节(从第 9 个字节开始).

Simple summary: 11th and 12th byte = number of tracks. This is located in the header which is 14 bytes long. Following that is a track chunk, and then another, and another as many times as defined by the 11th and 12th bytes. Each one has a length defined in the 5, 6, 7, and 8 bytes in the chunk. The length measures how many bytes the track is (starting on the 9th byte).

这篇关于如何从 MIDI 文件中提取速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆