Skip to content

Frame sync: replace per-symbol full sort with single-pass top-5 selection - #143

Open
xdab wants to merge 1 commit into
szechyjs:masterfrom
xdab:dsd-sync-hunt-topn
Open

xdab wants to merge 1 commit into
szechyjs:masterfrom
xdab:dsd-sync-hunt-topn

Conversation

@xdab

@xdab xdab commented Sep 21, 2026 •

Copy link
Copy Markdown

As announced in #142 - getFrameSync() in dsd_frame_sync.c copies the symbol amplitude window into lbuf2 and runs a full qsort over it on every iteration of the hunt loop - per symbol, for as long as no sync is found, just to read a couple of values off each end for the lmin/lmax level tracking.

An idle decoder on a quiet channel pays for this continuously. I was fixing this on a local fork, along with other perf-related improvements - now decided to share some back with the public repos; the dsd-fme equivalent already went in via lwvmobile#362.


This PR replaces the copy + sort with a single pass that keeps the five smallest and five largest values in two fixed 5-slot arrays and reads the same ranked endpoints from those.

Output is bit-identical, the idle hunt loop just stops paying for a full sort per symbol.
The datascope histogram now bins the unsorted window directly (bin counts don't depend on ordering), the unused lbuf2 scratch buffer is dropped; comp() in dsd_main.c stays, as the symbol timing sort in dsd_dibit.c still uses it.

Verified byte-identical console output (timestamps stripped) on DMR and D-Star sample captures, including runs with a 10 s no-carrier lead-in to exercise the hunt path, plus datascope mode. The sample-file testing was performed by AI as part of this PR's preparation.
Clean build, no new warnings.

…tion

The frame sync hunt loop copied the symbol amplitude window into
lbuf2 and ran a full qsort over it on every iteration, only to read
three ranked values off each end for lmin/lmax. Replace that with a
single pass maintaining the five smallest and five largest values in
two fixed 5-slot arrays; the same ranked endpoints are read from
those, so output is bit-identical.

The datascope histogram now bins the unsorted window (order does not
affect bin counts). The unused lbuf2 scratch buffer is removed; comp()
stays as dsd_dibit.c still uses it.

Ref: lwvmobile#142
@xdab
xdab force-pushed the dsd-sync-hunt-topn branch from 5cce1a1 to c134101 Compare September 21, 2026 18:48
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.

1 participant