Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions doc/concept/audio-jitter.md
Original file line number Diff line number Diff line change
Expand Up @@ -940,10 +940,12 @@ keeps three numbers: `owed`, the playhead movement the pace asked for that no
splice took yet; its `direction`; and an `allowance`, which starts at `span`.

At each hop boundary, before anything else, the allowance refills by
`CAP * hop`, up to `span`. If the pace's sign differs from `direction`, it
becomes the direction and `owed` resets to zero. A hold returns no splice.
Otherwise `owed` adds `pace * hop`, clamped to ±`span`, and a splice is tried
once `direction * owed >= hop`, or at once when urgent. The shift's range is
`CAP * hop`, up to `span`. A hold returns no splice and keeps `owed`, so a lag
flickering across half a hop, as clock readings jitter, still adds up to one.
Otherwise, if the pace's sign differs from `direction`, it becomes the
direction and `owed` resets to zero; then `owed` adds `pace * hop`, clamped
to ±`span`, and a splice is tried once `direction * owed >= hop`, or at once
when urgent. The shift's range is
the decision's `[low, high]`, within ±`floor(allowance)`, at least `-head` (the
history held) and at most what is held past the playhead less a hop; when not
urgent, also within a hop of `owed`, `[ceil(owed) - hop, floor(owed) + hop]`.
Expand Down
2 changes: 1 addition & 1 deletion doc/concept/audio-jitter/stretch/corpus.json

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion doc/concept/audio-jitter/stretch/corpus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,20 @@ export const cases: Case[] = [
),
stretch(
"turns-around",
"A change of direction starts the pace from nothing, and holding forgets it too.",
"A change of direction starts the pace from nothing, even across a hold.",
8000,
1,
voiced(8000, ms(8000, 340), 150, 250, 5),
[...Array(11).fill(behind(8000)), ...Array(11).fill(ahead(8000)), HOLD, ...Array(11).fill(behind(8000))],
),
stretch(
"flickers",
"A hold keeps the pace owed, so a lag flickering across half a hop still splices once its pace adds up to a hop.",
8000,
1,
voiced(8000, ms(8000, 340), 180, 220, 19),
Array.from({ length: 24 }, (_, i) => (i % 2 === 0 ? behind(8000) : HOLD)),
),
stretch(
"narrow-range",
"A decision's range bounds the splice whatever matches better past it.",
Expand Down
3 changes: 2 additions & 1 deletion doc/concept/audio-jitter/stretch/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export function play(
allowance = Math.min(allowance + CAP * h, span);
let shift = 0;
const sign = Math.sign(decision.pace);
if (sign !== direction) {
// A hold keeps the pace owed, so a lag flickering across half a hop still adds up to a splice.
if (sign !== 0 && sign !== direction) {
direction = sign;
owed = 0;
}
Expand Down
3 changes: 2 additions & 1 deletion js/watch/src/audio/stretch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,12 @@ export class Stretch {
this.#until = this.hop;
this.#allowance = Math.min(this.#allowance + CAP * this.hop, this.span);
const direction = Math.sign(decision.pace);
// A hold keeps the pace owed, so a lag flickering across half a hop still adds up to a splice.
if (direction === 0) return 0;
if (direction !== this.#direction) {
this.#direction = direction;
this.#owed = 0;
}
if (direction === 0) return 0;
this.#owed = Math.min(Math.max(this.#owed + decision.pace * this.hop, -this.span), this.span);
if (!decision.urgent && direction * this.#owed < this.hop) return 0;

Expand Down
7 changes: 4 additions & 3 deletions rs/moq-audio/src/stretch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,14 @@ impl Stretch {
} else {
0
};
// A hold keeps the pace owed, so a lag flickering across half a hop still adds up to a splice.
if direction == 0 {
return 0;
}
if direction != self.direction {
self.direction = direction;
self.owed = 0.0;
}
if direction == 0 {
return 0;
}
self.owed = (self.owed + decision.pace * hop).clamp(-span, span);
if !decision.urgent && f64::from(direction) * self.owed < hop {
return 0;
Expand Down
14 changes: 7 additions & 7 deletions test/audio-quality/budgets.json

Large diffs are not rendered by default.