Skip to main content

Module data

Module data 

Source
Expand description

Encoding and decoding of raw SigMF sample data.

A SigMF dataset is a sequence of frames. A frame holds one sample for each of the core:num_channels channels, stored channel after channel; complex samples store their real (I) component before their imaginary (Q) component. The layout of each component is given by a Datatype.

Decoded samples are represented as a flat list of SampleValues in the same order as on disk: frame 0 channel 0, frame 0 channel 1, …, frame 1 channel 0, and so on. A list of samples therefore always holds a multiple of the channel count.

use num_complex::Complex;
use sigmf::datatype::Datatype;
use sigmf::utils::data::{decode, encode, SampleValue};
use std::str::FromStr;

let datatype = Datatype::from_str("ci16_le")?;
// Two channels, two frames.
let samples = vec![
    SampleValue::ComplexI16(Complex::new(1, -1)),
    SampleValue::ComplexI16(Complex::new(2, -2)),
    SampleValue::ComplexI16(Complex::new(3, -3)),
    SampleValue::ComplexI16(Complex::new(4, -4)),
];
let bytes = encode(&samples, &datatype, 2)?;
assert_eq!(bytes.len(), 4 * 2 * 2);
assert_eq!(&bytes[..4], &[1, 0, 0xff, 0xff]);
assert_eq!(decode(&bytes, &datatype, 2)?, samples);

Structs§

SampleReader
Streams frames of samples out of a Read source.
SampleWriter
Streams frames of samples into a Write destination.

Enums§

SampleValue
One sample on one channel, typed by its datatype.

Functions§

bytes_per_frame
Returns the size in bytes of one frame of channel_count channels.
decode
Decodes a block of complete frames into samples.
encode
Encodes complete frames of samples into raw bytes.
frame_count
Returns the number of frames in dataset_bytes bytes of sample data.