Repository navigation
Android generator and calibrator take - #71
Merged
Merged
Conversation
Shared C++ for the AV Sync calibrator board (docs/calibrator.md, contract v1): - find_sound_onsets: clicks and beeps in a recording (trailing 0.25 ms RMS, 25 % of peak), told apart by 2.7 kHz vs 1.5 kHz energy. - find_flash_onsets: LED flash start from row-band means, on the rolling-shutter row the analyzer uses; readout from the band height or, with full-frame exposure, fitted over the pulses in camera_calibration. - camera_calibration: pair flashes with clicks, robust median, uncertainty. - display_calibration: click then beep D = 100 ms later, offset = gap - D, both swap directions weighted equally. - calibration pattern for all generators: halves swap every 500 ms, beep. Unit tests on synthetic signals (noise, missing pulses, stray sound, rolling shutter with known/unknown readout, slow screen, sensor mismatch). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
PhoneAnalyzer::begin_calibrator keeps 32 row-band means per frame and the microphone, and poll_calibrator reports progress about once a second, then the result (20 pairs or 30 s) or an error. No live report or QR scan while it runs. iOS: beginCalibrator(mode) on the camera view; the camera take first re-locks exposure (frame interval) at the lowest ISO, because the LED floods the lens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
…the QR
generateStyled(..., {mode: 'calibration'}) shows the calibration pattern in
the generator's own screen: the same display link, layers, audio engine and
player node as the test signal. Portrait halves left and right near the
bottom microphone, a red outline of the board, halves swap every 500 ms, a
1.5 kHz beep 100 ms after each swap (scheduled on the host clock minus the
reported output latency). The session is play-and-record on the built-in
speaker; the microphone take is analysed with the shared core
(display_calibration) and the result comes back when the screen closes.
The test signal sends a saved sender calibration in the AVS4 QR
(senderCalibration* options), only on the audio output it was measured on.
Core pattern helpers are now frame based (also 59.94 fps).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
Same feature as the phone: the generator can send the calibration pattern instead of the test signal, so a phone with the calibrator board can measure a TV/monitor chain. Left/right halves swap every 500 ms on the grain grid (also interlaced and 59.94), a 1.5 kHz beep 100 ms after each swap at the chirp level, a grey tick at the ends of the pattern line. Live key, also in the Signal API (pattern) and the web form (Picture). tests/tools/calibration_flow + tests/integration/calibration_pattern.py read both flows, check the timing and run a simulated calibrator through display_calibration (1080p50, 1080i25, 1080p59.94: 0.03 ms). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
Three steps with small animations: plug in, camera (the calibrator on the rear camera; progress ring of 20 flashes; 'Camera vs mic' result saved as this phone's analyser calibration, method calibrator-pulse, same record and validity as the clap), screen (the generator's calibration pattern; 'Screen vs speaker' saved as this phone's sender calibration, method transponder). The test signal then sends it in the AVS4 QR. A TV/monitor showing the container's calibration pattern can be measured too (result only, not saved). The clap calibration is unchanged. iOS only for now (Android has no generator and no calibrator take yet). Pure logic in src/calibrator.mjs with node tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
docs/calibrator.md (copy of PR #69's contract) gets an 'App side' section and the list of changes from the v1 proposal (none needs a firmware change). calibration.md: user guide 'With the calibrator'. phone-generator.md: calibration mode and the sender calibration in the QR. SPECIFICATION: AVSYNC_PATTERN and the calibrator in 12.3. IMPLEMENTATION_PLAN: entry with the deviations. CHANGELOG, mobile-app README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
… clap gap fill unchanged Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
Done once in core (Pairer::set_sender_calibration) for the phone session, the container analyzer and the file analyzer. Events keep raw_av_offset_ms and sender_calibration_ms; the phone reading has rawOffsetMs and senderCalibrationMs; /api/v1/measurement has raw_offset_ms and sender_calibration_ms; the web UI Input card shows AV sync raw. Not calibrated: no change. The phone fixture sends a sender calibration at 2 Hz. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
…ickname Measure and Results show the raw value and the sender calibration under a corrected result; saved results keep them. The analyser calibration stays subtracted in the app only, so nothing counts twice. Clear calibration asks first and clears the analyser and the sender calibration. A sender's default name is the newest Title from its QR; a set nickname wins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
… nickname Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
PhoneGeneratorPlan, the AVS4 QR, render_picture/render_sync_foreground and the calibration pattern functions compile into libavsync-jni as on iOS (generator_jni.cpp mirrors AVSyncGenerator.mm). The renderer's text goes through JNI to Android's text drawing with the bundled DejaVu Sans (GeneratorText.kt), as iOS uses CoreText; the font and icon come from the iOS resource folder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
Same behaviour and options as the iPhone generator: test picture with the AVS3 fields, sync square and scale, AVS4 QR with test ID, title and sender calibration, stable sender ID, 'Stopped' screen, calibration pattern with the microphone. Frames: Choreographer's expected presentation time (API 33+, else frame start plus two periods). Sound: one AudioTrack stream written in 5 ms blocks; packets are placed to the sample by AudioTrack.getTimestamp on System.nanoTime, the clock Choreographer uses. Module: supportsGenerator, generate, generateStyled, pickGeneratorImage, generatorImageInfo, like iOS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
beginCalibrator('camera' | 'display') as on iOS: the camera take re-runs the
auto step and locks at the lowest ISO (or the lowest exposure compensation when
the camera has no manual exposure), then PhoneAnalyzer::begin_calibrator starts;
display mode listens only. Progress and result reports come from
poll_calibrator.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
…on, clear both) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
Same file on both branches now, so the merge has no conflict here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
… on iOS Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
LeeO86
marked this pull request as ready for review
November 9, 2026 10:23
LeeO86
added a commit
that referenced
this pull request
Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #70. Rule: all generators get the same features. Android had no generator and no calibrator take; now it has both, behind the same JS API as iOS.
What this does
phone-+ coregenerator_test_id, install ID in the app preferences, version<versionName> (<versionCode>)), large "Stopped" after Stop, same stop reasons (background, audio focus lost, output changed, clock jump, missed deadline, 23 h), clock reference from the NTP check, screen brightness and wake.generateStyled(..., {mode: 'calibration'})): halves swap every 500 ms on the 60 Hz grid (corecalibration_left_white/calibration_swap_frame), 4 ms 1.5 kHz beep 100 ms after each swap, red board outline in real millimetres, microphone records meanwhile, coredisplay_calibrationonce a second, result or error back when the screen closes.beginCalibrator('camera' | 'display')→PhoneAnalyzer::begin_calibrator, progress/result frompoll_calibrator. The camera take re-runs the auto step and locks at the lowest ISO.supportsCalibratorno longer checks iOS); the Title placeholder says "Android" on Android.Design choices
postVsyncCallback→preferredFrameTimeline.expectedPresentationTimeNanos(like iOStargetTimestamp). Older: frame start + 2 display periods (estimate). The screen asks for a 60 Hz display mode. All onSystem.nanoTime.AudioTrack(48 kHz mono float, ~80 ms buffer), a thread writes 5 ms blocks, silence between packets.AudioTrack.getTimestampmaps an output frame toSystem.nanoTime(the Choreographer clock), so a packet for host time T starts at framepos + (T − time) × 48000: placed to the sample, output latency already inside (iOS subtractsoutputPresentationLatencyinstead). The start frame is recomputed with the newest timestamp each block until two blocks before it starts, so audio-vs-system clock drift does not add up and timestamp jitter cannot push it into the past. Underrun → stop (everything queued would play late). Why not AAudio/Oboe: the timestamp gives the same exact mapping from API 24 without native audio code or a new dependency; low latency is not needed because packets are planned 2.5 s ahead.PhoneGeneratorPlan, AVS4 QR,render_picture/render_sync_foreground, calibration functions compile intolibavsync-jnilike the iOSCore_*.cpp(generator_jni.cppmirrorsAVSyncGenerator.mm). Text: JNI to Android's own text drawing with the bundled DejaVu Sans (GeneratorText.kt), as iOS uses CoreText; the font and icon come from the iOS resource folder (gradleassets.srcDirs).Dialogover the app (no new Activity / manifest entry); one view draws plate, fields, sync square and foreground, rotated in portrait like iOS.GeneratorImageStore.kt), removed when replaced.Tests
node --test mobile-app/src/*.test.mjs tests/web/*.test.cjs: 58 pass.:avsync:testDebugUnitTest, local docker): 14/14 pass, incl. newGeneratorTest(sample placement from a timestamp, block mixing, raster fit, calibration layout in mm).generator_jni.cpp+text_android.cppbuilt for x86_64, a JVM stand-in forGeneratorText): test-ID vectorphone-985274814721, picture renders with all labels, title/subtitle, QR and fields; frame/position/named sequence right; synthetic click+beep train gives −37.93 ms for a planted −38 ms (24 pairs); silence gives the "No clicks heard" error.src/androidTest/PhoneGeneratorTest(needs a device/emulator, not run here; no KVM in the lab): stable ID test vector, picture 1280×720 with AVS4 QR read by ML Kit, host times, audio packet, frame/position, foreground, calibration pattern and silent analysis.android-apk.yaml); APK containslibavsync-jni.so,assets/DejaVuSans.ttf,assets/icon.png. CIapkjob on this PR: green.Device test list (Android phone)
testIdphone-…, Title shown, AV offset stable over 2 min, no "deadline missed"/"dropout".Open risks
AudioTrack.getTimestampaccuracy depends on the HAL (some report coarse or late positions); measured AV offset will show it.UNPROCESSED/VOICE_RECOGNITIONshould not cancel the beep; to check on devices with aggressive processing.🤖 Generated with Claude Code
https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4