Compare commits

..

2 Commits

Author SHA1 Message Date
f3f99a412e start .iq reading 2026-06-10 23:19:52 +02:00
577bdc3bac ignore test.iq 2026-06-10 22:06:36 +02:00
5 changed files with 94 additions and 0 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/target /target
test.iq

34
Cargo.lock generated Normal file
View File

@ -0,0 +1,34 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "analog-sdr-video-demodulator"
version = "0.1.0"
dependencies = [
"num-complex",
]
[[package]]
name = "autocfg"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
[[package]]
name = "num-complex"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
dependencies = [
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]

View File

@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
num-complex = "0.4.6"

56
src/iq_reader.rs Normal file
View File

@ -0,0 +1,56 @@
use num_complex::Complex;
use std::error::Error;
use std::fs::File;
use std::io::{BufRead, BufReader, Read};
use std::os::unix::process::CommandExt;
pub type IqSample = Complex<f32>;
// Data chunk
pub struct IqChunk {
pub samples: Vec<IqSample>,
}
pub struct FileSource {
// Buffer
pub reader: BufReader<File>,
// Hackrf I & Q 8 bits
pub raw_buffer: Vec<u8>,
// Size of a sample chunk
pub chunk_samples_size: usize,
}
impl FileSource {
pub fn new(file_path: &str, chunk_samples_size: usize) -> Self {
let file = File::open(file_path).unwrap();
// Init buffer with size 16 Mo
let reader = BufReader::with_capacity(16 * 1024 * 1024, file);
// 1 sample = 2 bytes (1 byte : I, 1 byte : Q)
let raw_reader = vec![0; chunk_samples_size * 2];
Self {
reader,
raw_buffer: raw_reader,
chunk_samples_size,
}
}
pub fn read_chunk(&mut self) -> Option<IqChunk> {
// TODO : match for EOF
self.reader.read_exact(&mut self.raw_buffer);
// Output samples
let mut samples = Vec::with_capacity(self.chunk_samples_size);
// Buffer read
for iq in self.raw_buffer.chunks(2) {
let i = (iq[0] as f32) / 128.0;
let q = (iq[1] as f32) / 128.0;
samples.push(Complex::new(i, q));
}
Some(IqChunk { samples })
}
}

View File

@ -1,3 +1,5 @@
mod iq_reader;
fn main() { fn main() {
println!("Hello, world!"); println!("Hello, world!");
} }