This commit is contained in:
2026-06-15 22:31:07 +02:00
parent 1513fd694d
commit 2d49da5cee
4 changed files with 4546 additions and 15 deletions

View File

@ -28,12 +28,14 @@ pub struct FileSource {
pub chunk_samples_size: usize,
// raw_buffer position (in samples)
pub cursor: usize,
// The length of the file in samples
pub len: u64,
}
impl FileSource {
pub fn new(file_path: &str, chunk_samples_size: usize) -> Result<Self, Box<dyn Error>> {
let file = File::open(file_path)?;
let len = file.metadata().unwrap().len() / 2;
// Init buffer with size 16 Mo
let reader = BufReader::with_capacity(16 * 1024 * 1024, file);
@ -45,13 +47,20 @@ impl FileSource {
raw_buffer: raw_reader,
chunk_samples_size,
cursor: chunk_samples_size,
len,
})
}
}
impl ExactSizeIterator for FileSource {}
impl Iterator for FileSource {
type Item = Result<IqSample, Box<dyn Error>>;
fn size_hint(&self) -> (usize, Option<usize>) {
(self.len as usize, Some(self.len as usize))
}
fn next(&mut self) -> Option<Self::Item> {
if self.cursor >= self.chunk_samples_size {
// Buffer read chunk