Skip to content
TeamMajdataPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

MajOffset

Beat-grid offset measurement for Simai charts. Given the PCM of a track, the chart's note times and the &first it declares, it reports how far the declared offset is from the audio.

The analyzer owns its working buffers: after the first call on a track, an analysis allocates only the result object. Keep one OffsetAnalyzer instance to analyze many charts in a row (the static Analyze uses one per thread).\n\nThe tempo is never used. The notes already say where the author meant every hit to be, and the only unknown is a uniform shift, so the analysis is a one-dimensional score over the offset:

score(Δ) = mean onset strength at (note time + &first + Δ)

The search radius comes from the chart itself: half the median distance between notes keeps the scan inside one cell of the note pattern, where no shifted copy can score as well by accident. It is clamped to 40–200 ms.

Usage

// pcm: mono float at 16 kHz (BASS resamples while it decodes, so callers rarely resample)
// notes: SimaiTimingPoint.Timing — chart-relative seconds, &first NOT added
var notes = chart.NoteTimings.ToArray().Select(t => t.Timing).ToArray();
var result = OffsetAnalyzer.Analyze(pcm, notes, givenOffsetSeconds: file.Offset);

Console.WriteLine($"{result.DeltaMilliseconds:+0.0;-0.0} ms, {result.Confidence}");
// the corrected value to write back into maidata.txt
var correctedFirst = file.Offset + result.DeltaMilliseconds / 1000.0;

OffsetAnalysisResult exposes:

Member Meaning
DeltaMilliseconds measured offset − declared offset, in ms; add it to &first to fix the chart
EstimatedOffsetSeconds the corrected offset itself
CombContrast the score at the chosen offset divided by the median score; below 1.10 nothing was found
NoteScatterMilliseconds the typical distance between a note and the onset it lands on
DriftMilliseconds how far the four quarters of the chart disagree
SearchWindowMilliseconds the radius the scan used
BeyondWindow the best offset sat at the edge, so the truth may lie outside the radius
NoteCount notes that landed inside the track
Candidates rival offsets that scored well, best first
Confidence High, Medium or Unreliable

When the answer is Unreliable

A chart can be internally inconsistent — a wrong tempo value makes its notes drift against the audio, a misplaced tempo change makes them jump — and then no single shift fits. That is detected, not averaged away:

Signal Meaning
NoteScatterMilliseconds > 20 the notes do not agree on any one offset
CombContrast < 1.10 no offset stands out at all (the notes are not on attacks)
DriftMilliseconds > 25 one part of the chart disagrees with another (12–25 only drops to Medium)
BeyondWindow the best fit is at the edge, so the real answer is probably larger

For scale, on a set of 19 charts the reliable ones sat at 3.6–10.4 ms scatter, while a chart with a wrong tempo value and a chart whose notes avoided the attacks both landed at 22–31 ms.

Limits

  • Input contract: mono at 16000 Hz; notes in chart-relative seconds.
  • Not a beat tracker: the answer is a uniform shift. If the chart is a whole bar off, this reports a large shift (up to the radius) rather than the musically right one.
  • No tempo diagnostics: without a tempo map the tool cannot say which section is wrong, only that the chart is inconsistent.
  • Absolute accuracy is around ±5 ms; comparisons between two measurements are good to ~2 ms.
  • The decoder matters: BASS and ffmpeg differ by up to 12 ms on some MP3s because of how each handles the decoder delay, so measure on the same timeline the player uses.

Documentation

  • How it works — 中文,写给不熟悉信号处理的读者:它在量什么、 怎么量、什么时候不该信它。
  • MajdataPlay integration — the exact files and code to wire it into the player.

Integrating into MajdataPlay

This package only needs PCM and the chart, so MajdataPlay needs one addition to its audio layer to expose PCM plus a small service. A step-by-step guide with the exact files, code and verification steps is in Documentation~/MajdataPlay.md.

Building

dotnet build MajOffset.csproj -c Release

The Unity assembly definition is Runtime/MajOffset.asmdef (no engine references, unsafe code enabled); the project file is for standalone builds and tests.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages