MultiSignalReader

Struct MultiSignalReader 

Source
pub struct MultiSignalReader { /* private fields */ }
Expand description

Reader for multiple signals (frame-based).

Reads one frame at a time, where each frame contains one sample from each signal. Handles signals in different files and with different formats.

Implementations§

Source§

impl MultiSignalReader

Source

pub fn read_frame(&mut self) -> Result<Vec<Sample>>

Read one frame (one sample from each signal).

Returns a vector with num_signals samples, ordered by signal index.

§Errors

Returns an error if:

  • The frame cannot be read
  • The frame is incomplete
Source

pub fn read_frames(&mut self, count: usize) -> Result<Vec<Vec<Sample>>>

Read multiple frames.

§Errors

Returns an error if:

  • The frames cannot be read
  • The frames are incomplete
Examples found in repository?
examples/seek_record.rs (line 109)
38fn demonstrate_single_segment_seeking(record: &Record) -> wfdb::Result<()> {
39    println!("\n=== Single-Segment Record ===");
40    println!("Signals: {}", record.signal_count());
41
42    if record.signal_count() == 0 {
43        println!("No signals to read");
44        return Ok(());
45    }
46
47    let signal_idx = 0;
48    let signal_info = &record.signal_info().unwrap()[signal_idx];
49    println!(
50        "\nDemonstrating with Signal {}: {}",
51        signal_idx,
52        signal_info
53            .description
54            .as_deref()
55            .unwrap_or("(no description)")
56    );
57
58    println!("\n--- SignalReader: Sample-based Seeking ---");
59    let mut reader = record.signal_reader(signal_idx)?;
60
61    println!("Reading first 5 samples from start...");
62    let samples = reader.read_samples(5)?;
63    println!("  Samples 0-4: {samples:?}");
64    println!("  Current position: {}", reader.position());
65
66    println!("\nSeeking to sample 100...");
67    match reader.seek_to_sample(100) {
68        Ok(pos) => {
69            println!("  Seek to position: {pos}");
70            let samples = reader.read_samples(5)?;
71            println!("  Samples 100-104: {samples:?}");
72            println!("  Current position: {}", reader.position());
73
74            println!("\nSeeking backward to sample 50...");
75            reader.seek_to_sample(50)?;
76            let samples = reader.read_samples(3)?;
77            println!("  Samples 50-52: {samples:?}");
78            println!("  Current position: {}", reader.position());
79        }
80        Err(e) => {
81            println!("  Seeking not supported for this format: {e}");
82        }
83    }
84
85    println!("\n--- SignalReader: Time-based Seeking ---");
86    let mut reader = record.signal_reader(signal_idx)?;
87
88    println!("Seeking to 1.0 second...");
89    match reader.seek_to_time(1.0) {
90        Ok(pos) => {
91            println!("  Seek to sample position: {pos}");
92            println!(
93                "  (1.0 sec × {} Hz = {} samples)",
94                record.metadata().sampling_frequency(),
95                pos
96            );
97            let samples = reader.read_samples(3)?;
98            println!("  Samples at 1.0s: {samples:?}");
99        }
100        Err(e) => {
101            println!("  Time-based seeking failed: {e}");
102        }
103    }
104
105    println!("\n--- MultiSignalReader: Frame-based Seeking ---");
106    let mut multi_reader = record.multi_signal_reader()?;
107
108    println!("Reading first 3 frames...");
109    let frames = multi_reader.read_frames(3)?;
110    for (i, frame) in frames.iter().enumerate() {
111        println!("  Frame {i}: {frame:?}");
112    }
113    println!("  Current position: frame {}", multi_reader.position());
114
115    println!("\nSeeking to frame 50...");
116    match multi_reader.seek_to_frame(50) {
117        Ok(pos) => {
118            println!("  Seek to frame: {pos}");
119            let frames = multi_reader.read_frames(2)?;
120            for (i, frame) in frames.iter().enumerate() {
121                println!("  Frame {}: {:?}", 50 + i, frame);
122            }
123            println!("  Current position: frame {}", multi_reader.position());
124        }
125        Err(e) => {
126            println!("  Frame seeking not supported: {e}");
127        }
128    }
129
130    println!("\n--- Physical Units Conversion ---");
131    let mut reader = record.signal_reader(signal_idx)?;
132
133    println!(
134        "Signal gain: {} ADC units per {}",
135        reader.gain(),
136        reader.units()
137    );
138    println!("Signal baseline: {} ADC units", reader.baseline());
139
140    let adc_values = reader.read_samples(5)?;
141    println!("\nFirst 5 ADC values: {adc_values:?}");
142
143    reader.seek_to_sample(0)?;
144    let physical_values = reader.read_physical(5)?;
145    println!("First 5 physical values: {physical_values:?}");
146
147    println!("\nConversion example:");
148    for i in 0..adc_values.len().min(3) {
149        let adc = adc_values[i];
150        let physical = physical_values[i];
151        println!("  ADC {} → {} {}", adc, physical, reader.units());
152    }
153
154    Ok(())
155}
Source

pub fn read_frames_physical(&mut self, count: usize) -> Result<Vec<Vec<f64>>>

Read frames as physical values.

§Errors

Returns an error if:

  • The frames cannot be read
  • The frames are incomplete
Source

pub const fn num_signals(&self) -> usize

Get number of signals.

Source

pub fn seek_to_frame(&mut self, frame: u64) -> Result<u64>

Seek all signals to a specific frame (sample) number.

All signals are positioned atomically to the same frame. Returns the actual frame position after seeking.

§Errors

Returns an error if:

  • Seeking is not supported for any signal format
  • The seek operation fails
Examples found in repository?
examples/seek_record.rs (line 116)
38fn demonstrate_single_segment_seeking(record: &Record) -> wfdb::Result<()> {
39    println!("\n=== Single-Segment Record ===");
40    println!("Signals: {}", record.signal_count());
41
42    if record.signal_count() == 0 {
43        println!("No signals to read");
44        return Ok(());
45    }
46
47    let signal_idx = 0;
48    let signal_info = &record.signal_info().unwrap()[signal_idx];
49    println!(
50        "\nDemonstrating with Signal {}: {}",
51        signal_idx,
52        signal_info
53            .description
54            .as_deref()
55            .unwrap_or("(no description)")
56    );
57
58    println!("\n--- SignalReader: Sample-based Seeking ---");
59    let mut reader = record.signal_reader(signal_idx)?;
60
61    println!("Reading first 5 samples from start...");
62    let samples = reader.read_samples(5)?;
63    println!("  Samples 0-4: {samples:?}");
64    println!("  Current position: {}", reader.position());
65
66    println!("\nSeeking to sample 100...");
67    match reader.seek_to_sample(100) {
68        Ok(pos) => {
69            println!("  Seek to position: {pos}");
70            let samples = reader.read_samples(5)?;
71            println!("  Samples 100-104: {samples:?}");
72            println!("  Current position: {}", reader.position());
73
74            println!("\nSeeking backward to sample 50...");
75            reader.seek_to_sample(50)?;
76            let samples = reader.read_samples(3)?;
77            println!("  Samples 50-52: {samples:?}");
78            println!("  Current position: {}", reader.position());
79        }
80        Err(e) => {
81            println!("  Seeking not supported for this format: {e}");
82        }
83    }
84
85    println!("\n--- SignalReader: Time-based Seeking ---");
86    let mut reader = record.signal_reader(signal_idx)?;
87
88    println!("Seeking to 1.0 second...");
89    match reader.seek_to_time(1.0) {
90        Ok(pos) => {
91            println!("  Seek to sample position: {pos}");
92            println!(
93                "  (1.0 sec × {} Hz = {} samples)",
94                record.metadata().sampling_frequency(),
95                pos
96            );
97            let samples = reader.read_samples(3)?;
98            println!("  Samples at 1.0s: {samples:?}");
99        }
100        Err(e) => {
101            println!("  Time-based seeking failed: {e}");
102        }
103    }
104
105    println!("\n--- MultiSignalReader: Frame-based Seeking ---");
106    let mut multi_reader = record.multi_signal_reader()?;
107
108    println!("Reading first 3 frames...");
109    let frames = multi_reader.read_frames(3)?;
110    for (i, frame) in frames.iter().enumerate() {
111        println!("  Frame {i}: {frame:?}");
112    }
113    println!("  Current position: frame {}", multi_reader.position());
114
115    println!("\nSeeking to frame 50...");
116    match multi_reader.seek_to_frame(50) {
117        Ok(pos) => {
118            println!("  Seek to frame: {pos}");
119            let frames = multi_reader.read_frames(2)?;
120            for (i, frame) in frames.iter().enumerate() {
121                println!("  Frame {}: {:?}", 50 + i, frame);
122            }
123            println!("  Current position: frame {}", multi_reader.position());
124        }
125        Err(e) => {
126            println!("  Frame seeking not supported: {e}");
127        }
128    }
129
130    println!("\n--- Physical Units Conversion ---");
131    let mut reader = record.signal_reader(signal_idx)?;
132
133    println!(
134        "Signal gain: {} ADC units per {}",
135        reader.gain(),
136        reader.units()
137    );
138    println!("Signal baseline: {} ADC units", reader.baseline());
139
140    let adc_values = reader.read_samples(5)?;
141    println!("\nFirst 5 ADC values: {adc_values:?}");
142
143    reader.seek_to_sample(0)?;
144    let physical_values = reader.read_physical(5)?;
145    println!("First 5 physical values: {physical_values:?}");
146
147    println!("\nConversion example:");
148    for i in 0..adc_values.len().min(3) {
149        let adc = adc_values[i];
150        let physical = physical_values[i];
151        println!("  ADC {} → {} {}", adc, physical, reader.units());
152    }
153
154    Ok(())
155}
Source

pub const fn position(&self) -> u64

Get current frame position.

Examples found in repository?
examples/seek_record.rs (line 113)
38fn demonstrate_single_segment_seeking(record: &Record) -> wfdb::Result<()> {
39    println!("\n=== Single-Segment Record ===");
40    println!("Signals: {}", record.signal_count());
41
42    if record.signal_count() == 0 {
43        println!("No signals to read");
44        return Ok(());
45    }
46
47    let signal_idx = 0;
48    let signal_info = &record.signal_info().unwrap()[signal_idx];
49    println!(
50        "\nDemonstrating with Signal {}: {}",
51        signal_idx,
52        signal_info
53            .description
54            .as_deref()
55            .unwrap_or("(no description)")
56    );
57
58    println!("\n--- SignalReader: Sample-based Seeking ---");
59    let mut reader = record.signal_reader(signal_idx)?;
60
61    println!("Reading first 5 samples from start...");
62    let samples = reader.read_samples(5)?;
63    println!("  Samples 0-4: {samples:?}");
64    println!("  Current position: {}", reader.position());
65
66    println!("\nSeeking to sample 100...");
67    match reader.seek_to_sample(100) {
68        Ok(pos) => {
69            println!("  Seek to position: {pos}");
70            let samples = reader.read_samples(5)?;
71            println!("  Samples 100-104: {samples:?}");
72            println!("  Current position: {}", reader.position());
73
74            println!("\nSeeking backward to sample 50...");
75            reader.seek_to_sample(50)?;
76            let samples = reader.read_samples(3)?;
77            println!("  Samples 50-52: {samples:?}");
78            println!("  Current position: {}", reader.position());
79        }
80        Err(e) => {
81            println!("  Seeking not supported for this format: {e}");
82        }
83    }
84
85    println!("\n--- SignalReader: Time-based Seeking ---");
86    let mut reader = record.signal_reader(signal_idx)?;
87
88    println!("Seeking to 1.0 second...");
89    match reader.seek_to_time(1.0) {
90        Ok(pos) => {
91            println!("  Seek to sample position: {pos}");
92            println!(
93                "  (1.0 sec × {} Hz = {} samples)",
94                record.metadata().sampling_frequency(),
95                pos
96            );
97            let samples = reader.read_samples(3)?;
98            println!("  Samples at 1.0s: {samples:?}");
99        }
100        Err(e) => {
101            println!("  Time-based seeking failed: {e}");
102        }
103    }
104
105    println!("\n--- MultiSignalReader: Frame-based Seeking ---");
106    let mut multi_reader = record.multi_signal_reader()?;
107
108    println!("Reading first 3 frames...");
109    let frames = multi_reader.read_frames(3)?;
110    for (i, frame) in frames.iter().enumerate() {
111        println!("  Frame {i}: {frame:?}");
112    }
113    println!("  Current position: frame {}", multi_reader.position());
114
115    println!("\nSeeking to frame 50...");
116    match multi_reader.seek_to_frame(50) {
117        Ok(pos) => {
118            println!("  Seek to frame: {pos}");
119            let frames = multi_reader.read_frames(2)?;
120            for (i, frame) in frames.iter().enumerate() {
121                println!("  Frame {}: {:?}", 50 + i, frame);
122            }
123            println!("  Current position: frame {}", multi_reader.position());
124        }
125        Err(e) => {
126            println!("  Frame seeking not supported: {e}");
127        }
128    }
129
130    println!("\n--- Physical Units Conversion ---");
131    let mut reader = record.signal_reader(signal_idx)?;
132
133    println!(
134        "Signal gain: {} ADC units per {}",
135        reader.gain(),
136        reader.units()
137    );
138    println!("Signal baseline: {} ADC units", reader.baseline());
139
140    let adc_values = reader.read_samples(5)?;
141    println!("\nFirst 5 ADC values: {adc_values:?}");
142
143    reader.seek_to_sample(0)?;
144    let physical_values = reader.read_physical(5)?;
145    println!("First 5 physical values: {physical_values:?}");
146
147    println!("\nConversion example:");
148    for i in 0..adc_values.len().min(3) {
149        let adc = adc_values[i];
150        let physical = physical_values[i];
151        println!("  ADC {} → {} {}", adc, physical, reader.units());
152    }
153
154    Ok(())
155}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.