Skip to content

Fix/render and timestretch - #58

Open
Xiantaidu wants to merge 3 commits into
YuFeng926:standalonefrom
Xiantaidu:fix/render-and-timestretch
Open

Xiantaidu wants to merge 3 commits into
YuFeng926:standalonefrom
Xiantaidu:fix/render-and-timestretch

Conversation

@Xiantaidu

Copy link
Copy Markdown

Problem

A non-identity TimeGrid is realised by stretching Stage 1's rendered waveform
in Stage 2 (WSOLA via SoundTouch). Stretching an already-vocoded signal leaves
an audible vibrato/tremor on sustained notes: the waveform is resampled after
the vocoder has fixed the harmonic phase, so every analysis window re-decides
pitch-period alignment independently. Short TimeGrid segments (~30-60 ms, below
SoundTouch's 73-90 ms analysis window) are the worst case -- the joins between
them are phase-incoherent.

Approach

Stage 1 now applies the time mapping to its own conditioning. Mel/log-linear
frames and the F0/UV track are warped by tauInverse before synthesis, so the
vocoder generates the stretched result directly and Stage 2 becomes a pure copy.

This keeps the signal at exactly one vocoder pass. The previous path was one
pass plus a waveform stretch; the obvious alternative (re-analyse and
re-synthesise) would have been two, which loses detail and doubles cost.

TimeGridConditioningWarp::stage1BakesGrid is the single predicate deciding
which regime a render is in. ContentRenderService records per-content whether
Stage 1 baked a given timeGridRevision, and Stage2TimeStretchRebuilder
reads that flag to choose copy vs stretch. The WSOLA path is kept for the cases
the bake does not cover.

Consequences handled

  • Two clocks. The F0 timeline is indexed in source time while chunk
    boundaries are in output time. When baking, the F0 query range is mapped
    through tauInverse; otherwise a grid that moves output onto a different
    source position reads the wrong frames and can blank voiced regions.
  • Fast paths are suppressed while baking. Both settleBlankChunk and the
    AutoTune light-pitch path publish un-warped audio; skipping the vocoder there
    would discard the time mapping entirely.
  • setContentTimeGrid must re-run Stage 1, through the same
    requestRenderForLocalMutationRange path other local edits use. It
    deliberately does not invalidate TimeStretchCache by hand -- that advances
    the generation, makes the result Stage 2 just published stale, and the
    playback reader then returns 0 samples, i.e. the whole track goes silent.
  • A non-identity grid advances contentRevision in the content owners.
    reconcileFullPlanAndRequest decides re-render by comparing
    contentRevision alone, so bumping only timeGridRevision made every handle
    drag a no-op: anchors moved on screen and nothing was re-synthesised.

Second commit: re-render only the edited span

Dragging one handle used to re-render the whole track -- setContentTimeGrid
asked for the entire [0, duration] range, and RenderCache decides what to
re-run by whether a chunk intersects the request. A 290 s clip meant all 82
chunks went through the vocoder again for a one-anchor nudge.

Only two segments actually change when an anchor moves -- the ones either side of
it. timeGridAffectedOutputRange diffs the before/after snapshots by handle id
(ids are stable across drag and undo/redo; source_seconds are immutable once
inserted, so an id whose output_seconds moved was dragged) and returns the
union of the neighbouring anchors' output positions. Insert and delete widen it
to both sides, since merging or splitting a segment changes both.

Anything not confidently narrow falls back to the full track: over-rendering is
far cheaper than shipping stale audio.

Tests

  • TimeGridConditioningWarpTests -- mapping contract: monotonicity, endpoint
    pinning, chunk-seam continuity.
  • ContentSnapshotProjectionTests -- the contentRevision rule across
    identity/non-identity transitions.
  • TimeGridEditTests -- middle-anchor drag narrows to exactly its neighbour
    span, edge-anchor drags cover the ends, insert/delete widen correctly,
    identical grids report no change.

40/40 ctest passing. Verified that this branch builds and passes on its own,
without the CopyVocal import branch.

…Stage 2

A non-identity TimeGrid used to be realised by stretching Stage 1's rendered
waveform in Stage 2 (WSOLA via SoundTouch). Stretching an already-vocoded
signal leaves an audible vibrato/tremor on sustained notes, because the
waveform is resampled after the vocoder has fixed the harmonic phase.

Stage 1 now applies the time mapping to its own conditioning: mel/log-linear
frames and the F0/UV track are warped by tauInverse before synthesis, so the
vocoder generates the stretched result directly and Stage 2 becomes a pure
copy. This keeps the signal to exactly one vocoder pass -- the previous path
was one pass plus a waveform stretch, and the obvious alternative
(re-analyse and re-synthesise) would have been two.

TimeGridConditioningWarp::stage1BakesGrid is the single predicate deciding
which regime a render is in; ContentRenderService tracks per-content whether
Stage 1 baked a given timeGridRevision, and Stage2TimeStretchRebuilder reads
that flag to choose copy vs stretch. The WSOLA path is kept for the cases the
bake does not cover.

Consequences handled here:

- The F0 timeline is indexed in source time while chunk boundaries are in
  output time. When baking, the F0 query range is mapped through tauInverse;
  otherwise a grid that moves output onto a different source position reads
  the wrong frames and can blank voiced regions.
- Fast paths that publish un-warped audio (blank-chunk settle, the AutoTune
  light pitch path) are suppressed while baking: skipping the vocoder would
  discard the time mapping entirely.
- setContentTimeGrid must now re-run Stage 1, via the same
  requestRenderForLocalMutationRange path other local edits use. It
  deliberately does not invalidate TimeStretchCache by hand -- that advances
  the generation and makes the result Stage 2 just published stale, so the
  playback reader returns 0 samples and the track goes silent.
- A non-identity grid advances contentRevision in the content owners.
  RenderCache::reconcileFullPlanAndRequest decides re-render by comparing
  contentRevision alone, so bumping only timeGridRevision made every handle
  drag a no-op: anchors moved on screen and nothing was re-synthesised.

Tests: TimeGridConditioningWarpTests covers the mapping contract (monotonicity,
endpoint pinning, chunk-seam continuity); ContentSnapshotProjectionTests covers
the contentRevision rule across identity/non-identity transitions.
Dragging one handle re-rendered the whole track: setContentTimeGrid asked for
the entire [0, duration] range, and RenderCache decides what to re-run by
whether a chunk intersects the request. A 290 s clip meant all 82 chunks went
through the vocoder again for a one-anchor nudge.

Only two segments actually change when an anchor moves -- the ones either side
of it -- because every other segment keeps the same source/output pair and so
the same slope. timeGridAffectedOutputRange diffs the before/after snapshots
by handle id (ids are stable across drag and undo/redo; source_seconds are
immutable once inserted, so an id whose output_seconds moved was dragged) and
returns the union of the neighbouring anchors' output positions. Insert and
delete widen it to the anchors on both sides, since merging or splitting a
segment changes both.

Differential analysis is only taken when a narrow range is actually trustworthy;
anything else falls back to the full track, because over-rendering is far
cheaper than shipping stale audio. The before/after snapshot is read before
applyTimeGrid, and only when the edit will bake (or when Stage 1 has baked
before, i.e. reverting a baked grid to identity still needs the diff) --
getContentSnapshot rebuilds the whole snapshot and identity-only edits go down
the Stage 2 path, so they should not pay for it.

Tests: TimeGridEditTests asserts a middle-anchor drag narrows to exactly its
neighbour span, edge-anchor drags cover the ends, insert/delete widen
correctly, and identical grids report no change.
Map source-timeline edit ranges onto the output timeline used by Stage 1 chunks when a TimeGrid is baked, so pitch and note edits re-render the correct chunks. Rebase published revision tags after a republish-only content change so playback keeps reading existing PCM. Stage an ASCII-named demo wav for the Windows POST_BUILD copy step. Add regression tests for both fixes.
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.

1 participant