Skip to content

File wfm_compose.h

FileList > doppler > wfm > wfm_compose.h

Go to the source code of this file

Multi-segment waveform composer (Phase B). More...

  • #include "doppler/clib_common.h"
  • #include "doppler/wfm_synth/wfm_synth_core.h"
  • #include "doppler/wfm/wfm_frame.h"
  • #include "doppler/wfm/wfm_data.h"
  • #include "doppler/doppler_channel/doppler_channel_core.h"

Classes

Type Name
struct wfm_draw_t
One rendered source instance: its timing AND the values it was actually rendered with.
struct wfm_scene_ops
The composer's own entry points, as a table its state starts with.
struct wfm_segment_t
One composer segment: one or more sources summed over the same span, then a trailing off-time gap.
struct wfm_source_t
One additive source within a segment: a synth config + its level.
struct wfm_span_t
One rendered segment instance's exact timing: where it lands in the composed stream and how its delay | on | off spans divide it.

Public Types

Type Name
typedef struct wfm_compose_state dp_wfm_compose_state_t
enum wfm__compose_8h_1abc5c98fcc1211af2b80116dd6e0a035d
Per-field "draw uniformly each repeat" flags ( ranged bitmask).
enum wfm_bitmod_t
How a WFM_SYNTH_BITS source maps its payload to symbols.
enum wfm_doppler_lifetime_t
When a source's Doppler channel restarts.
typedef void(* wfm_feed_fn
Where a channel renderer's INPUT comes from, when it is not a synth.
typedef struct wfm_render wfm_render_t
One source's renderer: its synth, plus its Doppler channel.
typedef struct wfm_scene_ops wfm_scene_ops_t
The composer's own entry points, as a table its state starts with.
enum wfm_seed_advance_t
Per-repeat seed policy for a looped/continuous stream.
enum wfm_snr_mode_t
What a source's snr is measured against.

Public Attributes

Type Name
const char dp_wfm_why_count_derived
The reason dp_wfm_scene_error() gives a count beside a segment whose sources set its length (dp_wfm_segment_sets_length() ) exported so the wfmgen CLI can name its flag beside it.
const char dp_wfm_why_dsss_cont_no_data_code
The reasons dp_wfm_source_error() gives a dsss source missing a code (doppler#1696): a burst whose frame has no data_code to spread it, a burst with neither a preamble nor a frame, and a continuous stream with no data_code. Exported so a test or a face can hold a refusal to its reason by identity.
const char dp_wfm_why_dsss_cont_rate
The reason dp_wfm_scene_error() gives a continuous dsss source whose chip rate is below its symbol rate exported so the wfmgen CLI can name the values beside it, by identity.
const char dp_wfm_why_dsss_empty
The reasons dp_wfm_source_error() gives a dsss source missing a code (doppler#1696): a burst whose frame has no data_code to spread it, a burst with neither a preamble nor a frame, and a continuous stream with no data_code. Exported so a test or a face can hold a refusal to its reason by identity.
const char dp_wfm_why_dsss_frame_no_data_code
The reasons dp_wfm_source_error() gives a dsss source missing a code (doppler#1696): a burst whose frame has no data_code to spread it, a burst with neither a preamble nor a frame, and a continuous stream with no data_code. Exported so a test or a face can hold a refusal to its reason by identity.
const char dp_wfm_why_pn_poly
The reason dp_wfm_source_error() gives for apn_poly wider than its register exported so a face that knows the values (the wfmgen CLI) can name them beside it, by identity rather than by matching text.
const char dp_wfm_why_retired_bits
The reason dp_wfm_source_error() gives forretired_bits set: Python's retiredbits= (andpayload= ,pattern= ), named once. The CLI's and a scene's RETIRED tables say the same in their own spelling (doppler#1718).
const char dp_wfm_why_retired_crc
The reasons dp_wfm_source_error() gives forretired_sync andretired_crc set.
const char dp_wfm_why_retired_sync
The reasons dp_wfm_source_error() gives forretired_sync andretired_crc set.
const char dp_wfm_why_snr_and_level
The reason dp_wfm_scene_error() gives a segment with a source that sets bothsnr andlevel beside a noise floor (dp_wfm_segment_snr_and_level() ). Static, like every reason here: it names the rule, not the segment; the offending source's index is the predicate's return value (doppler#2834).

Public Functions

Type Name
wfm_render_t * dp_wfm_compose_build_render (const wfm_source_t * src, double fs, size_t on_len, double freq, double snr, double f_end, double doppler, double doppler_rate, unsigned epoch, int seed_advance, size_t instance, dp_doppler_channel_state_t * borrow)
Build a source's renderer — dp_wfm_compose_build_synth plus the clock-Doppler channel the source declares, if it declares one.
dp_wfm_synth_state_t * dp_wfm_compose_build_synth (const wfm_source_t * src, double fs, size_t on_len, double freq, double snr, double f_end, unsigned epoch, int seed_advance, size_t instance)
Construct + configure the synth for one resolved source.
dp_wfm_compose_state_t * dp_wfm_compose_create (const wfm_segment_t * segs, size_t n_segs, int repeat, int continuous)
Build a composer over a copy of segs .
dp_wfm_compose_state_t * dp_wfm_compose_create_why (const wfm_segment_t * segs, size_t n_segs, int repeat, int continuous, const char ** why)
dp_wfm_compose_create() , able to say why the scene was refused.
void dp_wfm_compose_destroy (dp_wfm_compose_state_t * state)
Destroy a composer and its active synth.
size_t dp_wfm_compose_draws (const wfm_segment_t * segs, size_t n_segs, wfm_draw_t * out, size_t cap)
Replay the (epoch 0) instance timeline AND its drawn source values.
size_t dp_wfm_compose_execute (dp_wfm_compose_state_t * state, float _Complex * out, size_t max)
Emit up to max samples of the composed stream.
size_t dp_wfm_compose_execute_rate (dp_wfm_compose_state_t * state, float _Complex * out, size_t max, double * fs)
Emit up to max samples, all at ONE sample rate, and say which.
dp_wfm_compose_state_t * dp_wfm_compose_from_file (const char * path)
Build a composer from a JSON spec file.
dp_wfm_compose_state_t * dp_wfm_compose_from_file_why (const char * path, const char ** why)
dp_wfm_compose_from_file , able to say why a scene was refused.
dp_wfm_compose_state_t * dp_wfm_compose_from_json (const char * json)
Build a composer from a JSON spec string (for from-file).
dp_wfm_compose_state_t * dp_wfm_compose_from_json_at (const char * json, const char * base, const char ** why)
dp_wfm_compose_from_json_why() , reading a scene that lives inbase .
dp_wfm_compose_state_t * dp_wfm_compose_from_json_data (const char * json, const char * base, const char * data_file, const char ** why)
dp_wfm_compose_from_json_at() , replaying a record by its data.
dp_wfm_compose_state_t * dp_wfm_compose_from_json_why (const char * json, const char ** why)
The same, but able to say why a FRAME was refused.
dp_doppler_channel_state_t * dp_wfm_compose_persist_channel (const wfm_source_t * src, double fs, double doppler, double doppler_rate, dp_doppler_channel_state_t ** slot)
The PERSIST channel for one (segment, source) slot, created on first use, or NULL when the source does not persist.
int dp_wfm_compose_seed_advance (const dp_wfm_compose_state_t * state)
The composer's current seed-advance mode (a wfm_seed_advance_t ).
const wfm_segment_t * dp_wfm_compose_segments (const dp_wfm_compose_state_t * state, size_t * n_out, int * repeat, int * continuous)
Borrow the composer's stored segment list (for record / SigMF).
void dp_wfm_compose_set_data_pacing (dp_wfm_compose_state_t * state, wfm_data_pacing_t pacing)
Pace a composer's data sources: WFM_DATA_PACED under --realtime .
void dp_wfm_compose_set_seed_advance (dp_wfm_compose_state_t * state, int mode)
Choose how the seed advances on each repeat of a looped/continuous stream (a wfm_seed_advance_t ):
size_t dp_wfm_compose_spans (const wfm_segment_t * segs, size_t n_segs, wfm_span_t * out, size_t cap)
Replay the (epoch 0) instance timeline of a resolved segment list.
char * dp_wfm_draws_json (const wfm_segment_t * segs, size_t n_segs)
The same rows dp_wfm_compose_draws() reports, as a JSON array.
wfm_frame_desc_t * dp_wfm_frame_copy (const wfm_frame_desc_t * d)
Deep-copy a description: the struct and each literal field's bits.
void dp_wfm_frame_free (wfm_frame_desc_t * d)
Free a description returned by dp_wfm_frame_from_json() , bits and all. NULL is a no-op.
wfm_frame_desc_t * dp_wfm_frame_from_json (const char * json, const char ** why)
Read a frame description from its JSON form.
wfm_frame_desc_t * dp_wfm_frame_refuse_text (const char * text, const char ** why)
Refuse text for a source's frame= : it takes a description.
char * dp_wfm_frame_to_json (const wfm_frame_desc_t * d)
Write a description as its JSON frame object, the text dp_wfm_frame_from_json() reads back.
const char * dp_wfm_framing_flags_error (const wfm_source_t * src)
Why --sync /--crc /--acq-code cannot frame this source, or NULL.
const char * dp_wfm_ofdm_fs_error (const wfm_source_t * src, double fs)
The rules of an ofdm source that need the segment's sample rate:fs is an integer multiple ofbandwidth (the oversamplingM , done by a larger transform),M is at most 128,window is within 80M samples, and a frame with itsgap is at most 2^24 samples. Asked bydp_wfm_scene_error() , so every face says the same sentence.
void dp_wfm_render_destroy (wfm_render_t * r)
Free a renderer and everything it owns. NULL-safe.
wfm_render_t * dp_wfm_render_from_feed (const wfm_source_t * src, double fs, double doppler, double doppler_rate, dp_doppler_channel_state_t * borrow, size_t delay, size_t on, wfm_feed_fn feed, void * feed_ctx)
A renderer whose input is a caller-supplied feed, not a live synth.
void dp_wfm_render_noise_steps (wfm_render_t * r, float _Complex * dst, size_t n)
Pull n samples of the source's NOISE FLOOR only, through the same channel.
void dp_wfm_render_set_input_timeline (wfm_render_t * r, size_t delay, size_t on)
Tell a Doppler renderer where its INPUT's phases fall.
void dp_wfm_render_steps (wfm_render_t * r, float _Complex * dst, size_t n)
Pull exactly n samples fromr , through its channel if any.
int dp_wfm_resolve_noise (wfm_segment_t * segs, size_t n)
Resolve a segment list's noise model in place (Phase 4b).
const char * dp_wfm_scene_error (const wfm_segment_t * segs, size_t n_segs, int repeat, int continuous)
Why a scene cannot be composed, or NULL: the one validator.
double dp_wfm_segment_fs (const wfm_segment_t * seg, double fs)
The rate a segment renders at: the get_fn behind a Segment'sfs , so a segment whose ofdm sources set its rate reads it.
int dp_wfm_segment_sets_length (const wfm_segment_t * seg)
Whether a segment's sources SET its on-time, so its num_samples is derived and a count given beside them refused.
int dp_wfm_segment_snr_and_level (const wfm_segment_t * g)
The source in a segment that sets both snr and alevel where only one is allowed, or -1 when there is none.
double dp_wfm_snr_over_fs (int snr_mode, int type, int sps, size_t sf, double sym_span, double snr)
SNR (dB) referred to fs, from a source's snr/snr_mode/sps/type.
size_t dp_wfm_source_acq_code_bits (const wfm_source_t * src, double fs, uint8_t * out, size_t max)
The bits a source's sequence field reads as: a literal's own, or the run its generator renders.
int dp_wfm_source_attach_dsss (dp_wfm_synth_state_t * syn, const wfm_source_t * src, double fs)
Attach a dsss source's data to a freshly-created synth.
int dp_wfm_source_attach_frame (dp_wfm_synth_state_t * syn, const wfm_source_t * src)
Attach an unspread source's bit pattern, framed or not.
int dp_wfm_source_attach_ofdm (dp_wfm_synth_state_t * syn, const wfm_source_t * src, double fs, uint32_t seed)
Install an ofdm source's frame renderer and its data pull on a synth created with type WFM_SYNTH_FRAMES: the PPDU of each frame of the data source, built throughwlan from the source's constellation and code rate (orwlan ),window ,mac ,gap and the oversamplingfs / bandwidth . A no-op for any other type.
double dp_wfm_source_bandwidth (const wfm_source_t * src)
The channel bandwidth of an ofdm source, Hz: its bandwidth , or the preset's 20e6 when that is 0 (a C source that skipped the defaults).
size_t dp_wfm_source_bits_refuse_text (const char * text, uint8_t * out, size_t max_out, const char ** why)
Refuse text for a source's bit field: an object takes bits.
int dp_wfm_source_code_rate (const wfm_source_t * src, double fs)
The code-rate index an ofdm source renders with, never auto : theget_fn behind a Synth'scode_rate , asdp_wfm_source_constellation() is for its constellation.
int dp_wfm_source_common_frame (const wfm_source_t * src, const wfm_seq_t * sync, int crc, wfm_frame_desc_t * d)
The common frame as a description: [preamble x reps | sync | data | crc] , built by the ONE function that builds it.
int dp_wfm_source_constellation (const wfm_source_t * src, double fs)
The constellation index an ofdm source renders with, at fs: theget_fn behind a Synth'sconstellation , so it reads the resolved value (the pairwlan names, or the default's), neverauto .
size_t dp_wfm_source_crc_refuse_text (const char * text, uint8_t * out, size_t max_out, const char ** why)
Refuse text for the retired crc= : a CRC is a stage of the frame description.
double dp_wfm_source_create_snr (const wfm_source_t * src, double fs, double snr, int * snr_mode)
Resolve a source's (snr, snr_mode) into the pair to hand to dp_wfm_synth_create() .
size_t dp_wfm_source_data_bits (const wfm_source_t * src, double fs, uint8_t * out, size_t max)
As dp_wfm_source_acq_code_bits() , fordata .
size_t dp_wfm_source_data_code_bits (const wfm_source_t * src, double fs, uint8_t * out, size_t max)
As dp_wfm_source_acq_code_bits() , fordata_code .
uint64_t dp_wfm_source_data_frames (const wfm_source_t * src)
Frames a FINITE data source makes, ceil(bits / LEN) ; 0 for a stream or none. On continuous dsss, which has no frame, its bits.
int dp_wfm_source_data_is_stream (const wfm_source_t * src)
Whether a source's data is a stream: data_from_file is- .
uint64_t dp_wfm_source_data_samples (const wfm_source_t * src, double fs, uint64_t frames)
Samples the first frames frames of a source's data occupy; 0 with no data.
double dp_wfm_source_dsss_cps (const wfm_source_t * src, double fs)
Chips per data symbol of a CONTINUOUS dsss source at fs .
size_t dp_wfm_source_dsss_nchips (const wfm_source_t * src)
Chips one DSSS BURST from this source occupies, description and all.
const char * dp_wfm_source_error (const wfm_source_t * src)
NULL when this source can be built; else why not, as a sentence.
size_t dp_wfm_source_fill_bits (const wfm_source_t * src, double fs, uint8_t * out, size_t max)
As dp_wfm_source_acq_code_bits() , forfill .
const char * dp_wfm_source_frame_error (const wfm_source_t * src)
NULL when this source's frame fields can be honoured; else why not.
double dp_wfm_source_fs (const wfm_source_t * src, double fs)
The rate an ofdm source renders at: its bandwidth when fs is at a face's default, elsefs . Thefs_get_fn behind a Synth'sfs , and the per-source ruledp_wfm_source_ofdm_defaults() anddp_wfm_segment_fs() apply.
int dp_wfm_source_has_frame (const wfm_source_t * src)
Non-zero when this source describes a FRAME.
int dp_wfm_source_mac (const wfm_source_t * src, double fs)
The MAC mode an ofdm source renders with: auto readsfcs (dp_wlan_mac_resolve()). Theget_fn behind a Synth'smac .
size_t dp_wfm_source_mac_header_bits (const wfm_source_t * src, double fs, uint8_t * out, size_t max)
As dp_wfm_source_acq_code_bits() , formac_header .
const char * dp_wfm_source_ofdm_defaults (const wfm_source_t * src, double fs, wfm_source_t * out, double * fs_out)
An ofdm source with its zero-config defaults filled in, and the rate it renders at: the one place those defaults are decided.
unsigned dp_wfm_source_oversample (const wfm_source_t * src, double fs, const char ** why)
The oversampling M = fs / bandwidth of an ofdm source, 1 toWLAN_OVERSAMPLE_MAX , or 0 with the reason it has none.
const char * dp_wfm_source_rate_why (const wfm_source_t * src)
Why a source's rate fields would be refused when it builds, by the build's own resolver, or NULL: the one check every setter of a source's rate and type writes through.
const char * dp_wfm_source_set_bandwidth (wfm_source_t * src, double bandwidth)
Set a source's bandwidth : theset_fn behind a Synth's and a Segment'sbandwidth .
const char * dp_wfm_source_set_code_rate (wfm_source_t * src, int code_rate)
Set an ofdm source's code_rate so its rate pair stays whole: the set_fn behind a Synth's and a Segment'scode_rate , the mirror ofdp_wfm_source_set_constellation() , whose table is the rule.
const char * dp_wfm_source_set_constellation (wfm_source_t * src, int constellation)
Set an ofdm source's constellation so its rate pair stays whole: the set_fn behind a Synth's and a Segment'sconstellation .
const char * dp_wfm_source_set_type (wfm_source_t * src, int type)
Set a source's type : theset_fn behind a Synth's and a Segment'stype .
const char * dp_wfm_source_set_wlan (wfm_source_t * src, int wlan)
Set an ofdm source's wlan , the rate's second spelling: theset_fn behind a Synth's and a Segment'swlan .
size_t dp_wfm_source_sync_refuse_text (const char * text, uint8_t * out, size_t max_out, const char ** why)
Refuse text for the retired sync= : a sync word is a field of the frame description.
int dp_wfm_source_synth_type (const wfm_source_t * src)
The synth type to create this source with.
const char * dp_wfm_source_to_synth_error (const wfm_source_t * src, double fs)
Why dp_wfm_source_to_synth() refused this source, or NULL.
size_t dp_wfm_source_window (const wfm_source_t * src, double fs)
The window an ofdm source renders with, in samples at the output rate: the count it holds, or the standard's for an unset one.
double dp_wfm_spec_headroom (const char * json)
The top-level headroom (dB) from a spec JSON, or 0 if absent.
char * dp_wfm_spec_template_json (void)
A ready-to-edit example spec in the canonical from-file schema.
char * dp_wfm_spec_to_json (const wfm_segment_t * segs, size_t n_segs, int repeat, int continuous, int seed_advance, double headroom)
Serialise a spec to a JSON string (for record).
int dp_wfm_synth_attach_data (dp_wfm_synth_state_t * syn, const wfm_frame_desc_t * d, const wfm_frame_ops_t * ops, wfm_data_src_t * src, wfm_data_pacing_t pacing, int modulation)
Drive a type=bits synth from a frame whose payload is a data source.
const wfm_data_src_t * dp_wfm_synth_data_source (const dp_wfm_synth_state_t * syn)
The data source a synth pulls from (dp_wfm_synth_attach_data), or NULL: its stats are the run's truth for scoring.
void dp_wfm_synth_set_data_pacing (dp_wfm_synth_state_t * syn, wfm_data_pacing_t pacing)
Pace a synth's data source: WFM_DATA_PACED for --realtime .

Public Static Functions

Type Name
double dp_wfm_scene_fs (const wfm_segment_t * segs, size_t n_segs)
The ONE answer to "what is this stream's sample rate": the fs every segment shares, or 0.0 when they differ.
const wfm_segment_t * dp_wfm_scene_segments (const dp_wfm_compose_state_t * scene, size_t * n_out)
dp_wfm_compose_segments() for a caller that does not link the composer: dispatched through the state's own wfm_scene_ops_t.

Macros

Type Name
define WFM_NUM_SAMPLES_PLAIN ((size\_t)1024)
A plain segment's on-time when its num_samples is 0 and no source sets one: what--count , a scene andSegment default to.
define WFM_SEGMENT_FS_DEFAULT 1.0
A segment's sample rate when none is given, Hz: 1.0, every frequency normalised. The manifest default of wfm_segment_t.fs (WFM_SEGMENT_DEFAULTS ), named so the ofdm rule reads a name: for an ofdm source it reads as unset and becomes the bandwidth (dp_wfm_source_ofdm_defaults() ). A test holds the two equal.
define WFM_WINDOW_UNSET SIZE\_MAX
The window of an ofdm source that nobody set: the 100 ns default,2 * fs / bandwidth samples.

Detailed Description

Sequences a list of segments — each one a synth configuration plus an on-time and a trailing off-time gap — into a single IQ stream, optionally repeating the whole sequence or running forever. The composer owns one synth at a time (the active segment) and reuses the Phase-A engine verbatim, so every waveform type / SNR mode / MLS behaviour is identical to the single-waveform path; a one-segment spec is byte-identical to calling synth directly.

Lifecycle: dp_wfm_compose_create -> dp_wfm_compose_execute* -> dp_wfm_compose_destroy

wfm_source_t tone = {.type = 0, .freq = 1e5, .snr = 100.0};
wfm_source_t qpsk = {.type = 4, .sps = 8, .snr = 9.0};
wfm_segment_t segs[2] = {
    {.sources = &tone, .n_sources = 1, .fs = 1e6,
     .num_samples = 1000, .off_samples = 500},          // tone, then a gap
    {.sources = &qpsk, .n_sources = 1, .fs = 1e6,
     .num_samples = 4096, .off_samples = 0},            // qpsk
};
dp_wfm_compose_state_t *c = dp_wfm_compose_create(segs, 2, 0, 0);
float _Complex buf[4096];
size_t n;
while ((n = dp_wfm_compose_execute(c, buf, 4096)) > 0) { ... }
dp_wfm_compose_destroy(c);

Public Types Documentation

typedef dp_wfm_compose_state_t

typedef struct wfm_compose_state dp_wfm_compose_state_t;

Opaque composer state.


enum wfm__compose_8h_1abc5c98fcc1211af2b80116dd6e0a035d

Per-field "draw uniformly each repeat" flags ( ranged bitmask).

enum wfm__compose_8h_1abc5c98fcc1211af2b80116dd6e0a035d {
    WFM_RANGE_FREQ = 1u << 0,
    WFM_RANGE_SNR = 1u << 1,
    WFM_RANGE_LEVEL = 1u << 2,
    WFM_RANGE_FEND = 1u << 3,
    WFM_RANGE_NUM_SAMPLES = 1u << 4,
    WFM_RANGE_OFF_SAMPLES = 1u << 5,
    WFM_RANGE_DELAY_SAMPLES = 1u << 6,
    WFM_RANGE_DOPPLER = 1u << 7,
    WFM_RANGE_DOPPLER_RATE = 1u << 8
};

A scalar field is a constant; a ranged field carries a [lo, hi] span (the scalar holds lo, a companion *_hi holds hi) and is redrawn uniformly in [lo, hi] at the start of every repeat (composer epoch) — so a looped / continuous stream can vary Doppler (freq), arrival jitter (off_samples), etc. burst-to-burst while staying reproducible: the draw is a deterministic hash of the source seed, the epoch, the segment/source index, and the field, so --record stores the span (not a drawn value) and --from-file replays the same sequence byte-for-byte. Bits 0–3 and 7–8 live on wfm_source_t.ranged; bits 4–6 on wfm_segment_t.ranged.


enum wfm_bitmod_t

How a WFM_SYNTH_BITS source maps its payload to symbols.

enum wfm_bitmod_t {
    WFM_BITMOD_NONE = 0,
    WFM_BITMOD_BPSK = 1,
    WFM_BITMOD_QPSK = 2
};

Order IS the wire value; BITMOD_NAMES[] and the [[enum]] bitmod manifest are held to this by make lint-wfm-enum-tables.


enum wfm_doppler_lifetime_t

When a source's Doppler channel restarts.

enum wfm_doppler_lifetime_t {
    WFM_DOPPLER_PER_INSTANCE = 0,
    WFM_DOPPLER_PERSIST = 1
};

Neither is a superset of the other, so it is declared rather than defaulted into an argument:

  • PER_INSTANCE (default) restarts the geometry for every burst instance, which is the repeated-trial shape — every burst sees the same pass, and it composes with the per-instance re-draw of a ranged doppler.
  • PERSIST carries one emitter's motion across every REPEAT INSTANCE of its segment, and across the gaps between them, so burst k sees where the pass has got to. It is the only lifetime under which doppler_rate means anything over a multi-burst scene.

The channel is keyed by (segment, source), because that is the only source identity the composer has — a position. So a PERSIST source persists over its own segment's instances; two DIFFERENT segments each get their own pass, even where a reader might call them the same emitter. Sharing one across segments needs a declared source id, which nothing in the scene format carries yet; gh-942 says as much ("no per-source identity that survives it ... the repeats/epoch machinery is where one would hang").


typedef wfm_feed_fn

Where a channel renderer's INPUT comes from, when it is not a synth.

typedef void(* wfm_feed_fn) (void *ctx, float _Complex *dst, size_t n, int signal);

Called with the next n input samples wanted, signal non-zero for ON samples and zero for noise-only ones (the delay and the gap), in INPUT order: the ON calls together cover the burst exactly once, front to back.

Parameters:

  • ctx The pointer given to dp_wfm_render_from_feed().
  • dst Write n samples here.
  • n Samples wanted.
  • signal Non-zero: ON samples. Zero: noise-only.

typedef wfm_render_t

One source's renderer: its synth, plus its Doppler channel.

typedef struct wfm_render wfm_render_t;


typedef wfm_scene_ops_t

The composer's own entry points, as a table its state starts with.

typedef struct wfm_scene_ops wfm_scene_ops_t;

Every composer state's first member points at one of these, set at create. A component that holds a composer but does not link the composer engine (the SigMF writer, doppler#2564) reads the segments through it: dp_wfm_scene_segments() calls the composer's OWN dp_wfm_compose_segments(), so the code that runs is the code that built the scene, even when the two live in different extension modules.


enum wfm_seed_advance_t

Per-repeat seed policy for a looped/continuous stream.

enum wfm_seed_advance_t {
    WFM_SEED_ADVANCE_NONE = 0,
    WFM_SEED_ADVANCE_NOISE = 1,
    WFM_SEED_ADVANCE_ALL = 2
};

A source's single seed feeds two RNGs: the PN LFSR (spreading code and data bits — one register) and the AWGN generator. The clean cut is therefore signal (code+data) vs. noise, exposed as an ordered, cumulative level.


enum wfm_snr_mode_t

What a source's snr is measured against.

enum wfm_snr_mode_t {
    WFM_SNR_AUTO = 0,
    WFM_SNR_FS = 1,
    WFM_SNR_EBNO = 2,
    WFM_SNR_ESNO = 3
};

The scale a number in dB is quoted on is not a detail a caller can infer, and it changes the noise by 10log10(sps) between fs and esno. Naming the modes is what lets a downstream write the mode it means instead of a literal whose meaning lives in a comment. Order IS the wire value — the [[enum]] snr_mode manifest and MODE_NAMES[] in wfm_names.h are held to this by make lint-wfm-enum-tables.


Public Attributes Documentation

variable dp_wfm_why_count_derived

The reason dp_wfm_scene_error() gives a count beside a segment whose sources set its length (dp_wfm_segment_sets_length() ) exported so the wfmgen CLI can name its flag beside it.

const char dp_wfm_why_count_derived[];


variable dp_wfm_why_dsss_cont_no_data_code

The reasons dp_wfm_source_error() gives a dsss source missing a code (doppler#1696): a burst whose frame has no data_code to spread it, a burst with neither a preamble nor a frame, and a continuous stream with no data_code. Exported so a test or a face can hold a refusal to its reason by identity.

const char dp_wfm_why_dsss_cont_no_data_code[];


variable dp_wfm_why_dsss_cont_rate

The reason dp_wfm_scene_error() gives a continuous dsss source whose chip rate is below its symbol rate exported so the wfmgen CLI can name the values beside it, by identity.

const char dp_wfm_why_dsss_cont_rate[];


variable dp_wfm_why_dsss_empty

The reasons dp_wfm_source_error() gives a dsss source missing a code (doppler#1696): a burst whose frame has no data_code to spread it, a burst with neither a preamble nor a frame, and a continuous stream with no data_code. Exported so a test or a face can hold a refusal to its reason by identity.

const char dp_wfm_why_dsss_empty[];


variable dp_wfm_why_dsss_frame_no_data_code

The reasons dp_wfm_source_error() gives a dsss source missing a code (doppler#1696): a burst whose frame has no data_code to spread it, a burst with neither a preamble nor a frame, and a continuous stream with no data_code. Exported so a test or a face can hold a refusal to its reason by identity.

const char dp_wfm_why_dsss_frame_no_data_code[];


variable dp_wfm_why_pn_poly

The reason dp_wfm_source_error() gives for apn_poly wider than its register exported so a face that knows the values (the wfmgen CLI) can name them beside it, by identity rather than by matching text.

const char dp_wfm_why_pn_poly[];


variable dp_wfm_why_retired_bits

The reason dp_wfm_source_error() gives forretired_bits set: Python's retiredbits= (andpayload= ,pattern= ), named once. The CLI's and a scene's RETIRED tables say the same in their own spelling (doppler#1718).

const char dp_wfm_why_retired_bits[];


variable dp_wfm_why_retired_crc

The reasons dp_wfm_source_error() gives forretired_sync andretired_crc set.

const char dp_wfm_why_retired_crc[];

One sentence each, naming frame=; the CLI and a scene say the same in their own spelling. Exposed so a test can pin the wording once.


variable dp_wfm_why_retired_sync

The reasons dp_wfm_source_error() gives forretired_sync andretired_crc set.

const char dp_wfm_why_retired_sync[];

One sentence each, naming frame=; the CLI and a scene say the same in their own spelling. Exposed so a test can pin the wording once.


variable dp_wfm_why_snr_and_level

The reason dp_wfm_scene_error() gives a segment with a source that sets bothsnr andlevel beside a noise floor (dp_wfm_segment_snr_and_level() ). Static, like every reason here: it names the rule, not the segment; the offending source's index is the predicate's return value (doppler#2834).

const char dp_wfm_why_snr_and_level[];


Public Functions Documentation

function dp_wfm_compose_build_render

Build a source's renderer — dp_wfm_compose_build_synth plus the clock-Doppler channel the source declares, if it declares one.

wfm_render_t * dp_wfm_compose_build_render (
    const wfm_source_t * src,
    double fs,
    size_t on_len,
    double freq,
    double snr,
    double f_end,
    double doppler,
    double doppler_rate,
    unsigned epoch,
    int seed_advance,
    size_t instance,
    dp_doppler_channel_state_t * borrow
) 

THE pull path. Both faces go through dp_wfm_render_steps() rather than calling dp_wfm_synth_steps() themselves, because a Doppler channel is a RESAMPLER: it consumes about n*(1+d) inputs per n outputs, so "pull k, get k" only holds if something keeps the remainder. Two implementations that agreed today would drift the moment either grew a holdover the other did not.

A source with doppler == 0 && doppler_rate == 0 gets no channel and dp_wfm_render_steps() is then literally dp_wfm_synth_steps(), so every scene that does not ask for Doppler renders through exactly the path it always did — byte-identical, not merely equivalent.

doppler/doppler_rate arrive ranged-resolved, like freq/snr/f_end.

borrow is the channel a WFM_DOPPLER_PERSIST source keeps ACROSS segments: the composer owns it for the life of the scene and passes it in here, so the renderer uses it without adopting it and the geometry does not restart when the synth is torn down at a segment boundary. NULL means the ordinary case — the renderer creates and owns a channel if the source declares Doppler, and destroys it with itself.

Parameters:

  • src The source.
  • fs Segment sample rate, Hz.
  • on_len Segment on-time in samples (as dp_wfm_compose_build_synth()).
  • freq Drawn carrier / sweep-start frequency, Hz.
  • snr Drawn SNR, dB.
  • f_end Drawn chirp end frequency, Hz.
  • doppler Drawn clock Doppler, ppm.
  • doppler_rate Drawn Doppler rate, ppm/s.
  • epoch Composer repeat epoch.
  • seed_advance A wfm_seed_advance_t.
  • instance The segment's repeats instance, 0-based.
  • borrow A scene-owned PERSIST channel, or NULL.

Returns:

A heap renderer (caller dp_wfm_render_destroy()s it), or NULL when the synth does not build (as dp_wfm_compose_build_synth()) or the channel cannot be created.


function dp_wfm_compose_build_synth

Construct + configure the synth for one resolved source.

dp_wfm_synth_state_t * dp_wfm_compose_build_synth (
    const wfm_source_t * src,
    double fs,
    size_t on_len,
    double freq,
    double snr,
    double f_end,
    unsigned epoch,
    int seed_advance,
    size_t instance
) 

THE single synth-construction path (create + chirp-span pin + bits/symbols/RRC attach + per-repeat NOISE reseed) shared by the streaming composer and the Plan stimulus cache, so a cached per-source render is byte-identical to the composed one. freq/snr/f_end are passed already ranged-resolved by the caller; on_len pins a chirp's sweep to the on-time; epoch/seed_advance (a wfm_seed_advance_t) drive the per-repeat seed policy — epoch == 0 yields the unmodified seed. instance is the segment's repeats counter (0-based): a non-zero instance always reseeds the AWGN (fresh noise per burst instance, signal fixed, regardless of seed_advance); instance 0 is byte-identical to the pre-repeats behaviour.

Parameters:

  • src The source (resolved: dp_wfm_resolve_noise() applied).
  • fs Segment sample rate, Hz.
  • on_len Segment on-time in samples; a chirp sweeps over it unless the source declares its own span.
  • freq Drawn carrier / sweep-start frequency, Hz.
  • snr Drawn SNR, dB, in the source's own snr_mode.
  • f_end Drawn chirp end frequency, Hz.
  • epoch Composer repeat epoch (0 = first pass).
  • seed_advance A wfm_seed_advance_t: ALL adds epoch to the whole seed; NOISE reseeds only the AWGN with seed + epoch.
  • instance The segment's repeats instance, 0-based.

Returns:

A heap synth (caller dp_wfm_synth_destroy()s it), or NULL on failure allocation, or a frame / dsss geometry that does not build.


function dp_wfm_compose_create

Build a composer over a copy of segs .

dp_wfm_compose_state_t * dp_wfm_compose_create (
    const wfm_segment_t * segs,
    size_t n_segs,
    int repeat,
    int continuous
) 

Parameters:

  • segs Segment list (copied; caller keeps ownership).
  • n_segs Number of segments (>= 1).
  • repeat Non-zero: loop the whole sequence after the last segment.
  • continuous Non-zero: never finish (implies repeat); execute always returns max.

Returns:

Heap state, or NULL on bad args / allocation / synth failure.

Note:

Caller must dp_wfm_compose_destroy() when done.


function dp_wfm_compose_create_why

dp_wfm_compose_create() , able to say why the scene was refused.

dp_wfm_compose_state_t * dp_wfm_compose_create_why (
    const wfm_segment_t * segs,
    size_t n_segs,
    int repeat,
    int continuous,
    const char ** why
) 

The scene is asked dp_wfm_scene_error() before anything is built, and its sentence is what why receives the same sentence the wfmgen CLI, a scene read by dp_wfm_compose_from_json_why() and the standalone Synth report, because it is the same validator. It is the create the generated Composer([...]) calls (just-makeit's create_why), so a refused composer raises ValueError(<the reason>).

Parameters:

Returns:

Heap state, or NULL as for dp_wfm_compose_create().

wfm_source_t  src = { .type = WFM_SYNTH_DSSS, .sps = 2 };   // no codes
wfm_segment_t seg = { .sources = &src, .n_sources = 1, .fs = 1e6,
                      .num_samples = 64 };
const char   *why = NULL;
dp_wfm_compose_state_t *c = dp_wfm_compose_create_why (&seg, 1, 0, 0, &why);
if (c != NULL || why != dp_wfm_why_dsss_empty)   // refused, and says why
  return 1;

function dp_wfm_compose_destroy

Destroy a composer and its active synth.

void dp_wfm_compose_destroy (
    dp_wfm_compose_state_t * state
) 

Parameters:

  • state May be NULL.

function dp_wfm_compose_draws

Replay the (epoch 0) instance timeline AND its drawn source values.

size_t dp_wfm_compose_draws (
    const wfm_segment_t * segs,
    size_t n_segs,
    wfm_draw_t * out,
    size_t cap
) 

Same size-then-fill protocol as dp_wfm_compose_spans(): call once with cap 0 to size, then again with a buffer. Emits one row per SOURCE per instance, in stream order, because that is the granularity a per-source annotation or a scoring pipeline needs. Pass the RESOLVED segments (dp_wfm_compose_segments() on a live composer) so intrinsic on-times are already folded in.

The rows are produced by the same dp_wfm_draw_segment()/dp_wfm_draw_source() calls the renderer resolves through, so a field added to the draw reaches both by construction rather than by a reviewer noticing.

Parameters:

  • segs Resolved segment array.
  • n_segs Segment count.
  • out Row buffer (may be NULL when cap is 0).
  • cap Capacity of out in rows.

Returns:

Total rows in one pass of the spec (sum of n_sources over instances), regardless of cap.


function dp_wfm_compose_execute

Emit up to max samples of the composed stream.

size_t dp_wfm_compose_execute (
    dp_wfm_compose_state_t * state,
    float _Complex * out,
    size_t max
) 

Segments run back to back, each as delay + on-time + trailing gap per repeats instance; a segment whose synth fails to build renders as its gaps only. Segments with different fs are concatenated without a rate marker: use dp_wfm_compose_execute_rate() to learn each block's rate.

Parameters:

  • state The composer; NULL writes nothing and returns 0.
  • out Destination for up to max complex samples.
  • max Capacity of out, in samples.

Returns:

Number of samples written: < max (or 0) signals the sequence finished (never, when continuous).


function dp_wfm_compose_execute_rate

Emit up to max samples, all at ONE sample rate, and say which.

size_t dp_wfm_compose_execute_rate (
    dp_wfm_compose_state_t * state,
    float _Complex * out,
    size_t max,
    double * fs
) 

dp_wfm_compose_execute() for an output that states a rate per block: it stops early where the next segment's fs differs from the samples already written, so every block it returns has one rate. A scene whose segments share an fs never stops early, and its samples are the same, byte for byte, as dp_wfm_compose_execute()'s. A short return therefore does NOT mean the scene finished; 0 does.

wfm_source_t  src     = { .type = WFM_SYNTH_TONE, .snr = 100.0 };
wfm_segment_t segs[2] = {
  { .sources = &src, .n_sources = 1, .fs = 6e6, .num_samples = 8 },
  { .sources = &src, .n_sources = 1, .fs = 2e6, .num_samples = 8 },
};
dp_wfm_compose_state_t *c = dp_wfm_compose_create (segs, 2, 0, 0);
float _Complex buf[64];
double         fs = 0.0;
size_t a = dp_wfm_compose_execute_rate (c, buf, 64, &fs); // 8 at 6e6
int    ok = a == 8 && fs == 6e6;
size_t b = dp_wfm_compose_execute_rate (c, buf, 64, &fs); // 8 at 2e6
ok = ok && b == 8 && fs == 2e6;
ok = ok && dp_wfm_compose_execute_rate (c, buf, 64, &fs) == 0;
dp_wfm_compose_destroy (c);
return ok ? 0 : 1;

Parameters:

  • state the composer; NULL writes nothing and returns 0.
  • out destination, max samples.
  • max capacity of out.
  • fs receives the rate of the samples written (left untouched when none are).

Returns:

samples written; 0 when the scene has finished.


function dp_wfm_compose_from_file

Build a composer from a JSON spec file.

dp_wfm_compose_state_t * dp_wfm_compose_from_file (
    const char * path
) 

dp_wfm_compose_from_file_why with no reason channel. A relative data_from_file in the scene resolves against the scene file's own directory.

Parameters:

  • path The spec file.

Returns:

Composer state (caller dp_wfm_compose_destroy()s it), or NULL on read/parse error or a refused scene.


function dp_wfm_compose_from_file_why

dp_wfm_compose_from_file , able to say why a scene was refused.

dp_wfm_compose_state_t * dp_wfm_compose_from_file_why (
    const char * path,
    const char ** why
) 

Reads path and hands its text to dp_wfm_compose_from_json_at with the file's directory as the base, so the reason is that function's: a retired key or a refused frame, named. A file that cannot be opened gives NULL and leaves why untouched.

Parameters:

Returns:

Composer state, or NULL on read/parse error / a refused scene.


function dp_wfm_compose_from_json

Build a composer from a JSON spec string (for from-file).

dp_wfm_compose_state_t * dp_wfm_compose_from_json (
    const char * json
) 

dp_wfm_compose_from_json_why() with no reason channel. A relative data_from_file resolves against the caller's working directory.

Parameters:

  • json The spec text, NUL-terminated (docs/schema/wfmgen.schema.json).

Returns:

Composer state (caller dp_wfm_compose_destroy()s it), or NULL on parse error / bad type / no segments / a refused scene.


function dp_wfm_compose_from_json_at

dp_wfm_compose_from_json_why() , reading a scene that lives inbase .

dp_wfm_compose_state_t * dp_wfm_compose_from_json_at (
    const char * json,
    const char * base,
    const char ** why
) 

A source's relative "data_from_file" is the scene's: it resolves against base, the directory the scene was read from, so a scene and its data move together and replay from anywhere. NULL (as from_json_why passes) leaves a relative path relative to the caller's working directory.

Parameters:

  • json the scene's text.
  • base the scene's directory, or NULL.
  • why optional; receives a static reason for a refusal.

Returns:

the composer, or NULL.

const char *why = NULL;
dp_wfm_compose_state_t *c = dp_wfm_compose_from_json_at (
    "{\"segments\":[{\"type\":\"tone\",\"num_samples\":8}]}", ".",
    &why);
if (!c)
  return 1;
dp_wfm_compose_destroy (c);

function dp_wfm_compose_from_json_data

dp_wfm_compose_from_json_at() , replaying a record by its data.

dp_wfm_compose_state_t * dp_wfm_compose_from_json_data (
    const char * json,
    const char * base,
    const char * data_file,
    const char ** why
) 

A --record stores each data source's truth as "data_sent": the frames, the fill bits padding the last, the idle frames, and for a file or stdin the bits read and their dp_hash64 (payload-data-source.md §4.8). A replay identifies a file by that content, not by its name:

  • a "data_from_file" whose "data_sent" carries a hash is refused unless the file's length in bits and hash are the record's. The reason names the file and both hashes;
  • a "data_from_file": "-" is a run read from stdin, whose octets are gone. It is refused unless data_file names the file that held them, which is then checked the same way. - again is refused: a pipe could only be checked after it had been sent;
  • a data_file that no "-" source takes is refused: a scene carries its own data.

Every check is made before anything is built. A scene with no hash (one written by hand) replays its files unchecked.

Parameters:

  • json the scene's text.
  • base the scene's directory, or NULL.
  • data_file the file a record's stdin is replayed from (--data-from-file given again), as typed: relative to the working directory, not to base. NULL for none.
  • why optional; receives the reason for a refusal. A mismatch's names the numbers, so it is formatted into a thread-local buffer, valid until this thread reads another scene; never freed by the caller.

Returns:

the composer, or NULL.

const char *why = NULL;
dp_wfm_compose_state_t *c = dp_wfm_compose_from_json_data (
    "{\"segments\":[{\"type\":\"bits\",\"data_from_file\":\"-\"}]}",
    NULL, NULL, &why);
if (c || !why) // stdin with no file given again: refused, with a reason
  return 1;

function dp_wfm_compose_from_json_why

The same, but able to say why a FRAME was refused.

dp_wfm_compose_state_t * dp_wfm_compose_from_json_why (
    const char * json,
    const char ** why
) 

A spec is the interface most likely to be hand-written, and a NULL return is the one answer that cannot teach anything. This runs dp_wfm_source_frame_error over every parsed source before handing them to the composer — which asks the same question and would refuse either way — so the reason survives the boundary as a sentence instead of a pointer.

Beyond the frame rule, every dp_wfm_scene_error() rule reports this way, as do the reader's own refusals: an unknown or retired key, a source with no known "type", a Field that does not parse, an "fs" at the top level instead of per segment. Text that is not JSON at all, or has no non-empty "segments" array, is still a bare NULL: those are cJSON's to describe, and duplicating its diagnostics here would be a second opinion about the same text. So, for now, are a segment carrying both "sum" and "type", an empty "sum" array, and an allocation or synth failure: each returns NULL with why left NULL.

Parameters:

  • json the spec.
  • why optional; set to NULL first, then to the reason when the scene is refused. Most reasons are static; two kinds are formatted into a thread-local buffer, valid until this thread reads another scene: one naming the caller's text (an unknown key), and a "data_from_file" that cannot be read or is not the data its record sent. Never freed by the caller. Passing NULL makes this exactly dp_wfm_compose_from_json.

Returns:

Composer state, or NULL on parse error / bad type / no segments / a refused frame.


function dp_wfm_compose_persist_channel

The PERSIST channel for one (segment, source) slot, created on first use, or NULL when the source does not persist.

dp_doppler_channel_state_t * dp_wfm_compose_persist_channel (
    const wfm_source_t * src,
    double fs,
    double doppler,
    double doppler_rate,
    dp_doppler_channel_state_t ** slot
) 

The one place that decides "does this instance borrow a scene-owned channel": the composer and the Plan both call it, so they cannot disagree. NULL for a per_instance source, for a NULL slot, and for an instance that drew no Doppler at all (the channel then does not exist for it).

Parameters:

  • src The source.
  • fs Sample rate, Hz.
  • doppler This instance's drawn Doppler, ppm.
  • doppler_rate This instance's drawn Doppler rate, ppm/s.
  • slot The scene-owned slot for this (segment, source).

Returns:

The slot's channel (created on first use with this instance's geometry, and owned by the slot's holder, not the caller), or NULL as above or when creation fails.


function dp_wfm_compose_seed_advance

The composer's current seed-advance mode (a wfm_seed_advance_t ).

int dp_wfm_compose_seed_advance (
    const dp_wfm_compose_state_t * state
) 

The composer is the SSOT for it: --from-file sets it from the spec and the flag path sets it from --seed-advance, so a serialiser must read it back from here rather than from whichever half happened to supply it.

Parameters:

  • state Compose state (may be NULL → WFM_SEED_ADVANCE_NONE).

Returns:

The mode, a wfm_seed_advance_t value; WFM_SEED_ADVANCE_NONE until dp_wfm_compose_set_seed_advance() sets another.


function dp_wfm_compose_segments

Borrow the composer's stored segment list (for record / SigMF).

const wfm_segment_t * dp_wfm_compose_segments (
    const dp_wfm_compose_state_t * state,
    size_t * n_out,
    int * repeat,
    int * continuous
) 

Each source's data_sent holds what its data source has sent so far in the latest instance, brought up to date by this call, so a record or a SigMF sidecar written after a run carries the run's truth.

Parameters:

  • state the composer; NULL returns NULL with a count of 0 and both flags 0.
  • n_out receives the segment count (may be NULL).
  • repeat receives the repeat flag (may be NULL).
  • continuous receives the continuous flag (may be NULL).

Returns:

Pointer to the internal segments (owned by the composer; valid until dp_wfm_compose_destroy), or NULL for a NULL state.


function dp_wfm_compose_set_data_pacing

Pace a composer's data sources: WFM_DATA_PACED under --realtime .

void dp_wfm_compose_set_data_pacing (
    dp_wfm_compose_state_t * state,
    wfm_data_pacing_t pacing
) 

Applied to the synths already built create builds the first segment's, before this can be called and to every synth built from here on, so a data stream with nothing yet sends an idle frame of fill rather than waiting (dp_wfm_data_frame, the one rule). The default, WFM_DATA_UNPACED, waits.

Parameters:

  • state The composer; NULL is a no-op.
  • pacing WFM_DATA_PACED or WFM_DATA_UNPACED.

function dp_wfm_compose_set_seed_advance

Choose how the seed advances on each repeat of a looped/continuous stream (a wfm_seed_advance_t ):

void dp_wfm_compose_set_seed_advance (
    dp_wfm_compose_state_t * state,
    int mode
) 

  • WFM_SEED_ADVANCE_NONE (default): byte-identical repeats.
  • WFM_SEED_ADVANCE_NOISE: advance only the AWGN seed → a fresh noise realization each pass while the signal (LO / PN code / data / pulse) stays bit-identical (so a fixed preamble/code re-acquires every burst).
  • WFM_SEED_ADVANCE_ALL: advance the whole seed → code, data, and noise all change (a fully stochastic stream).

Set before the first execute(); the first pass is always unchanged. An out-of-range mode is ignored.

Parameters:

  • state Compose state (may be NULL).
  • mode A wfm_seed_advance_t value.

function dp_wfm_compose_spans

Replay the (epoch 0) instance timeline of a resolved segment list.

size_t dp_wfm_compose_spans (
    const wfm_segment_t * segs,
    size_t n_segs,
    wfm_span_t * out,
    size_t cap
) 

Walks every segment's repeats instances, re-deriving each instance's drawn delay/on/off exactly as the streaming composer will (identical draw hash), and fills out with up to cap spans in stream order. Returns the TOTAL instance count regardless of cap — call once with cap 0 to size, then again with a buffer. Pass the RESOLVED segments (dp_wfm_compose_segments() on a live composer) so intrinsic on-times (dsss) are already folded in.

Assumes every segment builds: a segment that fails at render time (invalid burst geometry) degrades to its gaps only, so positions after it would shift relative to this replay.

Parameters:

  • segs Resolved segment array.
  • n_segs Segment count.
  • out Span buffer (may be NULL when cap is 0).
  • cap Capacity of out in spans.

Returns:

Total number of instances in one pass of the spec.


function dp_wfm_draws_json

The same rows dp_wfm_compose_draws() reports, as a JSON array.

char * dp_wfm_draws_json (
    const wfm_segment_t * segs,
    size_t n_segs
) 

One object per source per instance, in stream order, with the keys named after the wfm_draw_t fields. Exists so a binding can hand a caller its GROUND TRUTH without marshalling a struct array itself: a ranged field is only usable if what it drew can be read back, and scoring a receiver against a scene whose freq re-draws per instance means scoring against a number the caller does not otherwise have (doppler#1112).

Reads through dp_wfm_compose_draws(), so it cannot disagree with the SigMF annotations, which read through it too.

Parameters:

Returns:

Heap JSON string the caller free()s; never NULL — the allocations go through the abort-on-OOM helpers. A spec with no rows yields [].

size_t n; int rp, ct;
const wfm_segment_t *segs = dp_wfm_compose_segments(c, &n, &rp, &ct);
char *js = dp_wfm_draws_json(segs, n);
puts(js);
free(js);

function dp_wfm_frame_copy

Deep-copy a description: the struct and each literal field's bits.

wfm_frame_desc_t * dp_wfm_frame_copy (
    const wfm_frame_desc_t * d
) 

A source borrows its description; a holder that must outlive the caller's (the composer, a Python Synth) takes a copy instead, and releases it with dp_wfm_frame_free(). A later change to the original, or freeing it, does not reach the copy.

Parameters:

  • d the description to copy; NULL gives NULL.

Returns:

the owned copy.

wfm_frame_desc_t *a
    = dp_wfm_frame_from_json ("{\"fields\": [{\"spec\": \"1010\"}]}", NULL);
wfm_frame_desc_t *b = dp_wfm_frame_copy (a);
dp_wfm_frame_free (a);   // b is unaffected
// b->field[0].seq.len == 4
dp_wfm_frame_free (b);

function dp_wfm_frame_free

Free a description returned by dp_wfm_frame_from_json() , bits and all. NULL is a no-op.

void dp_wfm_frame_free (
    wfm_frame_desc_t * d
) 

Also frees a copy from dp_wfm_frame_copy(). It frees every field's bits and then d itself, so never pass a description the caller filled in its own storage (dp_wfm_frame_fixed()).

Parameters:

  • d The description, or NULL.
dp_wfm_frame_free (dp_wfm_frame_from_json ("{\"fields\": []}", NULL));
dp_wfm_frame_free (NULL);   // nothing to free

function dp_wfm_frame_from_json

Read a frame description from its JSON form.

wfm_frame_desc_t * dp_wfm_frame_from_json (
    const char * json,
    const char ** why
) 

The form a scene's "frame" key holds, and what wfmgen --frame FILE reads — one reader for both: {"fields": [...], "stages": [...]}. A field with bits is its Field text, "spec" ("0x1ACFFC1D", "pn:31:5*4"); a derived field is its "bits" and the "derived_by" stage (index plus one). A stage names its "kind" ("crc16", "rs", "randomise", "conv", "interleave", or a number from WFM_STAGE_USER up) and its cover as "first_field"/"n_fields", plus "depth", "unit_bits" and "emit_num"/"emit_den" where the kind uses them.

A malformed description is REFUSED, never salvaged: a frame read wrong builds a waveform that looks fine and is not the one described. Whether it lays out is a separate question, asked by dp_wfm_source_frame_error() once a source carries it.

Parameters:

  • json the frame object, NUL-terminated.
  • why receives a static reason on failure; may be NULL.

Returns:

the description, owning its literal bits (free it with dp_wfm_frame_free()), or NULL if the text is not a frame object.

const char       *why;
wfm_frame_desc_t *d = dp_wfm_frame_from_json (
    "{\"fields\": [{\"name\": \"sync\", \"spec\": \"0x1ACFFC1D\"},"
    "              {\"name\": \"data\", \"spec\": \"pn:31:5*4\"}]}",
    &why);
if (!d)
  fprintf (stderr, "error: %s\n", why);
// d->n_fields == 2; d->field[1].reps == 4
dp_wfm_frame_free (d);

function dp_wfm_frame_refuse_text

Refuse text for a source's frame= : it takes a description.

wfm_frame_desc_t * dp_wfm_frame_refuse_text (
    const char * text,
    const char ** why
) 

The frame face of dp_wfm_source_bits_refuse_text(). A source's frame= takes a FrameDesc or a Frame on the Python face, and a str is refused rather than read as JSON; a description written as JSON is a scene's "frame" key, read by dp_wfm_frame_from_json(). It has the shape of that reader because the binding calls it where the reader would be called (just-makeit's owned-pointer parse_fn with parse_why).

Parameters:

  • text ignored.
  • why receives the static reason; may be NULL.

Returns:

NULL, always.

const char *why;
wfm_frame_desc_t *d = dp_wfm_frame_refuse_text ("{\"fields\": []}", &why);
// d == NULL; why names FrameDesc

function dp_wfm_frame_to_json

Write a description as its JSON frame object, the text dp_wfm_frame_from_json() reads back.

char * dp_wfm_frame_to_json (
    const wfm_frame_desc_t * d
) 

The same writer a scene's "frame" key uses, so the two cannot spell a description differently: a literal field is its Field text, a derived field its bits and derived_by, a stage its kind and cover.

Parameters:

  • d the description; NULL gives NULL.

Returns:

a NUL-terminated string the caller releases with free().

wfm_frame_desc_t *d
    = dp_wfm_frame_from_json ("{\"fields\": [{\"spec\": \"1010\"}]}", NULL);
char *text = dp_wfm_frame_to_json (d);
// text: {"fields":[{"spec":"0xa"}],"stages":[]}
free (text);
dp_wfm_frame_free (d);

function dp_wfm_framing_flags_error

Why --sync /--crc /--acq-code cannot frame this source, or NULL.

const char * dp_wfm_framing_flags_error (
    const wfm_source_t * src
) 

The CLI's flags spell the common frame, which needs a waveform that carries a bit stream and, off dsss, a data source to fill it. Said once here and used by the same refusal inside dp_wfm_source_frame_error, so the flags and a bare source give one answer. A dsss burst needs neither.

Parameters:

  • src the source.

Returns:

a static sentence naming the fix, or NULL.


function dp_wfm_ofdm_fs_error

The rules of an ofdm source that need the segment's sample rate:fs is an integer multiple ofbandwidth (the oversamplingM , done by a larger transform),M is at most 128,window is within 80M samples, and a frame with itsgap is at most 2^24 samples. Asked bydp_wfm_scene_error() , so every face says the same sentence.

const char * dp_wfm_ofdm_fs_error (
    const wfm_source_t * src,
    double fs
) 

Parameters:

  • src The source; any other type, or one that fails its rate-free rules (dp_wfm_source_error()), answers NULL.
  • fs The segment's sample rate (Hz).

Returns:

A static sentence, or NULL.

wfm_source_t s = { .type = WFM_SYNTH_FRAMES, .sps = 1, .bandwidth = 20e6 };
dp_wfm_ofdm_fs_error (&s, 30e6);   // not an integer multiple, or NULL

function dp_wfm_render_destroy

Free a renderer and everything it owns. NULL-safe.

void dp_wfm_render_destroy (
    wfm_render_t * r
) 

A borrowed PERSIST channel is not freed: its owner frees it.

Parameters:

  • r The renderer, or NULL.

function dp_wfm_render_from_feed

A renderer whose input is a caller-supplied feed, not a live synth.

wfm_render_t * dp_wfm_render_from_feed (
    const wfm_source_t * src,
    double fs,
    double doppler,
    double doppler_rate,
    dp_doppler_channel_state_t * borrow,
    size_t delay,
    size_t on,
    wfm_feed_fn feed,
    void * feed_ctx
) 

This is what lets the Plan run a Doppler channel over its CACHED clean on-time through the one renderer the composer uses, so the dilation, the holdover and the input timeline are the same code rather than a second implementation of them. dp_wfm_render_steps() then yields the channel's output exactly as it does for a synth-backed renderer.

Parameters:

  • src Source whose carrier_hz the channel uses.
  • fs Sample rate, Hz.
  • doppler Drawn Doppler, ppm.
  • doppler_rate Drawn Doppler rate, ppm/s.
  • borrow A PERSIST channel the caller owns, or NULL to make one that dies with the renderer.
  • delay Leading noise-only INPUT samples (0 if the gaps are never pulled: see dp_wfm_render_set_input_timeline()).
  • on ON input samples.
  • feed Input source.
  • feed_ctx Passed to feed.

Returns:

A renderer (dp_wfm_render_destroy() it), or NULL if the source has no Doppler to apply (doppler and doppler_rate both zero and no borrow) or the channel could not be built.


function dp_wfm_render_noise_steps

Pull n samples of the source's NOISE FLOOR only, through the same channel.

void dp_wfm_render_noise_steps (
    wfm_render_t * r,
    float _Complex * dst,
    size_t n
) 

What a gap renders (gh-409). The channel runs here too, and deliberately: an emitter does not stop moving because its burst ended, so a pass is continuous and during a gap the thing propagating is the noise floor. Skip the channel over gaps and doppler_rate across a multi-burst scene quietly means "rate per unit of ON time" instead of per second.

With an input timeline set (dp_wfm_render_set_input_timeline()) the timeline, not this call, decides which input samples are noise-only.

Parameters:

  • r Renderer; not NULL.
  • dst Receives n samples.
  • n Samples to produce.

function dp_wfm_render_set_input_timeline

Tell a Doppler renderer where its INPUT's phases fall.

void dp_wfm_render_set_input_timeline (
    wfm_render_t * r,
    size_t delay,
    size_t on
) 

A renderer with a channel pulls the synth in refills sized to the channel's input, not to what the caller asked for, so it cannot learn the phase boundaries from the pull calls: the channel's input and output clocks are decoupled. This states them, in INPUT samples delay noise-only, then on signal, then noise-only for ever and the renderer follows that timeline however the output is drained (doppler#1858).

Without it a channel renderer falls back to choosing per refill from the phase of the output being drained, which is wrong at every phase boundary. No effect on a renderer with no channel.

Parameters:


function dp_wfm_render_steps

Pull exactly n samples fromr , through its channel if any.

void dp_wfm_render_steps (
    wfm_render_t * r,
    float _Complex * dst,
    size_t n
) 

With no channel this is dp_wfm_synth_steps(). With one, the channel's leftover output (the holdover) is drained first and the input is refilled as needed, following the input timeline when one is set (dp_wfm_render_set_input_timeline()).

Parameters:


function dp_wfm_resolve_noise

Resolve a segment list's noise model in place (Phase 4b).

int dp_wfm_resolve_noise (
    wfm_segment_t * segs,
    size_t n
) 

No-op for 1-source segments (keeps the bundled-synth path byte-identical). For a multi-source segment it sets one shared noise floor (from an explicit WFM_SYNTH_NOISE source, else the first snr-bearing source), cleans the signal sources, and appends a WFM_SYNTH_NOISE source at the floor — so the composer's accumulator just sums. May realloc each segment's sources. Idempotent.

dp_wfm_compose_create() calls this on its private copy, so every face (CLI, JSON, Python) resolves identically.

A source counts as snr-bearing when its snr is below the clean threshold (100 dB). A non-anchor source's snr is turned into a level of floor + snr dB, and every signal source's snr is then set clean so its own synth adds no AWGN. A segment whose sources are all clean, with no explicit noise source, is left alone. On a -1 return the segments may already be partly rewritten.

Parameters:

  • segs Segment array, rewritten in place.
  • n Number of segments in segs.

Returns:

0 on success; -1 if a non-anchor source over-specifies (snr + level) or on allocation failure.


function dp_wfm_scene_error

Why a scene cannot be composed, or NULL: the one validator.

const char * dp_wfm_scene_error (
    const wfm_segment_t * segs,
    size_t n_segs,
    int repeat,
    int continuous
) 

Every source's dp_wfm_source_error(), then what only the scene can say:

  • A continuous dsss source's chip rate fs / sps, at its segment's fs, is at least its symbol_rate one chip per data symbol, the synth's own floor (dp_wfm_source_dsss_cps()). The default fs = 1.0 with a symbol_rate in Hz is the case that finds it (doppler#1706); the reason is dp_wfm_why_dsss_cont_rate.
  • A count (num_samples, non-zero or ranged) beside sources that set the segment's length (dp_wfm_segment_sets_length()) is refused with dp_wfm_why_count_derived: the length is theirs, so it would be dropped (doppler#1729). A count equal to the length they derive is not: it is what a composer's segments read back, and it composes the same.
  • A data STREAM (--data-from-file -) has no end to repeat, so repeat, continuous and a segment's repeats > 1 are refused, and stdin feeds at most one source.

dp_wfm_compose_create() refuses exactly these, and dp_wfm_compose_create_why() says which; a face calls this to say why.

The first fault found wins: sources are checked in segment order, and the count rule runs only after every source has passed.

Parameters:

  • segs The segments, as the caller gave them (unresolved).
  • n_segs Number of segments in segs.
  • repeat Non-zero when the scene loops (as for dp_wfm_compose_create()).
  • continuous Non-zero when the scene never finishes.

Returns:

a static sentence naming the fault and its fix, or NULL.


function dp_wfm_segment_fs

The rate a segment renders at: the get_fn behind a Segment'sfs , so a segment whose ofdm sources set its rate reads it.

double dp_wfm_segment_fs (
    const wfm_segment_t * seg,
    double fs
) 

Every source is asked with dp_wfm_source_fs() at fs, so their order never changes the answer: the rate the ofdm sources at a default name, when they agree, else fs. Sources that name differing rates read fs, and the composer refuses the segment naming both (the read never claims a rate the segment cannot render at).

Parameters:

  • seg The segment; its sources are read, its own fs is not.
  • fs The segment's stored sample rate, Hz.

Returns:

The rate the segment renders at, Hz.

#include <doppler/wfm/wfm_defaults.h>   // WFM_SOURCE_DEFAULTS

wfm_source_t  s = WFM_SOURCE_DEFAULTS;
s.type          = WFM_SYNTH_FRAMES;    // ofdm, 20 MHz
wfm_segment_t g = { .sources = &s, .n_sources = 1 };
printf ("%g\n", dp_wfm_segment_fs (&g, 1.0));    // 2e+07
printf ("%g\n", dp_wfm_segment_fs (&g, 40e6));   // 4e+07

function dp_wfm_segment_sets_length

Whether a segment's sources SET its on-time, so its num_samples is derived and a count given beside them refused.

int dp_wfm_segment_sets_length (
    const wfm_segment_t * seg
) 

Two kinds of source set a length (payload-data-source.md 4.6):

  • A finite data source data, a finite file, or a carried frame of fixed bits is its frames (dp_wfm_source_data_frames()); the longest of a segment's sets it.
  • A lone dsss burst one dsss source, no symbol_rate, no data source is one burst (dp_wfm_source_dsss_nchips() times sps).

A stream sets none: it runs to its end, and a count may bound it. A non-zero num_samples (or a ranged one) beside a segment this answers 1 for is refused by dp_wfm_scene_error() with dp_wfm_why_count_derived, on every face.

static const uint8_t bits[16] = { 1 };
wfm_source_t  src  = { .type       = WFM_SYNTH_BITS,
                       .modulation = 1, // bpsk
                       .sps        = 1,
                       .pn_length  = 7 };
src.data = (wfm_seq_t){ .kind = WFM_SEQ_LITERAL, .bits = bits,
                        .len = 16 };
wfm_segment_t seg = { .sources = &src, .n_sources = 1, .fs = 1e6 };
if (!dp_wfm_segment_sets_length (&seg)) // its frames are the run
  return 1;
seg.num_samples = 1000;                 // so a count is refused
if (dp_wfm_scene_error (&seg, 1, 0, 0) != dp_wfm_why_count_derived)
  return 1;

Parameters:

  • seg the segment, as the caller gave it.

Returns:

1 when its sources set its on-time, else 0.


function dp_wfm_segment_snr_and_level

The source in a segment that sets both snr and alevel where only one is allowed, or -1 when there is none.

int dp_wfm_segment_snr_and_level (
    const wfm_segment_t * g
) 

One multi-source segment has one noise floor: an explicit noise source sets it, else the first snr-bearing signal source anchors it. Every OTHER snr-bearing source is placed snr dB above that floor, so its level is derived, and giving it a nonzero level too says the same thing twice and could disagree. dp_wfm_resolve_noise() refuses such a segment, and dp_wfm_scene_error() reports it as dp_wfm_why_snr_and_level; both ask THIS function, so they cannot disagree about which scene it is (doppler#2834).

Parameters:

  • g A segment, as the caller built it (before resolve).

Returns:

Index into g->sources of the first offender, or -1: a lone source, a segment with no floor (all clean, no explicit noise), or one where no non-anchor source gives both.

#include <doppler/wfm/wfm_compose.h>
#include <stdio.h>

int
main (void)
{
  // A tone beside an explicit noise source: the noise sets the floor, so
  // the tone may give its snr OR its level, not both.
  wfm_source_t s[2] = {
    { .type = WFM_SYNTH_TONE, .snr = 20.0, .level = -6.0 },
    { .type = WFM_SYNTH_NOISE, .level = -40.0 },
  };
  wfm_segment_t g = { .sources = s, .n_sources = 2, .fs = 2e6 };

  printf ("both: source %d\n", dp_wfm_segment_snr_and_level (&g)); // 0
  puts (dp_wfm_scene_error (&g, 1, 0, 0) == dp_wfm_why_snr_and_level
            ? "scene refused with dp_wfm_why_snr_and_level"
            : "unexpected");

  s[0].level = 0.0; // snr alone
  printf ("snr alone: %d\n", dp_wfm_segment_snr_and_level (&g)); // -1
  return 0;
}

function dp_wfm_snr_over_fs

SNR (dB) referred to fs, from a source's snr/snr_mode/sps/type.

double dp_wfm_snr_over_fs (
    int snr_mode,
    int type,
    int sps,
    size_t sf,
    double sym_span,
    double snr
) 

The single source of truth for the Es/No, Eb/No, and over-fs conventions (snr_mode 0 auto / 1 fs / 2 ebno / 3 esno). dp_wfm_resolve_noise() uses it to place the shared noise floor at level(anchor) − dp_wfm_snr_over_fs(anchor), and the Plan stimulus engine reuses it to recompute the floor at an arbitrary swept SNR — so both agree to the bit.

For type=dsss the symbol is the outer data symbol. For a BURST that spans sf * sps samples (sf chips, sps samples per chip). For a CONTINUOUS async stream the data clock is independent of the code, so the span is fs / symbol_rate samples — passed as sym_span (non-integer), which OVERRIDES the sf·sps reconstruction when non-zero. auto picks esno, and esno/ebno convert as snr − 10·log10(span) (BPSK payload, so the two coincide). Every other type ignores sf and sym_span.

Parameters:

  • snr_mode 0 auto, 1 fs, 2 ebno, 3 esno.
  • type A WFM_SYNTH_* waveform type (selects the auto convention).
  • sps Samples per symbol/chip (≥1; <1 treated as 1).
  • sf Spreading factor — chips per data symbol (burst dsss; ≥1, <1 treated as 1).
  • sym_span Continuous-dsss symbol span in samples (fs/symbol_rate); 0 = burst/non-dsss, derive from sf·sps.
  • snr The declared SNR in dB.

Returns:

SNR over fs in dB.


function dp_wfm_source_acq_code_bits

The bits a source's sequence field reads as: a literal's own, or the run its generator renders.

size_t dp_wfm_source_acq_code_bits (
    const wfm_source_t * src,
    double fs,
    uint8_t * out,
    size_t max
) 

A wfm_seq_t field is a literal (bits non-NULL) or a generated one (a PN, Gold or dotted description with bits NULL and len its output length). These five are the Python read of acq_code, data_code, data, fill and mac_header: they write the field's bits through dp_wfm_seq_bits(), so a generated field reads as the bits it renders and not as nothing. A field that is absent (len 0) or draws its bits from the frame's data source (WFM_SEQ_DATA) has none and returns 0. What is stored, set and written to a record is unchanged.

Parameters:

  • src The source.
  • fs The segment's sample rate, Hz; unused, a read of bits has no rate.
  • out Receives the bits, one per byte; NULL with max 0 only asks how many there are.
  • max Capacity of out.

Returns:

The bits the field holds, or 0.

#include <doppler/wfm/wfm_defaults.h>   // WFM_SOURCE_DEFAULTS

wfm_source_t s = WFM_SOURCE_DEFAULTS;
s.mac_header = (wfm_seq_t){ .kind = WFM_SEQ_PN, .len = 192, .reg_bits = 15 };
printf ("%zu\n", dp_wfm_source_mac_header_bits (&s, 20e6, NULL, 0)); // 192

function dp_wfm_source_attach_dsss

Attach a dsss source's data to a freshly-created synth.

int dp_wfm_source_attach_dsss (
    dp_wfm_synth_state_t * syn,
    const wfm_source_t * src,
    double fs
) 

The single dsss-attach path, called by BOTH synth-construction faces (dp_wfm_compose_build_synth and the standalone dp_wfm_source_to_synth), so the two cannot drift on how a dsss stream is configured. Selects on symbol_rate: 0 → the burst form (dp_wfm_synth_set_dsss_chips); > 0 → the continuous form (dp_wfm_synth_set_dsss_cont) with chips_per_symbol = (fs/sps)/symbol_rate, taking the data from the payload when one is supplied (bits) and otherwise from the seeded PN, and framing it with the per-frame code-only window (code_only_symbols of every frame_symbols, dp_wfm_synth_set_dsss_window) when one is set. A no-op for a non-dsss source.

Parameters:

  • syn A synth from dp_wfm_synth_create() with wtype == WFM_SYNTH_DSSS.
  • src The source (codes, payload, symbol_rate, pn config).
  • fs Segment sample rate (Hz) — the continuous chip rate is fs/sps.

Returns:

0 on success (or non-dsss no-op); -1 on invalid geometry.


function dp_wfm_source_attach_frame

Attach an unspread source's bit pattern, framed or not.

int dp_wfm_source_attach_frame (
    dp_wfm_synth_state_t * syn,
    const wfm_source_t * src
) 

The type=bits counterpart of dp_wfm_source_attach_dsss(), and called from the same two places for the same reason. When the source carries a frame, the pattern handed to dp_wfm_synth_set_bits() is dp_wfm_frame_assemble() of [preamble x reps | sync | payload | crc] rather than the payload alone — so the layout, the CRC's position and its bit order come from the one descriptor that the DSSS path and the receiver already read.

The frame CYCLES, exactly as an unframed pattern does: one descriptor fills whatever length is asked for, which is what turns a one-frame description into a multi-frame record.

Parameters:

  • syn A synth from dp_wfm_synth_create() with wtype == WFM_SYNTH_BITS.
  • src The source (pattern, modulation, and any frame fields).

Returns:

0 on success (or a non-bits/no-pattern no-op); -1 on failure.


function dp_wfm_source_attach_ofdm

Install an ofdm source's frame renderer and its data pull on a synth created with type WFM_SYNTH_FRAMES: the PPDU of each frame of the data source, built throughwlan from the source's constellation and code rate (orwlan ),window ,mac ,gap and the oversamplingfs / bandwidth . A no-op for any other type.

int dp_wfm_source_attach_ofdm (
    dp_wfm_synth_state_t * syn,
    const wfm_source_t * src,
    double fs,
    uint32_t seed
) 

Called by every face's build, as dp_wfm_source_attach_dsss() is, so the standalone and the composed source cannot drift. The renderer's configuration, seed included, is the state triplet's reject keys.

Parameters:

  • syn The synth.
  • src The source; it must pass dp_wfm_source_error() and dp_wfm_ofdm_fs_error().
  • fs The segment's sample rate (Hz).
  • seed The seed the scrambler's per-PPDU draw uses when scrambler_init is 0 (the composer's epoch-advanced seed).

Returns:

0 on success or for another type, -1 if a refused source reached here or a build failed.

dp_wfm_synth_state_t *syn = dp_wfm_synth_create (
    WFM_SYNTH_FRAMES, 20e6, 0.0, 100.0, 0, 1u, 1, 0, 0, 0, 0.0);
// dp_wfm_source_attach_ofdm (syn, &src, 20e6, 1u) installs the renderer

function dp_wfm_source_bandwidth

The channel bandwidth of an ofdm source, Hz: its bandwidth , or the preset's 20e6 when that is 0 (a C source that skipped the defaults).

double dp_wfm_source_bandwidth (
    const wfm_source_t * src
) 

A negative value is not repaired here: dp_wfm_source_error() refuses it by name.

Parameters:

  • src The source.

Returns:

Hz.


function dp_wfm_source_bits_refuse_text

Refuse text for a source's bit field: an object takes bits.

size_t dp_wfm_source_bits_refuse_text (
    const char * text,
    uint8_t * out,
    size_t max_out,
    const char ** why
) 

A composer source's bit fields (payload, sync, acq_code, data_code) take BITS on the Python face a uint8 array, bytes or a sequence of 0/1 and module helpers make them from other forms: field_bits(text) for the Field grammar, cvt.hex_to_bin, cvt.bytes_to_bin. A str is refused rather than read, so the object has one shape and the Field grammar one door. The text faces (the CLI, a scene) keep reading a Field through dp_wfm_field_parse().

It has the shape of dp_wfm_field_bits() because the binding calls it where that would be called (just-makeit's coerce_str_fn), and it always refuses: it returns 0 and sets why to its one static reason.

Parameters:

  • text ignored.
  • out never written.
  • max_out ignored.
  • why receives the static reason; may be NULL.

Returns:

0, always.

const char *why;
size_t      n = dp_wfm_source_bits_refuse_text ("0101", NULL, 0, &why);
// n == 0; why names field_bits()

function dp_wfm_source_code_rate

The code-rate index an ofdm source renders with, never auto : theget_fn behind a Synth'scode_rate , asdp_wfm_source_constellation() is for its constellation.

int dp_wfm_source_code_rate (
    const wfm_source_t * src,
    double fs
) 

Parameters:

  • src The source.
  • fs Unused; the signature every get_fn has.

Returns:

The index (0 for 1/2 ... 3 for 5/6), or the stored value when the rate does not resolve.


function dp_wfm_source_common_frame

The common frame as a description: [preamble x reps | sync | data | crc] , built by the ONE function that builds it.

int dp_wfm_source_common_frame (
    const wfm_source_t * src,
    const wfm_seq_t * sync,
    int crc,
    wfm_frame_desc_t * d
) 

Used by the bridge (a scene's or Python's acq_code + data, with no sync word and no CRC) and by wfmgen for --sync and --crc, which are sugar for these fields. The preamble is a field for an unspread source and is NOT one for a spread burst: a DSSS preamble is sent unspread outside the description. The description borrows src's and sync's sequences.

Parameters:

  • src the source (its acq_code, acq_reps, data, data_from_file and data_len are read).
  • sync the sync word, or NULL for none.
  • crc non-zero appends a CRC-16 over the payload.
  • d receives the description.

Returns:

0, or -1 when it does not lay out.


function dp_wfm_source_constellation

The constellation index an ofdm source renders with, at fs: theget_fn behind a Synth'sconstellation , so it reads the resolved value (the pairwlan names, or the default's), neverauto .

int dp_wfm_source_constellation (
    const wfm_source_t * src,
    double fs
) 

Parameters:

  • src The source.
  • fs Unused: the rate does not change the pair. The signature is the one every get_fn has.

Returns:

The index, or the stored value when the rate does not resolve (a source whose build is then refused naming why).


function dp_wfm_source_crc_refuse_text

Refuse text for the retired crc= : a CRC is a stage of the frame description.

size_t dp_wfm_source_crc_refuse_text (
    const char * text,
    uint8_t * out,
    size_t max_out,
    const char ** why
) 

As dp_wfm_source_sync_refuse_text, for crc=. crc="none" is refused too: it would otherwise be a spelling that works forever with no way to retire it.

Parameters:

  • text the str (unused: every str is refused).
  • out unused.
  • max_out unused.
  • why receives the sentence.

Returns:


function dp_wfm_source_create_snr

Resolve a source's (snr, snr_mode) into the pair to hand to dp_wfm_synth_create() .

double dp_wfm_source_create_snr (
    const wfm_source_t * src,
    double fs,
    double snr,
    int * snr_mode
) 

dp_wfm_synth_create() runs before a dsss source's codes are attached, so it cannot know the spreading factor its own esno would need. This helper — the one create-time entry point shared by the composer (dp_wfm_compose_build_synth) and the standalone-Synth bridge (dp_wfm_source_to_synth), so every face agrees to the bit — converts a dsss source's SNR to the over-fs reference (via dp_wfm_snr_over_fs; the burst span is sf = n_data_code, a continuous stream uses fs/symbol_rate) and returns snr_mode=fs. A framed bpsk/qpsk/pn is referred the same way, because its synth is created as BITS (dp_wfm_source_synth_type()). Every other source passes through unchanged.

Parameters:

  • src The source (supplies type/sps/snr_mode/n_data_code/ symbol_rate).
  • fs Segment sample rate (Hz) — needed for a continuous dsss source's fs/symbol_rate span; ignored otherwise.
  • snr The declared SNR in dB, already ranged-resolved.
  • snr_mode Receives the snr_mode for create.

Returns:

The SNR in dB for create.


function dp_wfm_source_data_bits

As dp_wfm_source_acq_code_bits() , fordata .

size_t dp_wfm_source_data_bits (
    const wfm_source_t * src,
    double fs,
    uint8_t * out,
    size_t max
) 

Parameters:

  • src The source.
  • fs Unused.
  • out Receives the bits, or NULL to count.
  • max Capacity of out.

Returns:

The bits the field holds, or 0.


function dp_wfm_source_data_code_bits

As dp_wfm_source_acq_code_bits() , fordata_code .

size_t dp_wfm_source_data_code_bits (
    const wfm_source_t * src,
    double fs,
    uint8_t * out,
    size_t max
) 

Parameters:

  • src The source.
  • fs Unused.
  • out Receives the bits, or NULL to count.
  • max Capacity of out.

Returns:

The bits the field holds, or 0.


function dp_wfm_source_data_frames

Frames a FINITE data source makes, ceil(bits / LEN) ; 0 for a stream or none. On continuous dsss, which has no frame, its bits.

uint64_t dp_wfm_source_data_frames (
    const wfm_source_t * src
) 

Known before the first sample (a file's length from fstat), which is what lets a finite run's length be derived rather than given (§4.6).

static const uint8_t bits[40] = { 1 };
wfm_source_t src = { .type = WFM_SYNTH_BPSK, .sps = 4 };
src.data      = (wfm_seq_t){ .kind = WFM_SEQ_LITERAL, .bits = bits,
                             .len = 40 };
src.data_len  = 16;
src.fill      = (wfm_seq_t){ .kind = WFM_SEQ_DOTTED, .len = 2 };
if (dp_wfm_source_data_frames (&src) != 3) // 40 bits in 16-bit frames
  return 1;
if (dp_wfm_source_data_samples (&src, 1e6, 3) != 3 * 16 * 4) // bpsk
  return 1;

A carried frame with no data source (data / data_from_file), on a type that can carry a frame, counts as one frame, sent once.

Parameters:

  • src The source; NULL gives 0.

Returns:

frames (bits, for continuous dsss); 0 for a stream, a source with no data, or a frame with no non-empty data field.


function dp_wfm_source_data_is_stream

Whether a source's data is a stream: data_from_file is- .

int dp_wfm_source_data_is_stream (
    const wfm_source_t * src
) 

A stream has no length up front and no end to repeat, so a scene refuses it with repeat, continuous or repeats > 1, Plan refuses it, and a segment carrying one runs until it ends (dp_wfm_scene_error()).

Parameters:

  • src The source; NULL reads as not a stream.

Returns:

1 when data_from_file is exactly "-", else 0.


function dp_wfm_source_data_samples

Samples the first frames frames of a source's data occupy; 0 with no data.

uint64_t dp_wfm_source_data_samples (
    const wfm_source_t * src,
    double fs,
    uint64_t frames
) 

The one length a run with a data source is measured in: a finite run is this over dp_wfm_source_data_frames(), and a stream ends at this over the frames it sent.

  • A frame (bits, bpsk/qpsk/pn): its output bits at the mapping's bits per symbol (rounded up), times sps, per frame.
  • A dsss burst: its chips times sps (samples per chip), per burst.
  • Continuous dsss has no frame: a "frame" is one data bit, one per data symbol, and the run is every chip up to the symbol after the frames-th data symbol, at fs / sps / symbol_rate chips per symbol not a whole number, so not a product times sps. Every symbol carries data unless a code-only window is set; then the data pauses through each frame's first code_only_symbols, and the run counts every window before the last data symbol (not one after it).

Parameters:

  • src the source.
  • fs the segment's sample rate (only continuous dsss reads it).
  • frames frames (data bits, for continuous dsss) sent.

Returns:

samples, in the segment's sample clock; 0 for a NULL source, a source with no data source and no carried frame, a frame that does not lay out, or a continuous dsss source under one chip per symbol.


function dp_wfm_source_dsss_cps

Chips per data symbol of a CONTINUOUS dsss source at fs .

double dp_wfm_source_dsss_cps (
    const wfm_source_t * src,
    double fs
) 

sps is samples per CHIP for dsss, so the chip rate is fs / sps, and the data clock is symbol_rate: their ratio, non-integer in general, which is the asynchronicity. It is the number the builder hands dp_wfm_synth_set_dsss_cont(), and the one dp_wfm_scene_error() holds to >= 1 so the rule and the synth read the same value.

Parameters:

  • src the source.
  • fs its segment's sample rate, in Hz.

Returns:

chips per data symbol, or 0 for a source that is not continuous dsss (or has no sps).

wfm_source_t s = { .type = WFM_SYNTH_DSSS, .sps = 2,
                   .symbol_rate = 1000.0 };
if (dp_wfm_source_dsss_cps (&s, 1e6) != 500.0)   // 500 chips per symbol
  return 1;

function dp_wfm_source_dsss_nchips

Chips one DSSS BURST from this source occupies, description and all.

size_t dp_wfm_source_dsss_nchips (
    const wfm_source_t * src
) 

What sizes a lone dsss segment's intrinsic on-time. It reads the same description the burst is assembled from, so a stage that lengthens the frame a rate-1/2 inner code doubles it lengthens the segment by the same arithmetic instead of by a second copy of it.

Parameters:

  • src the source.

Returns:

burst chips, or 0 for a non-dsss source, a CONTINUOUS dsss source (which has no intrinsic length), or an empty/refused geometry.


function dp_wfm_source_error

NULL when this source can be built; else why not, as a sentence.

const char * dp_wfm_source_error (
    const wfm_source_t * src
) 

The question every face asks before it builds the wfmgen CLI, a scene read by dp_wfm_compose_from_json_why(), the standalone Synth through dp_wfm_source_to_synth() and the composer through dp_wfm_compose_create() so all four refuse the same sources for the same reason. It checks the source's own parameters, then asks dp_wfm_source_frame_error() about its frame:

  • pn_poly must fit the pn_length-bit register (pn_fits_register()). The generator masks a wider one, silently, so pn_poly = 0x40 on a 5-bit register is a register with no feedback: the seed, then zeros, a constant waveform that still looks like a PN source (doppler#1636). 0 selects the maximal-length polynomial and always fits.
  • No two members the surface table declares exclusive may both be set (WFM_SURFACE_EXCLUSIVE, wfm_surface.h): a carried frame is the whole frame, so a payload beside it would be dropped (doppler#1683). The CLI and a scene refuse the same pair first, naming their own spelling.
  • A dsss source has the codes it needs (doppler#1696): a burst whose frame has bits to spread needs data_code (dp_wfm_why_dsss_frame_no_data_code), a burst needs a preamble or a frame (dp_wfm_why_dsss_empty), and a continuous stream needs data_code (dp_wfm_why_dsss_cont_no_data_code). A preamble alone is a valid burst: an acquisition stimulus.

A rule that needs the segment's sample rate is not here a source does not carry it but in dp_wfm_scene_error(), which asks this first.

Parameters:

  • src The source.

Returns:

NULL if there is nothing wrong, else a static message.

wfm_source_t s = { .type = WFM_SYNTH_PN, .sps = 1, .pn_length = 5,
                   .pn_poly = 0x40 };
dp_wfm_source_error (&s);   // "pn_poly has a bit above ..."
s.pn_poly = 0x12;
dp_wfm_source_error (&s);   // NULL: x^5 + x^2 + 1 fits

function dp_wfm_source_fill_bits

As dp_wfm_source_acq_code_bits() , forfill .

size_t dp_wfm_source_fill_bits (
    const wfm_source_t * src,
    double fs,
    uint8_t * out,
    size_t max
) 

Parameters:

  • src The source.
  • fs Unused.
  • out Receives the bits, or NULL to count.
  • max Capacity of out.

Returns:

The bits the field holds, or 0.


function dp_wfm_source_frame_error

NULL when this source's frame fields can be honoured; else why not.

const char * dp_wfm_source_frame_error (
    const wfm_source_t * src
) 

ONE rule, asked by all three faces — the wfmgen CLI before it generates, the standalone Synth through dp_wfm_source_to_synth, and the composer through dp_wfm_compose_create — because the alternative is what shipped: the flags were accepted, stored and readable back on every face, and applied on none of them, so a caller who asked for a framed waveform silently got an unframed one.

A frame needs a payload. type=bits and the PN-sourced bpsk/qpsk/pn carry one when a payload is given (literal or generated, gh-762); the latter are then built as a BITS synth (dp_wfm_source_synth_type()). Types with no bit stream (tone, noise, chirp, symbols) are refused with a reason.

Parameters:

  • src The source.

Returns:

NULL if there is nothing wrong, else a static message.


function dp_wfm_source_fs

The rate an ofdm source renders at: its bandwidth when fs is at a face's default, elsefs . Thefs_get_fn behind a Synth'sfs , and the per-source ruledp_wfm_source_ofdm_defaults() anddp_wfm_segment_fs() apply.

double dp_wfm_source_fs (
    const wfm_source_t * src,
    double fs
) 

Both defaults, WFM_SEGMENT_FS_DEFAULT (1.0) and WFM_SYNTH_FS_DEFAULT (1e6), read as unset whichever face stored the value, because every read is handed the stored rate. Neither is a legal ofdm rate (1.0 / 5e6 and 1e6 / 5e6 are below M = 1), so no rate a source rendered at reads differently. A source of any other type, or ofdm at any other rate, reads fs. The rate needs no pair, so a live half pair reads it too.

Parameters:

  • src The source.
  • fs The stored sample rate, Hz.

Returns:

The rate the source renders at, Hz.

#include <doppler/wfm/wfm_defaults.h>   // WFM_SOURCE_DEFAULTS

wfm_source_t s = WFM_SOURCE_DEFAULTS;
s.type         = WFM_SYNTH_FRAMES;      // ofdm
printf ("%g\n", dp_wfm_source_fs (&s, 1e6));   // 2e+07
printf ("%g\n", dp_wfm_source_fs (&s, 40e6));  // 4e+07
s.bandwidth = 10e6;
printf ("%g\n", dp_wfm_source_fs (&s, 1.0));   // 1e+07

function dp_wfm_source_has_frame

Non-zero when this source describes a FRAME.

int dp_wfm_source_has_frame (
    const wfm_source_t * src
) 

A carried description, a preamble or a data source is what says "framed".

Lengths are tested, never pointers: a carried frame, an acq_code with non-zero length AND acq_reps, a non-empty data, or a data_from_file.

Parameters:

  • src The source; NULL reads as unframed.

Returns:

1 when the source is framed, 0 otherwise (including NULL).


function dp_wfm_source_mac

The MAC mode an ofdm source renders with: auto readsfcs (dp_wlan_mac_resolve()). Theget_fn behind a Synth'smac .

int dp_wfm_source_mac (
    const wfm_source_t * src,
    double fs
) 

Parameters:

  • src The source.
  • fs Unused; the signature every get_fn has.

Returns:

A dp_wlan_mac_t value other than WLAN_MAC_AUTO.


function dp_wfm_source_mac_header_bits

As dp_wfm_source_acq_code_bits() , formac_header .

size_t dp_wfm_source_mac_header_bits (
    const wfm_source_t * src,
    double fs,
    uint8_t * out,
    size_t max
) 

Parameters:

  • src The source.
  • fs Unused.
  • out Receives the bits, or NULL to count.
  • max Capacity of out.

Returns:

The bits the field holds, or 0.


function dp_wfm_source_ofdm_defaults

An ofdm source with its zero-config defaults filled in, and the rate it renders at: the one place those defaults are decided.

const char * dp_wfm_source_ofdm_defaults (
    const wfm_source_t * src,
    double fs,
    wfm_source_t * out,
    double * fs_out
) 

For a source of type ofdm (WFM_SYNTH_FRAMES), on a copy:

  • the rate: with wlan 0, a constellation and code_rate at auto become the 36 Mb/s pair (WLAN_MBPS_DEFAULT) by dp_wlan_rate_resolve(), which refuses half a pair and wlan beside a given half in its own words. A wlan source keeps its pair at auto: wlan is how it was spelled, and a record writes it alone;
  • the MAC: auto is fcs (dp_wlan_mac_resolve());
  • the payload: a source with neither data nor data_from_file takes pn:768:15, 96 octets of the PN15 m-sequence from the data field's default polynomial and seed, which with the FCS is a 100-octet PSDU;
  • the rate it renders at: an fs at a face's default (WFM_SEGMENT_FS_DEFAULT, a segment's; WFM_SYNTH_FS_DEFAULT, a Synth's) is read as unset and becomes the source's bandwidth (M = 1). Neither is a whole multiple of a bandwidth ofdm takes, so ofdm refused both and no rate a source rendered at is read differently. One consequence: such an fs given explicitly is read the same way, and the read-back and the record show the bandwidth.

Any other source is copied unchanged, as is fs. The result is resolved: resolving it again changes nothing, so a composer's own segments, which hold it, compose again. The composer, the standalone synth, the scene validator and the record each work on what this returns, so none holds, writes or reads auto.

Parameters:

  • src The source as given.
  • fs The segment's sample rate, Hz, as given.
  • out The resolved copy. It shares src's pointers, so it is read, never freed.
  • fs_out The rate it renders at. May be NULL.

Returns:

NULL, or the sentence of the refusal, with out a plain copy.

#include <doppler/wfm/wfm_defaults.h>   // WFM_SOURCE_DEFAULTS

wfm_source_t s = WFM_SOURCE_DEFAULTS, r;
s.type         = WFM_SYNTH_FRAMES;      // ofdm, nothing else given
double fs;
dp_wfm_source_ofdm_defaults (&s, 1.0, &r, &fs);
// r: qam16, 3/4, fcs, pn:768:15; fs: 20e6

function dp_wfm_source_oversample

The oversampling M = fs / bandwidth of an ofdm source, 1 toWLAN_OVERSAMPLE_MAX , or 0 with the reason it has none.

unsigned dp_wfm_source_oversample (
    const wfm_source_t * src,
    double fs,
    const char ** why
) 

The one derivation: dp_wfm_ofdm_fs_error() and the renderer take their geometry from it, and dp_wfm_source_window() scales by it. fs must be a whole multiple of the bandwidth (the transform is longer, not resampled) and at most 128 times it.

Parameters:

  • src The source.
  • fs The segment's sample rate, Hz.
  • why Receives the refusal's sentence, or NULL on success; may be NULL.

Returns:

M, or 0.


function dp_wfm_source_rate_why

Why a source's rate fields would be refused when it builds, by the build's own resolver, or NULL: the one check every setter of a source's rate and type writes through.

const char * dp_wfm_source_rate_why (
    const wfm_source_t * src
) 

Another type has no rate, so it is always NULL. An ofdm source is refused for half a pair, for wlan beside a given half, and for a wlan no row of Table 17-6 names, each in dp_wlan_rate_resolve()'s words. A given pair the table lacks, as (qam16, 5/6), reads back as written, so it is not refused here: the build refuses it with "no SIGNAL RATE bits". wlan at a bandwidth other than 20 MHz is refused here too, since it reads only those two fields. The rules that need a sample rate or a data source are the build's, dp_wfm_source_error().

Parameters:

  • src The source.

Returns:

NULL, or a static sentence.


function dp_wfm_source_set_bandwidth

Set a source's bandwidth : theset_fn behind a Synth's and a Segment'sbandwidth .

const char * dp_wfm_source_set_bandwidth (
    wfm_source_t * src,
    double bandwidth
) 

On an ofdm source whose rate is spelled by wlan, a bandwidth other than 20 MHz is refused, the struct untouched, with dp_wfm_source_rate_why()'s sentence: wlan is the data rate at 20 MHz. Any other value is written, and one the build refuses (not 20e6, 10e6 or 5e6) reads back as written.

Parameters:

  • src The source.
  • bandwidth Hz; 0 is 20e6.

Returns:

NULL after writing, or a static sentence with src untouched.


function dp_wfm_source_set_code_rate

Set an ofdm source's code_rate so its rate pair stays whole: the set_fn behind a Synth's and a Segment'scode_rate , the mirror ofdp_wfm_source_set_constellation() , whose table is the rule.

const char * dp_wfm_source_set_code_rate (
    wfm_source_t * src,
    int code_rate
) 

Parameters:

  • src The source.
  • code_rate The index (0 for 1/2 ... 3 for 5/6), or WLAN_CODE_AUTO.

Returns:

NULL after writing, or a static sentence with src untouched.


function dp_wfm_source_set_constellation

Set an ofdm source's constellation so its rate pair stays whole: the set_fn behind a Synth's and a Segment'sconstellation .

const char * dp_wfm_source_set_constellation (
    wfm_source_t * src,
    int constellation
) 

An ofdm rate is a pair, constellation and code_rate, given whole or left at auto whole (docs/design/wlan.md, "A live object's pair stays whole"). A setter writes one half, so on an ofdm source it keeps the pair whole by these rules, the same for both halves (dp_wfm_source_set_code_rate() is the mirror):

the pair before set a half to a value set a half to auto
auto, no wlan the other half is FIXED at the value it read before the write: the default pair's, (qam16, 3/4) at 20 MHz stays auto
auto, rate set by wlan refused, the struct untouched: "the rate is set by wlan: set wlan to 0 before setting constellation or code_rate" stays auto
given written; the other half is kept as given BOTH halves return to auto

auto is a property of the pair, never of one half: setting either half to auto returns both, so no write leaves one half auto beside a given other. A given pair the standard's rate table lacks, as (qam16, 5/6), is written: the setter returns NULL, and the source is refused when it builds, by dp_wfm_source_error(), with "this constellation and code_rate have no SIGNAL RATE bits (Table 17-6 lists eight of the sixteen pairs)". On any other type the value is stored as given, as it reads back.

Every setter, this one, dp_wfm_source_set_code_rate(), dp_wfm_source_set_wlan() and dp_wfm_source_set_type(), writes only a source that dp_wfm_source_rate_why() accepts, so no write leaves a source that reads as a valid pair and is refused when it builds. A record and from_json set every field at once and refuse half a pair when they are read.

Parameters:

Returns:

NULL after writing, or a static sentence with src untouched.

#include <doppler/wfm/wfm_defaults.h>   // WFM_SOURCE_DEFAULTS

wfm_source_t s = WFM_SOURCE_DEFAULTS;
s.type         = WFM_SYNTH_FRAMES;                    // ofdm
dp_wfm_source_set_constellation (&s, 0);              // bpsk
// s.constellation == 0, s.code_rate == WLAN_CODE_3_4: fixed at its read

function dp_wfm_source_set_type

Set a source's type : theset_fn behind a Synth's and a Segment'stype .

const char * dp_wfm_source_set_type (
    wfm_source_t * src,
    int type
) 

The rate fields of another type are stored as given, so a source can hold half a pair, or wlan beside a pair, until it becomes ofdm. A write to ofdm is refused, the struct untouched, when dp_wfm_source_rate_why() refuses the source it would leave: half a pair ("constellation and code_rate are one rate: give both, or neither"), wlan beside a given pair ("a data rate in Mb/s is a spelling of constellation and code_rate: give the rate, or constellation and code_rate, not both"), or a wlan no row names. A write to any other type is always made.

Parameters:

  • src The source.
  • type A waveform type, WFM_SYNTH_TONE to WFM_SYNTH_FRAMES.

Returns:

NULL after writing, or a static sentence with src untouched.

#include <doppler/wfm/wfm_defaults.h>   // WFM_SOURCE_DEFAULTS

wfm_source_t s  = WFM_SOURCE_DEFAULTS;           // tone
s.constellation = 0;                             // bpsk, stored as given
const char *why = dp_wfm_source_set_type (&s, WFM_SYNTH_FRAMES);
// why names half a pair; s.type is still tone

function dp_wfm_source_set_wlan

Set an ofdm source's wlan , the rate's second spelling: theset_fn behind a Synth's and a Segment'swlan .

const char * dp_wfm_source_set_wlan (
    wfm_source_t * src,
    int wlan
) 

On an ofdm source whose pair is given, a nonzero wlan is refused, the struct untouched: "the rate is set by constellation and code_rate: set either to auto (which returns the pair to auto) before setting wlan". It is the mirror of a half set beside wlan (dp_wfm_source_set_constellation()). 0 is always written, and so is any value on another type. On an ofdm source, a wlan no row of the table names is refused at the write, the struct untouched, with dp_wfm_source_rate_why()'s sentence.

Parameters:

  • src The source.
  • wlan 0, or a data rate at 20 MHz in Mb/s.

Returns:

NULL after writing, or a static sentence with src untouched.


function dp_wfm_source_sync_refuse_text

Refuse text for the retired sync= : a sync word is a field of the frame description.

size_t dp_wfm_source_sync_refuse_text (
    const char * text,
    uint8_t * out,
    size_t max_out,
    const char ** why
) 

The coercion hook of the sync tombstone: ANY str reaching it is refused, and a non-empty array is refused by dp_wfm_source_error, so sync= fails whatever it is given and the sentence names frame=.

Parameters:

  • text the str (unused: every str is refused).
  • out unused.
  • max_out unused.
  • why receives the sentence.

Returns:


function dp_wfm_source_synth_type

The synth type to create this source with.

int dp_wfm_source_synth_type (
    const wfm_source_t * src
) 

The source's own type, except for a FRAMED bpsk/qpsk/pn: that one transmits its frame, and the only synth that plays a bit pattern is a WFM_SYNTH_BITS one (dp_wfm_synth_set_bits() is a no-op on any other), so it is created as BITS and dp_wfm_source_attach_frame() hands it the frame with the mapping the type names (bpsk for bpsk/pn, Gray QPSK for qpsk). Created with its own type it played the LFSR stream and dropped the frame (doppler#1616).

Asked by both construction faces (dp_wfm_compose_build_synth and the standalone dp_wfm_source_to_synth) and by dp_wfm_source_create_snr(), which refers such a source's SNR to fs so its noise stays in the reference its type names.

wfm_source_t s = { .type = WFM_SYNTH_BPSK };
int t = dp_wfm_source_synth_type (&s); // unframed: WFM_SYNTH_BPSK

Parameters:

  • src The source.

Returns:

A WFM_SYNTH_* type.


function dp_wfm_source_to_synth_error

Why dp_wfm_source_to_synth() refused this source, or NULL.

const char * dp_wfm_source_to_synth_error (
    const wfm_source_t * src,
    double fs
) 

The standalone Synth's reason channel (just-makeit's bridge_error_fn, which takes the bridge's own arguments): dp_wfm_scene_error() of a scene of one segment at fs, so a refused Synth raises the same sentence as every other face, including a rule that needs the rate. NULL leaves the binding's generic error, for a refusal that is not the source's.

Parameters:

  • src The source.
  • fs The sample rate the bridge was given.

Returns:

A static sentence, or NULL.

wfm_source_t s = { .type = WFM_SYNTH_PN, .sps = 1, .pn_length = 5,
                   .pn_poly = 0x40 };
dp_wfm_source_to_synth_error (&s, 1e6);   // dp_wfm_why_pn_poly

function dp_wfm_source_window

The window an ofdm source renders with, in samples at the output rate: the count it holds, or the standard's for an unset one.

size_t dp_wfm_source_window (
    const wfm_source_t * src,
    double fs
) 

WFM_WINDOW_UNSET gives 2 * fs / bandwidth (the 100 ns transition, 17.3.2.5, which dp_wlan_window_resolve gives Wlan at the same oversampling); any other count, 0 included, is returned as it is, so the explicit rectangular window stays. When fs is not a whole multiple of the bandwidth, or the multiple is above 128 (WLAN_OVERSAMPLE_MAX), there is no oversampling to scale by, and the unset value comes back unchanged for dp_wfm_ofdm_fs_error() to refuse; a count it returns is never above 2 * 128. A source whose type is not ofdm (WFM_SYNTH_FRAMES) and whose window is unset returns 0: it renders with no window. The one place the default is defined for this face: the renderer, the scene and the record each call it, so none holds an unset window.

Parameters:

  • src The source.
  • fs The segment's sample rate, Hz.

Returns:

The count of samples.

#include <doppler/wfm/wfm_defaults.h>   // WFM_SOURCE_DEFAULTS

wfm_source_t s = WFM_SOURCE_DEFAULTS;   // window unset
printf ("%zu\n", dp_wfm_source_window (&s, 80e6));   // 8: 2 * (80 / 20)
s.window = 0;
printf ("%zu\n", dp_wfm_source_window (&s, 80e6));   // 0: rectangular

function dp_wfm_spec_headroom

The top-level headroom (dB) from a spec JSON, or 0 if absent.

double dp_wfm_spec_headroom (
    const char * json
) 

Lets --from-file reproduce a recorded --headroom; the value is a writer gain, so it lives outside the composer state.

Parameters:

  • json The spec text, NUL-terminated.

Returns:

The headroom value in dB; 0.0 when the key is absent or the text does not parse as JSON.


function dp_wfm_spec_template_json

A ready-to-edit example spec in the canonical from-file schema.

char * dp_wfm_spec_template_json (
    void
) 

Returns a representative multi-segment template — an inline tone, an RRC-shaped QPSK-from-bits burst with a trailing gap, and a two-source additive sum mix — serialised with dp_wfm_spec_to_json(), so it is valid by construction and round-trips through dp_wfm_compose_from_json() unchanged. It therefore doubles as a working starting point for wfmgen --from-file, not just documentation: dump it, edit the fields, feed it back.

Returns:

malloc'd JSON (caller frees), or NULL on allocation failure.


function dp_wfm_spec_to_json

Serialise a spec to a JSON string (for record).

char * dp_wfm_spec_to_json (
    const wfm_segment_t * segs,
    size_t n_segs,
    int repeat,
    int continuous,
    int seed_advance,
    double headroom
) 

seed_advance (a wfm_seed_advance_t) and headroom (dB of output backoff applied at the writer, not the composer) are each emitted as a top-level field only when non-default, so an unrecorded run and any older spec stay byte-identical. Read headroom back with dp_wfm_spec_headroom(); the parser reads seed_advance straight onto the composer.

seed_advance is a parameter rather than something read from segs because it is a property of the whole stream, like repeat/continuous. Omitting it is what made a recorded run replay a DIFFERENT waveform (doppler#978): the key was parsed and never written, so the round-trip silently fell back to NONE and every loop after the first came out identical.

Parameters:

  • segs The segments to write (typically dp_wfm_compose_segments() of a live composer).
  • n_segs Number of segments.
  • repeat Written as the top-level boolean repeat.
  • continuous Written as the top-level boolean continuous.
  • seed_advance A wfm_seed_advance_t; written as "noise" / "all", omitted at NONE or an out-of-range value.
  • headroom Output backoff in dB; omitted when exactly 0.

Returns:

malloc'd JSON (caller frees), or NULL on allocation failure.


function dp_wfm_synth_attach_data

Drive a type=bits synth from a frame whose payload is a data source.

int dp_wfm_synth_attach_data (
    dp_wfm_synth_state_t * syn,
    const wfm_frame_desc_t * d,
    const wfm_frame_ops_t * ops,
    wfm_data_src_t * src,
    wfm_data_pacing_t pacing,
    int modulation
) 

The pull that replaces the cycle (docs/design/payload-data-source.md §7). Each frame is d assembled over the next chunk of src (dp_wfm_frame_assemble_data): the first now, and each one after at the previous frame's last bit, so every stage over the payload covers its own frame's chunk. Under pacing, a source with nothing yet sends an idle frame (dp_wfm_data_frame, the one rule). When src ends, the synth goes silent and dp_wfm_synth_data_ended() says so.

Parameters:

  • syn a synth created with type=bits.
  • d the frame; exactly one field is data:LEN, and LEN is the source's.
  • ops stage kernels, as dp_wfm_frame_assemble(); may be NULL.
  • src the data source; the synth OWNS it from here, success or not, and frees it with the synth.
  • pacing WFM_DATA_PACED for --realtime, else WFM_DATA_UNPACED.
  • modulation as dp_wfm_synth_set_bits().

Returns:

0, or -1: not a bits synth, no data field in d, a frame that does not assemble, or a source that failed its first read.

wfm_frame_desc_t d;
const wfm_seq_t  data = { .kind = WFM_SEQ_DATA, .len = 16 };
dp_wfm_frame_fixed (&d, NULL, 0, NULL, &data, 1);        // [data:16 | crc]
wfm_data_src_t *src = dp_wfm_data_create ("0x0123456789AB", NULL, 16, NULL,
                                          NULL);
dp_wfm_synth_state_t *s
    = dp_wfm_synth_create (WFM_SYNTH_BITS, 1e6, 0.0, 100.0, 0, 1, 8, 7, 0,
                           0, 0.0);
dp_wfm_synth_attach_data (s, &d, NULL, src, WFM_DATA_UNPACED, 1); // bpsk
// three 32-bit frames, each over its own 16-bit chunk, then silence
dp_wfm_synth_destroy (s);                 // frees src too

function dp_wfm_synth_data_source

The data source a synth pulls from (dp_wfm_synth_attach_data), or NULL: its stats are the run's truth for scoring.

const wfm_data_src_t * dp_wfm_synth_data_source (
    const dp_wfm_synth_state_t * syn
) 

Parameters:

  • syn The synth; NULL gives NULL.

Returns:

The source, still owned by the synth (valid until it is destroyed), or NULL when the synth has no data source attached.


function dp_wfm_synth_set_data_pacing

Pace a synth's data source: WFM_DATA_PACED for --realtime .

void dp_wfm_synth_set_data_pacing (
    dp_wfm_synth_state_t * syn,
    wfm_data_pacing_t pacing
) 

A synth attached by dp_wfm_source_attach_frame() pulls UNPACED it waits for its data, as cat does. A paced caller (the composer under --realtime) sets this after the build, so a source with nothing yet sends an idle frame instead (dp_wfm_data_frame, the one rule). A synth with no data source ignores it, and so does a NULL syn.

Parameters:

  • syn The synth; NULL, or one with no data source, is a no-op.
  • pacing WFM_DATA_PACED to send idle frames while the source has nothing, WFM_DATA_UNPACED to wait for it.
dp_wfm_synth_state_t *s = dp_wfm_synth_create (
    WFM_SYNTH_BITS, 1e6, 0.0, 100.0, 0, 1, 8, 7, 0, 0, 0.0);
dp_wfm_synth_set_data_pacing (s, WFM_DATA_PACED); // no source: no-op
dp_wfm_synth_destroy (s);

Public Static Functions Documentation

function dp_wfm_scene_fs

The ONE answer to "what is this stream's sample rate": the fs every segment shares, or 0.0 when they differ.

static inline double dp_wfm_scene_fs (
    const wfm_segment_t * segs,
    size_t n_segs
) 

fs is per segment, and a scene whose segments differ is legal: no single rate is true of it. 0.0 is the library's "not stated" (a Writer opened at fs=0.0, a SigMF document without core:sample_rate), so an output asks this and either states the rate it returns or, given 0.0, says nothing or refuses, if its format cannot say nothing (a BLUE header has one xdelta). Every output asks here rather than reading segs[0].fs, which is a rate only when they agree (doppler#1733).

wfm_segment_t s[2] = { { .fs = 6e6 }, { .fs = 6e6 } };
int ok = dp_wfm_scene_fs (s, 2) == 6e6;
s[1].fs = 2e6;
ok = ok && dp_wfm_scene_fs (s, 2) == 0.0 && dp_wfm_scene_fs (s, 0) == 0.0;
return ok ? 0 : 1;

Parameters:

  • segs the segments; may be NULL when n_segs is 0.
  • n_segs their count.

Returns:

the shared fs, or 0.0 when the segments differ or there are none.


function dp_wfm_scene_segments

dp_wfm_compose_segments() for a caller that does not link the composer: dispatched through the state's own wfm_scene_ops_t.

static inline const wfm_segment_t * dp_wfm_scene_segments (
    const dp_wfm_compose_state_t * scene,
    size_t * n_out
) 

Parameters:

Returns:

the composer's internal segments, as dp_wfm_compose_segments().


Macro Definition Documentation

define WFM_NUM_SAMPLES_PLAIN

A plain segment's on-time when its num_samples is 0 and no source sets one: what--count , a scene andSegment default to.

#define WFM_NUM_SAMPLES_PLAIN `((size_t)1024)`


define WFM_SEGMENT_FS_DEFAULT

A segment's sample rate when none is given, Hz: 1.0, every frequency normalised. The manifest default of wfm_segment_t.fs (WFM_SEGMENT_DEFAULTS ), named so the ofdm rule reads a name: for an ofdm source it reads as unset and becomes the bandwidth (dp_wfm_source_ofdm_defaults() ). A test holds the two equal.

#define WFM_SEGMENT_FS_DEFAULT `1.0`


define WFM_WINDOW_UNSET

The window of an ofdm source that nobody set: the 100 ns default,2 * fs / bandwidth samples.

#define WFM_WINDOW_UNSET `SIZE_MAX`

It is the manifest default of wfm_source_t.window, so a source a face builds starts unset, and 0 stays the explicit rectangular window (a C caller that zero-initializes a source gets it). A count of samples is never this large: the range is 0 to 80 * fs / bandwidth, at most 80 * 128. dp_wfm_source_window() turns it into the count.



The documentation for this class was generated from the following file native/inc/doppler/wfm/wfm_compose.h