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
impl MultiSignalReader
Sourcepub fn read_frame(&mut self) -> Result<Vec<Sample>>
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
Sourcepub fn read_frames(&mut self, count: usize) -> Result<Vec<Vec<Sample>>>
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}Sourcepub fn read_frames_physical(&mut self, count: usize) -> Result<Vec<Vec<f64>>>
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
Sourcepub const fn num_signals(&self) -> usize
pub const fn num_signals(&self) -> usize
Get number of signals.
Sourcepub fn seek_to_frame(&mut self, frame: u64) -> Result<u64>
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}Sourcepub const fn position(&self) -> u64
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§
impl !RefUnwindSafe for MultiSignalReader
impl !Sync for MultiSignalReader
impl !UnwindSafe for MultiSignalReader
impl Freeze for MultiSignalReader
impl Send for MultiSignalReader
impl Unpin for MultiSignalReader
impl UnsafeUnpin for MultiSignalReader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more