pub fn write_edf_bytes(signal: &[Vec<i64>], fs: f64) -> Option<Vec<u8>>Expand description
Build a minimal, spec-valid EDF byte image for signal at rate fs.
One data record holds every channel’s samples (record_duration
chosen so the stored rate matches fs). Returns None when the signal
cannot be expressed as EDF digital samples: non-i16 values, ragged
channels, or an empty / zero-length signal. The layout mirrors
crate::edf::read_edf’s parser exactly, so the EDF this writes reads
back identically.
Examples found in repository?
examples/gen_smoke_corpus.rs (line 67)
50fn main() {
51 // (file name, channels, samples/channel, fs) — small + diverse shapes.
52 let specs: &[(&str, usize, usize, f64)] = &[
53 ("synthetic_a.edf", 4, 1024, 256.0),
54 ("synthetic_b.edf", 6, 768, 128.0),
55 ("synthetic_c.edf", 2, 512, 256.0),
56 ];
57
58 let out_dir: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
59 .join("corpora")
60 .join("smoke");
61 std::fs::create_dir_all(&out_dir).expect("create corpora/smoke");
62
63 println!("# Generated by `cargo run --example gen_smoke_corpus`.");
64 println!("# Paste the [[file]] blocks below into corpora/ecs-smoke.toml.\n");
65 for (name, n_chan, n_samp, fs) in specs {
66 let sig = signal(*n_chan, *n_samp, *fs);
67 let edf = write_edf_bytes(&sig, *fs).expect("synthetic signal -> EDF");
68 let path = out_dir.join(name);
69 std::fs::write(&path, &edf).expect("write edf");
70 let sha = sha256_hex(&edf);
71 println!("[[file]]");
72 println!("path = \"smoke/{name}\"");
73 println!("sha256 = \"{sha}\"");
74 println!("fs = {fs:.1}");
75 println!("n_chan = {n_chan}");
76 println!("n_samples = {n_samp}");
77 println!();
78 eprintln!("wrote {} ({} bytes, sha {})", path.display(), edf.len(), &sha[..12]);
79 }
80}