ExSrpPhat.Codec (ex_srp_phat v0.1.0)

Copy Markdown View Source

Packs PCM + geometry + opts into little-endian f64/u32 binaries for the NIF, and unpacks the packed results binary back into ExSrpPhat.Source structs. Mirrors the Rust codec module byte-for-byte.

Layouts (all integers u32-little, all reals float-little-64):

  • frames: [n_emp][n_samples] then n_emp × n_samples PCM, row-major
  • geometry: [sample_rate_hz: f64][n_emp: u32] then n_emp × 3 ECEF xyz
  • opts: [grid_extent_m][coarse_res_m][fine_res_m][min_peak_ratio] (f64)
              then `[max_sources: u32]`
  • results: [n_src: u32] then per source 21×f64:
              `xyz(3) | vel(3) | has_vel(1) | radial(1) | has_radial(1) |
               cov(9) | has_cov(1) | confidence(1) | dominant_hz(1)`

Summary

Functions

Pack already-aligned channels (a list of equal-length sample lists, in emplacement order) into the frames buffer.

Pack the sample rate and a list of {x, y, z} ECEF tuples (in emplacement order, aligned to pack_frames/1) into the geometry buffer.

Pack grid-search opts. Recognized keys (all optional, defaults shown)

Unpack the results buffer into a list of ExSrpPhat.Source structs.

Functions

pack_frames(channels)

@spec pack_frames([[number()]]) :: binary()

Pack already-aligned channels (a list of equal-length sample lists, in emplacement order) into the frames buffer.

Sample/coordinate values must be native numbers (integer or float); they are coerced to f64 via * 1.0. Decimal and other numeric structs are not supported.

pack_geometry(sample_rate_hz, ecef_list)

@spec pack_geometry(number(), [{number(), number(), number()}]) :: binary()

Pack the sample rate and a list of {x, y, z} ECEF tuples (in emplacement order, aligned to pack_frames/1) into the geometry buffer.

pack_opts(opts \\ [])

@spec pack_opts(keyword()) :: binary()

Pack grid-search opts. Recognized keys (all optional, defaults shown):

  • :grid_extent_m (300.0) — half-extent of the search cube around the centroid
  • :coarse_res_m (20.0) — coarse grid cell size
  • :fine_res_m (2.0) — finest grid cell size after refinement
  • :min_peak_ratio (0.5) — peak significance threshold (fraction of global max)
  • :max_sources (4) — cap on returned sources

unpack_results(arg)

@spec unpack_results(binary()) :: [ExSrpPhat.Source.t()]

Unpack the results buffer into a list of ExSrpPhat.Source structs.