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.
encodeanddecodeconvert whole in-memory blocks.SampleWriterandSampleReaderstream frames to aWriteor from aRead.bytes_per_frameandframe_countcompute dataset sizes.
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§
- Sample
Reader - Streams frames of samples out of a
Readsource. - Sample
Writer - Streams frames of samples into a
Writedestination.
Enums§
- Sample
Value - One sample on one channel, typed by its datatype.
Functions§
- bytes_
per_ frame - Returns the size in bytes of one frame of
channel_countchannels. - 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_bytesbytes of sample data.