Repository navigation
fix: 修复低音量段无声与进度跳转时的音量突增 - #419
Open
foragedysetour wants to merge 1 commit into
Open
foragedysetour wants to merge 1 commit into
foragedysetour wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改动类型
是否包含破坏性变更
改动说明
问题出在增益换算层:
src/utils/volume.ts使用gain = position³,导致 10% 位置仅 -60 dB,5% 仅 -78 dB,低音量区几乎无声;滚轮每格固定 5%,但响度步进严重不均——底部一格约 18 dB,顶部仅 1.3 dB。现改为位置与 dB 线性:整条滑块覆盖 0 至 -60 dB,每 1% 约 0.6 dB,滚轮每格约 3 dB;1% 约 -59.4 dB,50% 为 -30 dB,100% 仍为 0 dB。代价是中段输出比旧版低约 12 dB,50% 从 -18.1 dB 变为 -30 dB,但低段可用、步进可预期。
静音从公式中拆出:位置 0 为静音档(
gain = 0),工具栏静音按钮单独记录lastVolume,取消静音时恢复原值(无记录时回到 0.7)。输出层在
cpal_stream.rs、wasapi/pcm.rs中于每个回调缓冲内做 10–20 ms 线性增益过渡,避免拖动音量或切静音产生 click。增益状态改为Option<f32>:新流、暂停恢复后的首个缓冲直接采用目标值,仅播放中的变化才渐变,避免 seek 后首缓冲满音量爆音。改动清单
src/utils/volume.ts:MIN_VOLUME_DB = -60,正反变换改为 dB 线性,位置保留 6 位小数src/utils/volume.spec.ts(新增):静音、最低档、dB 线性、逆变换、满音量,共 7 例src/components/player/Toolbar.spec.ts:按新曲线更新期望值native/audio-engine/src/output/:cpal_stream.rs、wasapi/pcm.rs、wasapi/mod.rs的增益过渡与首缓冲对齐关联 Issue
Closes #416
测试情况
pnpm exec vitest run:64 个文件全部通过pnpm typecheck、pnpm lint通过;改动文件已通过prettier --checkcargo check --all-targets、cargo fmt --check通过复现:滑块拖到 5%–10%,旧版几乎无声,新版可听到轻微连续声音;连续拖动进度条时,旧版(加渐变后)会在起播瞬间顶到满音量。
自查清单
pnpm format,pnpm typecheck、pnpm lint通过pnpm build:native验证;未手写native/*/index.d.tsdev分支提交