【发布时间】:2014-07-12 20:32:12
【问题描述】:
我意识到这里有很多关于将 MIDI 刻度转换为毫秒的问题(例如:How to convert midi timeline into the actual timeline that should be played、Midi Ticks to Actual PlayBack Seconds !!! ( Midi Music)、Midi timestamp in seconds),我已经查看了所有这些问题,并尝试实施这些建议,但我仍然没听懂。
(我有没有提到我有点“数学恐惧症”)
谁能帮我做一个实际的例子?我正在使用Bass lib from un4seen。我有我需要的所有数据 - 我只是不相信我的计算。
低音方法
打勾
// position of midi stream
uint64_t tick = BASS_ChannelGetPosition(midiFileStream, BASS_POS_MIDI_TICK)
PPQN
//The Pulses Per Quarter Note (or ticks per beat) value of a MIDI stream.
float ppqn;
BASS_ChannelGetAttribute(handle, BASS_ATTRIB_MIDI_PPQN, &ppqn);
节奏
//tempo in microseconds per quarter note.
uint32_t tempo = BASS_MIDI_StreamGetEvent( midiFileStream, -1, MIDI_EVENT_TEMPO);
我尝试计算刻度的 MS 值:
float currentMilliseconds = tick * tempo / (ppqn * 1000);
我得到的值似乎正确,但我对它没有任何信心,因为我不太了解公式。
printf("tick %llu\n",tick);
printf("ppqn %f\n",ppqn);
printf("tempo %u\n",tempo);
printf("currentMilliseconds %f \n", currentMilliseconds);
示例输出:
tick 479
ppqn 24.000000
tempo 599999
currentMilliseconds 11974.980469
更新
我的困惑仍在继续,但基于blog post,我认为我的代码是正确的——至少输出看起来是准确的。相反,下面@Strikeskids 提供的答案会产生不同的结果。也许我有一个操作顺序问题?
float kMillisecondsPerQuarterNote = tempo / 1000.0f;
float kMillisecondsPerTick = kMillisecondsPerQuarterNote / ppqn;
float deltaTimeInMilliseconds = tick * kMillisecondsPerTick;
printf("deltaTimeInMilliseconds %f \n", deltaTimeInMilliseconds);
。
float currentMillis = tick * 60000.0f / ppqn / tempo;
printf("currentMillis %f \n", currentMillis);
输出:
deltaTimeInMilliseconds 11049.982422
currentMillis 1.841670
【问题讨论】:
-
你知道速度可以在文件中间改变吗?你无法逃避使用even more math。
-
BASS 提供的每四分音符已经有微秒。你说的不是你要找的吗?
-
@Brad - 不,我正在尝试计算特定滴答声的毫秒数