Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

避免大于音频当前播放时间的“提前毫秒数”使歌词时间戳为负 #67

Merged
merged 2 commits into from
Feb 27, 2020

Conversation

pzhlkj6612
Copy link
Member

@pzhlkj6612 pzhlkj6612 commented Feb 26, 2020

Fixed #65
Reverted 8b5141f

@BensonLaur @ish-kafel


#65curAudioPos关系不大,故撤销上一个提交(不过,没有为curAudioPos赋初值的确会造成潜在的问题)。


实际上,无论是哪一句歌词,只要insertOffsetTime大于音频的当前播放时间,由于盲目的计算time -= insertOffsetTime,都会使计算出的时间戳为负值。


注意,出现负值的根本原因是程序中数据类型的混乱,代码如下:

https://github.com/Beslyric-for-X/Beslyric-for-X/blob/8b5141f5ba94899ea2e6ae3fb235f0459abcf671/Entities/LyricMaker.cpp#L319-L337

证明:

  1. quint64类型最大值为18446744073709551615int类型范围为-21474836482147483647,共4294967296个数;
  2. 18446744073709551615进行两次除法运算(分别除以100060)后,值为307445734561825
  3. 通过取模(这里也可以称为取余,因为同号)运算307445734561825 % 4294967296,值为3385579553,即对于unsigned int类型,结果为3385579553
  4. 由于输出时转换为int类型(%.2d),又因为3385579553>2147483647,所以结果为负数;
  5. 3385579553 - 2147483647结果为1238095906,即从-2147483648算起第 1238095906 个数,即-2147483648 + 1238095906 - 1,结果为-909387743

在搜索引擎里搜索909387743,能看到有多少歌词受到了这个 BUG 的影响。


本 PR 能够帮助到未来的一个需求: #66

@pzhlkj6612 pzhlkj6612 added this to the Next Release milestone Feb 26, 2020
@pzhlkj6612 pzhlkj6612 requested review from BensonLaur and removed request for BensonLaur February 26, 2020 15:47
@pzhlkj6612 pzhlkj6612 merged commit 76af7d2 into master Feb 27, 2020
@pzhlkj6612 pzhlkj6612 deleted the negative_timestamp branch February 27, 2020 07:30
@BensonLaur
Copy link
Member

优秀!

第5步的另一个思路可以由 一个负数的 32位无符号二进制为 该负数绝对值二进制的反码加1(相当于2^32-该负数的绝对值) 该过程的反过程可推出,一个32位无符号 A 对应的 负数值 = -(2^32- A) = -(4294967296-3385579553) = -909387743

@BensonLaur BensonLaur mentioned this pull request Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

首句歌词时间戳异常
2 participants