raw sound samples with rayon

This commit is contained in:
Breval Ferrari 2025-03-10 11:06:07 -04:00
parent 76ced9bb9d
commit 58cf13a564
No known key found for this signature in database
GPG key ID: F71E304D6400AB8E

View file

@ -4,6 +4,7 @@ use num::{
traits::{FromBytes, ToBytes},
Zero,
};
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
use crate::{Bendable, IntoDataBytes, TryFromDataBytes};
@ -65,12 +66,13 @@ where
impl<T> Bendable for RawSamples<T>
where
T: Sample + FromBytes + ToBytes + Zero,
T: Sample + FromBytes + ToBytes + Zero + Send,
<T as FromBytes>::Bytes: Sized + for<'a> TryFrom<&'a [u8]>,
for<'a> Vec<T>: IntoParallelRefMutIterator<'a, Item = &'a mut T>,
{
type Unit = T;
fn map<F: Fn(&Self::Unit) -> Self::Unit + Sync>(mut self, f: F) -> Self {
self.0.iter_mut().for_each(|e| *e = f(e));
self.0.par_iter_mut().for_each(|e| *e = f(e));
self
}
fn format() -> crate::dynamic::Format {