Skip to content

feat: expose sample positions for raw model frames - #211

Open
marlonwq wants to merge 1 commit into
spotify:mainfrom
marlonwq:codex/raw-frame-sample-positions
Open

marlonwq wants to merge 1 commit into
spotify:mainfrom
marlonwq:codex/raw-frame-sample-positions

Conversation

@marlonwq

Copy link
Copy Markdown

Summary

Closes #190. Consumers of raw note, onset, and contour arrays can now map frames to original-audio sample positions without accumulating error at input-window boundaries. Add the opt-in model_frames_to_samples() utility and document its use in unwrap_output, run_inference, and the README.

retained_frames_per_window = ANNOT_N_FRAMES - 2 * floor(overlap_frames / 2)
window, local_frame = divmod(frame_index, retained_frames_per_window)
sample_position = window * input_hop + local_frame * FFT_HOP + padding_offset

This follows the same request as #199, which was closed by its author without merge. The helper accounts for input padding, supports custom hops and odd overlaps, and keeps the existing inference arrays and decoded MIDI behavior intact. It describes the raw frame grid, separately from the empirical alignment correction used for decoded note events.

Evidence

  • Before: On a synthetic 530-second window grid, uniform frame_index * FFT_HOP indexing differs from window-derived sample positions by up to 60,724 samples (about 2.75 seconds).
    After: The helper matches those positions exactly, with zero sample-position error.

  • 23 tests passed on Windows / Python 3.12.14 with the bundled ONNX model and ONNX Runtime 1.20.1:

    python -m pytest tests/test_inference.py tests/test_inference_timing.py tests/test_note_creation.py -q
    23 passed, 5 warnings in 104.53s
    

    This includes 13 new timing cases, existing prediction/note-event reference comparisons, and MIDI/WAV/CSV/NPZ export. The timing cases exercise real input-window generation and unwrapping, including zero overlap, odd overlap, custom hops, empty output, invalid parameters, and a long recording's window grid.

  • Black (120-column limit), Flake8, and git diff --check pass for the changed files. TensorFlow training and dataset suites were not run locally.

Merge Danger

Door: Two-way. The helper, documentation, and tests can be reverted independently.

Blast Radius: API. Adds an opt-in function; existing prediction values, note decoding, and MIDI output are unchanged. Callers using custom overlap/hop settings must pass those same settings to the helper. Sample positions use the resampled 22,050 Hz audio grid and are not clipped to audio duration.

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.

Frame-level model_output["note"] array has growing temporal drift due to hop_size ≠ kept_frames × FFT_HOP

1 participant