-
Notifications
You must be signed in to change notification settings - Fork 49
feat(mobile): scale completion sound speed with task length #3050
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
Merged
charlesvien
merged 3 commits into
main
from
posthog-code/mobile-scale-completion-sound-speed
Jul 2, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { playbackRateForTaskDuration } from "./playbackRate"; | ||
|
|
||
| describe("playbackRateForTaskDuration", () => { | ||
| it.each([ | ||
| ["below the fast floor (10s)", 10 * 1000, 3], | ||
| ["at the fast floor (30s)", 30 * 1000, 3], | ||
| ["geometric mid of the fast ramp (60s)", 60 * 1000, Math.sqrt(3)], | ||
| ["normal band start (2min)", 2 * 60 * 1000, 1], | ||
| ["normal band end (4min)", 4 * 60 * 1000, 1], | ||
| [ | ||
| "geometric mid of the slow ramp", | ||
| Math.sqrt(4 * 60 * 1000 * (30 * 60 * 1000)), | ||
| Math.sqrt(1 / 3), | ||
| ], | ||
| ["at the slow ceiling (30min)", 30 * 60 * 1000, 1 / 3], | ||
| ["beyond the slow ceiling (2h)", 2 * 60 * 60 * 1000, 1 / 3], | ||
| ["NaN (non-finite) → fast rate", Number.NaN, 3], | ||
| ])("%s → %f", (_label, durationMs, expected) => { | ||
| expect(playbackRateForTaskDuration(durationMs)).toBeCloseTo(expected, 5); | ||
| }); | ||
|
|
||
| it("decreases monotonically as duration grows", () => { | ||
| const durations = [ | ||
| 10 * 1000, | ||
| 45 * 1000, | ||
| 90 * 1000, | ||
| 2 * 60 * 1000, | ||
| 4 * 60 * 1000, | ||
| 10 * 60 * 1000, | ||
| 30 * 60 * 1000, | ||
| ]; | ||
| const rates = durations.map(playbackRateForTaskDuration); | ||
| for (let i = 1; i < rates.length; i++) { | ||
| expect(rates[i]).toBeLessThanOrEqual(rates[i - 1]); | ||
| } | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| const MIN_RATE = 1 / 3; | ||
| const MAX_RATE = 3; | ||
| const FAST_MS = 30 * 1000; | ||
| const NORMAL_START_MS = 2 * 60 * 1000; | ||
| const NORMAL_END_MS = 4 * 60 * 1000; | ||
| const SLOW_MS = 30 * 60 * 1000; | ||
|
|
||
| // Maps a task's duration to an audio playback rate so a quick task rings fast | ||
| // (and high-pitched) while a long one drags slow (and low). Anchored at: <=30s | ||
| // -> 3x, the 2-4min "normal" band -> 1x, >=30min -> 1/3x, with smooth | ||
| // log-interpolation across the two ramps so the rate doesn't jump at the edges. | ||
| export function playbackRateForTaskDuration(durationMs: number): number { | ||
| if (!Number.isFinite(durationMs) || durationMs <= FAST_MS) return MAX_RATE; | ||
| if (durationMs >= SLOW_MS) return MIN_RATE; | ||
| if (durationMs >= NORMAL_START_MS && durationMs <= NORMAL_END_MS) return 1; | ||
|
|
||
| if (durationMs < NORMAL_START_MS) { | ||
| const frac = | ||
| (Math.log(durationMs) - Math.log(FAST_MS)) / | ||
| (Math.log(NORMAL_START_MS) - Math.log(FAST_MS)); | ||
| return MAX_RATE ** (1 - frac); | ||
| } | ||
|
|
||
| const frac = | ||
| (Math.log(durationMs) - Math.log(NORMAL_END_MS)) / | ||
| (Math.log(SLOW_MS) - Math.log(NORMAL_END_MS)); | ||
| return MIN_RATE ** frac; | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.