-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-timeline.js
More file actions
88 lines (76 loc) · 3.11 KB
/
Copy pathdebug-timeline.js
File metadata and controls
88 lines (76 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* 时间轴调试脚本
* 用于分析歌曲《晴天》的时间key计算
*/
const bpm = 68
const millisecondsPerBeat = 60000 / bpm // 每拍的毫秒数
console.log('='.repeat(70))
console.log('时间轴计算调试 - 《晴天》')
console.log('='.repeat(70))
console.log(`BPM: ${bpm}`)
console.log(`每拍毫秒数: ${millisecondsPerBeat.toFixed(2)}ms`)
console.log(`每小节毫秒数 (4拍): ${(millisecondsPerBeat * 4).toFixed(2)}ms`)
console.log('='.repeat(70))
// 测试前10个时间key
const testKeys = [
'009a', // 第一个事件
'009b',
'010a',
'010b',
'011a',
'011b',
'012a',
'012b',
'013a',
'013b',
]
console.log('\n前10个事件的时间计算:\n')
testKeys.forEach((timeKey, index) => {
// 当前的计算逻辑 (有问题的)
const barNumber = parseInt(timeKey.substring(0, 3), 10)
const beatOffset = timeKey.includes('b') ? 2 : 0
const triggerTime = ((barNumber - 1) * 4 + beatOffset) * millisecondsPerBeat
console.log(`${index + 1}. 时间key: "${timeKey}"`)
console.log(` → 小节号: ${barNumber}`)
console.log(` → 拍偏移: ${beatOffset}`)
console.log(` → 计算公式: ((${barNumber} - 1) * 4 + ${beatOffset}) * ${millisecondsPerBeat.toFixed(2)}`)
console.log(` → 触发时间: ${triggerTime.toFixed(0)}ms = ${(triggerTime / 1000).toFixed(2)}秒`)
console.log('')
})
console.log('='.repeat(70))
console.log('问题分析:')
console.log('='.repeat(70))
console.log('第一个事件 "009a" 的触发时间是:')
console.log(` ((9 - 1) * 4 + 0) * ${millisecondsPerBeat.toFixed(2)} = ${((9-1)*4*millisecondsPerBeat).toFixed(0)}ms`)
console.log(` = ${(((9-1)*4*millisecondsPerBeat)/1000).toFixed(2)}秒`)
console.log('')
console.log('❌ 问题: 歌曲从第9小节开始,导致28秒的延迟!')
console.log('')
console.log('='.repeat(70))
console.log('解决方案:')
console.log('='.repeat(70))
console.log('方案1: 从最小小节号开始计算 (推荐)')
console.log(' - 找到最小的小节号 (minBarNumber)')
console.log(' - 修改公式: ((barNumber - minBarNumber) * 4 + beatOffset) * millisecondsPerBeat')
console.log(' - 这样第一个事件会在0ms触发')
console.log('')
console.log('方案2: 手动调整小节起始值')
console.log(' - 在配置中设置 startBarNumber = 9')
console.log(' - 修改公式: ((barNumber - startBarNumber) * 4 + beatOffset) * millisecondsPerBeat')
console.log('')
console.log('='.repeat(70))
console.log('修复后的计算 (方案1):')
console.log('='.repeat(70))
const minBarNumber = 9 // 《晴天》的最小小节号
console.log(`最小小节号: ${minBarNumber}`)
console.log('\n修复后的前10个事件:\n')
testKeys.forEach((timeKey, index) => {
const barNumber = parseInt(timeKey.substring(0, 3), 10)
const beatOffset = timeKey.includes('b') ? 2 : 0
const triggerTime = ((barNumber - minBarNumber) * 4 + beatOffset) * millisecondsPerBeat
console.log(`${index + 1}. 时间key: "${timeKey}" → ${triggerTime.toFixed(0)}ms = ${(triggerTime / 1000).toFixed(2)}秒`)
})
console.log('')
console.log('='.repeat(70))
console.log('✅ 修复后,第一个事件 "009a" 在 0秒 触发!')
console.log('='.repeat(70))