Snap Detected Vocal Onsets to a Tempo Grid

Last updated: November 29, 2026

Quick Overview

Given a list of detected note onset times in seconds, a song tempo in BPM and a grid subdivision (for example 4 for sixteenth notes), return each onset snapped to the nearest grid line, optionally leaving onsets alone when the snap would move them more than a tolerance.

Suno
Coding & Algorithms
Software Engineer
Suno
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a list of detected note onset times in seconds, a song tempo in BPM and a grid subdivision (for example 4 for sixteenth notes), return each onset snapped to the nearest grid line, optionally leaving onsets alone when the snap would move them more than a tolerance.

A warm-up in the style of a Suno Studio coding screen, where generated stems and recorded takes need to line up with the song's beat grid. The interviewer is checking that you turn musical units into time units correctly and write clean, well-named code rather than racing.

What the Interviewer Expects
  • Derive grid spacing as 60 / bpm / subdivision seconds
  • Round to the nearest grid index rather than flooring
  • Validate bpm and subdivision inputs
  • Handle an optional maximum shift (humanize tolerance)
  • Discuss floating point rounding in the output
Key Topics to Cover
Quantization
Tempo and beat math
Floating point
Clean API design
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you support a tempo map where BPM changes mid-song?
  • How would you add swing, where every second subdivision is delayed?
  • What changes if onsets arrive as a stream during recording?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: onsets (seconds), bpm, subdivision (grid lines per beat), optional max_shift in seconds. Output: snapped times in the same order. A beat lasts 60 / bpm seconds, so a sixteenth-note grid...

High-Level Design

Compute the grid step once. For each onset, find k = round(t / step) and the snapped time k * step. If a tolerance is given and the shift exceeds it, keep the original onset (an expressive note th...


Submit Your Answer
Markdown supported

Related Questions