如何获得MIDI事件的确切时间 [英] How to get Exact Time of a MIDI event

查看:219
本文介绍了如何获得MIDI事件的确切时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读一个MIDI文件,我想从它确定在C#中NoteOn事件的确切时间。结果
我试图用绝对时间,但输出是像256632 。结果
这个数字是什么?
这是我的代码,返回时间线:

 (注为NoteOnEvent).AbsoluteTime 


解决方案

一个MIDI文件仅包含增量倍。包括作为每个MIDI事件之前1和4字节之间的可变长度值。您正在使用的库是正在为您提供AbsoluteTime财产很有帮助。简单地通过对每个事件的增量时间相加来计算



的单位为增量蜱。增量刻度的长度不是固定值,它是在MIDI文件头中指定。 n音讯公开它作为MidiFile.DeltaTicksPerQuarterNote属性。所以你需要划分你AbsoluteTime得到这个值来获得歌曲的起始音符位置的值。



这当然仍相对值,这取决于歌曲的节奏。在弹奏四分音符率。推荐的节奏被包含在文件中为好,它是在n音讯的TempoEvent。其MicrosecondsPerQuarterNote属性告诉你四分音符应该是后续事件有多长。要注意的是可以有一首歌一个以上的速度事件。


I'm trying to read a MIDI file and I want to determine the exact time of a NoteOn event from it in C#.
I tried to use absolute time, but the output was something like 256632.
What is this number ? This is the line of my code that returns the time :

(note as NoteOnEvent).AbsoluteTime

解决方案

A MIDI file only contains incremental times. Included as a variable length value between 1 and 4 bytes before each MIDI event. The library you are using is being helpful in providing you with the AbsoluteTime property. Simply calculated by summing the incremental times for each event.

The unit is "delta ticks". The length of a delta tick is not a fixed value, it is specified in the MIDI file header. NAudio exposes it as the MidiFile.DeltaTicksPerQuarterNote property. So you'll need to divide the value you get from AbsoluteTime by this value to get the note position from the start of the song.

This is of course still a relative value, it depends on the tempo of the song. The rate at which you play quarter notes. The recommended tempo is included in the file as well, it is the TempoEvent in NAudio. Its MicrosecondsPerQuarterNote property tells you how long a quarter note should be for subsequent events. Beware that there can be more than one tempo event in a song.

这篇关于如何获得MIDI事件的确切时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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