samcrow / uhd-rust

Rust bindings to the UHD (USRP Hardware Driver) library
13 stars 12 forks source link

Different rates tricky with const required in alloc_boxed_slice #5

Closed varenius closed 1 year ago

varenius commented 1 year ago

Apologies if this is more of a rust question (me being a newbie) than a uhd-rust question, but: I want to build an app where I can do measurements with the USRP with different sample rates (and integration times). Copying from the example receive.rs I fail at https://github.com/samcrow/uhd-rust/blob/master/uhd/examples/receive.rs#L33 which requires a "const" number of samples. Could you please offer a suggestion for how to allow different sample numbers, i.e. what buffer creation method to use instead?

samcrow commented 1 year ago

The buffer argument to the receive_simple function can be anything that derefs to &mut [I]. The simplest way to have a buffer size determined at runtime is to use a Vec<Complex<i16>>. You can create this with vec![Complex::<i16>::default(); samples] where samples is a variable.

varenius commented 1 year ago

Excellent, many thanks! And great work publishing this uhd-rust crate, it will be immensly useful!