Clippy fixes

This commit is contained in:
Anne de Jong 2024-07-18 13:34:37 +02:00
parent f3dbf9d948
commit d3c162ab79
8 changed files with 30 additions and 38 deletions

View File

@ -689,7 +689,7 @@ impl CpalApi {
let max_sr = cpalcfg.max_sample_rate().0;
let min_sr = cpalcfg.min_sample_rate().0;
if samplerate <= max_sr && samplerate >= min_sr {
let cfg = cpalcfg.with_sample_rate(SampleRate(samplerate as u32));
let cfg = cpalcfg.with_sample_rate(SampleRate(samplerate));
let mut cfg = cfg.config();
cfg.channels = highest_ch + 1;

View File

@ -162,27 +162,27 @@ impl Recording {
) -> Result<()> {
match data.getRaw() {
RawStreamData::Datai8(dat) => {
let arr = ndarray::ArrayView2::<i8>::from_shape((framesPerBlock, nchannels), &dat)?;
let arr = ndarray::ArrayView2::<i8>::from_shape((framesPerBlock, nchannels), dat)?;
ds.write_slice(arr, (ctr, .., ..))?;
}
RawStreamData::Datai16(dat) => {
let arr =
ndarray::ArrayView2::<i16>::from_shape((framesPerBlock, nchannels), &dat)?;
ndarray::ArrayView2::<i16>::from_shape((framesPerBlock, nchannels), dat)?;
ds.write_slice(arr, (ctr, .., ..))?;
}
RawStreamData::Datai32(dat) => {
let arr =
ndarray::ArrayView2::<i32>::from_shape((framesPerBlock, nchannels), &dat)?;
ndarray::ArrayView2::<i32>::from_shape((framesPerBlock, nchannels), dat)?;
ds.write_slice(arr, (ctr, .., ..))?;
}
RawStreamData::Dataf32(dat) => {
let arr =
ndarray::ArrayView2::<f32>::from_shape((framesPerBlock, nchannels), &dat)?;
ndarray::ArrayView2::<f32>::from_shape((framesPerBlock, nchannels), dat)?;
ds.write_slice(arr, (ctr, .., ..))?;
}
RawStreamData::Dataf64(dat) => {
let arr =
ndarray::ArrayView2::<f64>::from_shape((framesPerBlock, nchannels), &dat)?;
ndarray::ArrayView2::<f64>::from_shape((framesPerBlock, nchannels), dat)?;
ds.write_slice(arr, (ctr, .., ..))?;
}
}

View File

@ -130,12 +130,12 @@ impl InStreamData {
#[inline]
/// Return reference to underlying raw data storage
pub fn getRaw(&self) -> &RawStreamData {
return &self.raw;
&self.raw
}
#[inline]
/// Convenience function to return the number of channels in this instreamdata.
pub fn nchannels(&self) -> usize {
return self.meta.nchannels();
self.meta.nchannels()
}
/// Iterate over raw data of a certain channel. Tye should be specificied
/// and if not set correctly, this results in undefined behavior
@ -185,11 +185,10 @@ impl InStreamData {
{
Box::new(
(0..self.meta.nchannels())
.into_iter()
.flat_map(|chi| self.iter_channel_raw(chi)),
)
}
fn iter_channel_converted<'a, T>(&'a self, ch: usize) -> impl Iterator<Item = Flt> + 'a
fn iter_channel_converted<T>(&self, ch: usize) -> impl Iterator<Item = Flt> + '_
where
T: Sample + Copy + 'static,
Flt: FromSample<T>,
@ -208,7 +207,6 @@ impl InStreamData {
{
Box::new(
(0..self.meta.nchannels())
.into_iter()
.flat_map(move |chi| self.iter_channel_converted(chi)),
)
}
@ -232,19 +230,19 @@ impl InStreamData {
let nch = self.meta.nchannels();
match &self.raw {
RawStreamData::Datai8(c) => {
return c.len() / nch;
c.len() / nch
}
RawStreamData::Datai16(c) => {
return c.len() / nch;
c.len() / nch
}
RawStreamData::Datai32(c) => {
return c.len() / nch;
c.len() / nch
}
RawStreamData::Dataf32(c) => {
return c.len() / nch;
c.len() / nch
}
RawStreamData::Dataf64(c) => {
return c.len() / nch;
c.len() / nch
}
}
}

View File

@ -227,13 +227,13 @@ impl Filter for Biquad {
impl<'a, T: AsArray<'a, Flt>> TransferFunction<'a, T> for Biquad {
fn tf(&self, fs: Flt, freq: T) -> Ccol {
let freq = freq.into();
let res = freq.mapv(|f| {
freq.mapv(|f| {
let z = Complex::exp(I * 2. * pi * f / fs);
let num = self.b0 + self.b1 / z + self.b2 / z / z;
let den = 1. + self.a1 / z + self.a2 / z / z;
num / den
});
res
})
}
}

View File

@ -26,9 +26,11 @@ impl Default for Overlap {
/// The 'mode' used in computing averaged power spectra. When providing data in
/// blocks to the [AvPowerSpectra] the resulting 'current estimate' responds
/// differently, depending on the model.
#[derive(Default)]
pub enum ApsMode {
/// Averaged over all data provided. New averages can be created by calling
/// `AvPowerSpectra::reset()`
#[default]
AllAveraging,
/// In this mode, the `AvPowerSpectra` works a bit like a sound level meter,
/// where new data is weighted with old data, and old data exponentially
@ -44,11 +46,6 @@ pub enum ApsMode {
/// Spectrogram mode. Only returns the latest estimate(s).
Spectrogram,
}
impl Default for ApsMode {
fn default() -> Self {
ApsMode::AllAveraging
}
}
/// Averaged power spectra computing engine
/// Used to compute power spectra estimations on
@ -93,7 +90,7 @@ impl AvPowerSpectra {
Overlap::Number(i) if i < nfft => i,
// If overlap percentage is >= 100, or < 0.0 its an error
Overlap::Percentage(p) if p >= 100. || p < 0.0 => {
Overlap::Percentage(p) if !(0.0..100.).contains(&p) => {
bail!("Invalid overlap percentage. Should be >= 0. And < 100.")
}
// If overlap percentage is 0, this gives
@ -196,11 +193,11 @@ impl AvPowerSpectra {
T: AsArray<'a, Flt, Ix2>,
{
let timeblock = timedata.into();
let Cpsnew = self.ps.compute(&timeblock);
let Cpsnew = self.ps.compute(timeblock);
// println!("Cpsnew: {:?}", Cpsnew[[0, 0, 0]]);
// Initialize to zero
if self.cur_est.len() == 0 {
if self.cur_est.is_empty() {
assert_eq!(self.N, 0);
self.cur_est = CPSResult::zeros(Cpsnew.raw_dim().f());
}

View File

@ -32,7 +32,7 @@ impl TimeBuffer {
{
let new_data = new_data.into();
let nch = new_data.shape()[1];
if self.data.len() == 0 {
if self.data.is_empty() {
self.data = vec![VecDeque::new(); nch];
}
if self.data.len() != nch {
@ -45,7 +45,7 @@ impl TimeBuffer {
}
/// Return the number of samples that is currently stored
pub fn nsamples(&self) -> usize {
if let Some(q) = self.data.get(0) {
if let Some(q) = self.data.first() {
return q.len();
};
0
@ -54,14 +54,14 @@ impl TimeBuffer {
/// enough samples to return. Never returns less samples than
/// `nsamples_requested`.
pub fn pop(&mut self, nsamples_requested: usize, nsamples_keep: usize) -> Option<Dmat> {
if self.data.len() == 0 {
if self.data.is_empty() {
return None;
}
if nsamples_keep > nsamples_requested {
panic!("BUG: Cannot keep more samples than requested to return");
}
debug_assert!(self.data.len() > 0);
debug_assert!(!self.data.is_empty());
let c1 = unsafe { self.data.get_unchecked(0) };
let nsamples_available = c1.len();
@ -91,7 +91,7 @@ impl TimeBuffer {
} else {
let slice1len = dat_slice1.len();
// Copy from first slice
col_slice[..slice1len].copy_from_slice(&dat_slice1);
col_slice[..slice1len].copy_from_slice(dat_slice1);
// Copy rest from second slice
col_slice[slice1len..nsamples_requested]
.copy_from_slice(&dat_slice2[..nsamples_requested - slice1len]);

View File

@ -73,8 +73,10 @@ fn hamming(N: usize) -> Dcol {
///
/// The [WindowType::default] is [WindowType::Hann].
#[derive(Display, Clone, Debug)]
#[derive(Default)]
pub enum WindowType {
/// Von Hann window
#[default]
Hann = 0,
/// Hamming window
Hamming = 1,
@ -85,11 +87,6 @@ pub enum WindowType {
/// Blackman window
Blackman = 4,
}
impl Default for WindowType {
fn default() -> Self {
WindowType::Hann
}
}
/// Window (taper) computed from specified window type.
#[derive(Clone)]

View File

@ -106,7 +106,7 @@ impl RtAps {
if let Some(RtApsComm::CommStopThread) = res {
panic!("BUG: CommStopThread should never be set!")
}
return lck.take();
lck.take()
}
}
impl Drop for RtAps {