TeamMajdata.MajOffset 0.1.0

dotnet add package TeamMajdata.MajOffset --version 0.1.0
                    
NuGet\Install-Package TeamMajdata.MajOffset -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TeamMajdata.MajOffset" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TeamMajdata.MajOffset" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="TeamMajdata.MajOffset" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TeamMajdata.MajOffset --version 0.1.0
                    
#r "nuget: TeamMajdata.MajOffset, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TeamMajdata.MajOffset@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TeamMajdata.MajOffset&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=TeamMajdata.MajOffset&version=0.1.0
                    
Install as a Cake Tool

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.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 50 11/30/2026