【发布时间】:2010-03-11 12:25:48
【问题描述】:
我正在使用 Un4seen 的 BASS 处理一个音频项目。这个库主要使用字节,但我有一个转换,让我以毫秒为单位显示歌曲的当前位置。
知道 MS = 样本 * 1000 / SampleRate 并且 Samples = Bytes * 8 / Bits / Channels
所以这是我的主要问题,它相当简单......我的项目中有一个函数可以将毫秒转换为时间码,单位为 Mins:Secs:Milliseconds。
Public Function ConvertMStoTimeCode(ByVal lngCurrentMSTimeValue As Long)
ConvertMStoTimeCode = CheckForLeadingZero(Fix(lngCurrentMSTimeValue / 1000 / 60)) & ":" & _
CheckForLeadingZero(Int((lngCurrentMSTimeValue / 1000) Mod 60)) & ":" & _
CheckForLeadingZero(Int((lngCurrentMSTimeValue / 10) Mod 100))
End Function
现在问题出现在秒计算范围内。任何时候 MS 计算超过 0.5 秒位置都会向上舍入到下一秒。所以 1.5 秒实际上打印为 2.5 秒。我确信使用 Int 转换会导致向下舍入,并且我知道我的数学是正确的,因为我已经在计算器中检查了 100 次。我不明白为什么这个数字会四舍五入。有什么建议吗?
【问题讨论】:
-
这是我遗漏的一个函数: Private Function CheckForLeadingZero(ByRef intValue As Integer, Optional ByVal intLength As Integer = 2) As String Dim strValue As String strValue = CStr(intValue) If Len(strValue)