Ver código fonte

延迟计算

skyblued 2 anos atrás
pai
commit
fe14be177c
1 arquivos alterados com 11 adições e 8 exclusões
  1. 11 8
      src/subpages/colexiu/buttons/evaluating.tsx

+ 11 - 8
src/subpages/colexiu/buttons/evaluating.tsx

@@ -50,7 +50,7 @@ const formatPitch = (num?: number): number => {
   }
   return num
 }
-
+let starTime = 0
 const formatTimes = () => {
   const difftime = detailState.times?.[0]?.difftime || 0
   let ListenMode = false
@@ -68,17 +68,18 @@ const formatTimes = () => {
     times = detailState.times.filter((n: any, index: number) => {
       return index >= startIndex && index <= endIndex
     })
+    starTime = times[0].sourceRelativeTime || times[0].relativeTime
     // console.log("🚀 ~ times", times)
   }
   let measureIndex = -1
   let recordMeasure = -1
-  let timeStamp = 0
   for (let index = 0; index < times.length; index++) {
     const item = times[index]
     const note = getNoteByMeasuresSlursStart(item)
     const rate = runtime.speed / detailState.baseSpeed //1
-    const start = difftime + (item.sourceRelativeTime || item.relativeTime)
-    const end = difftime + (item.sourceRelaEndtime || item.relaEndtime)
+    const start = difftime + (item.sourceRelativeTime || item.relativeTime) - starTime
+    const end = difftime + (item.sourceRelaEndtime || item.relaEndtime) - starTime
+    console.log(start, end , starTime)
     const isStaccato =
       typeof note.voiceEntry.isStaccato === 'function' ? note.voiceEntry.isStaccato() : note.voiceEntry.isStaccato
     const noteRate = isStaccato ? 0.5 : 1
@@ -107,7 +108,7 @@ const formatTimes = () => {
     }
     // console.log(note.measureOpenIndex , measureIndex, note.noteElement.sourceMeasure.measureListIndex)
     const data = {
-      timeStamp: timeStamp, // (start * 1000) / rate
+      timeStamp: (start * 1000) / rate,
       duration: ((end * 1000) / rate - (start * 1000) / rate) * noteRate,
       frequency: formatPitch(item.noteElement?.pitch?.frequency),
       nextFrequency: formatPitch(item.noteElement?.pitch?.nextFrequency),
@@ -120,7 +121,6 @@ const formatTimes = () => {
       denominator: note.noteElement?.Length.denominator,
       isOrnament: !!note?.voiceEntry?.ornamentContainer,
     }
-    timeStamp += data.duration
     datas.push(data)
   }
   return datas
@@ -280,10 +280,13 @@ const timeupdate = () => {
     const nowTime = new Date().getTime()
     console.log('第一次播放时间', nowTime)
     // synced = true
-    const time = runtime.audiosInstance?.audios[playUrl.value].currentTime
+    let time = runtime.audiosInstance?.audios[playUrl.value].currentTime
+    if (unitTestData.isSelectMeasureMode){
+      time = time - detailState.section[0].time
+    }
     console.log('已播放时长: ', time * 1000)
     console.log('不减掉已播放时间: ', nowTime - backtime)
-    const delayTime = nowTime - backtime //- time * 1000
+    const delayTime = nowTime - backtime - time * 1000
     console.log('真正播放延迟', delayTime)
     // 蓝牙耳机延迟一点发送消息确保在录音后面
     setTimeout(() => {