pub struct GpuSpectrogram { /* private fields */ }Expand description
GPU-accelerated (or CPU-fallback) spectrogram computer.
§Example
use scirs2_signal::gpu_spectrograms::{GpuSpectrogram, GpuSpectrogramConfig};
use scirs2_core::ndarray::ArrayView1;
let config = GpuSpectrogramConfig::default();
let sg = GpuSpectrogram::new(config).expect("config is valid");
// 4096-sample sine wave at normalised frequency 0.1
let signal: Vec<f32> = (0..4096)
.map(|i| (2.0 * std::f32::consts::PI * 0.1 * i as f32).sin())
.collect();
let mag = sg.compute(ArrayView1::from(&signal)).expect("compute ok");
println!("spectrogram shape: {:?}", mag.dim());Implementations§
Source§impl GpuSpectrogram
impl GpuSpectrogram
Sourcepub fn new(config: GpuSpectrogramConfig) -> Result<Self, GpuSpectrogramError>
pub fn new(config: GpuSpectrogramConfig) -> Result<Self, GpuSpectrogramError>
Construct a new spectrogram computer from the given configuration.
§Errors
Returns GpuSpectrogramError::InvalidFftSize when fft_size is not
a power of two or is zero.
Sourcepub fn compute(
&self,
signal: ArrayView1<'_, f32>,
) -> Result<Array2<f32>, GpuSpectrogramError>
pub fn compute( &self, signal: ArrayView1<'_, f32>, ) -> Result<Array2<f32>, GpuSpectrogramError>
Compute the magnitude spectrogram of signal.
Returns an Array2<f32> of shape [n_frames, fft_size / 2 + 1].
Each row is the single-sided magnitude spectrum of one analysis frame.
§Errors
Returns GpuSpectrogramError::SignalTooShort when signal is
shorter than one FFT frame.
Sourcepub fn compute_power(
&self,
signal: ArrayView1<'_, f32>,
) -> Result<Array2<f32>, GpuSpectrogramError>
pub fn compute_power( &self, signal: ArrayView1<'_, f32>, ) -> Result<Array2<f32>, GpuSpectrogramError>
Compute the power spectrogram (magnitude squared) of signal.
Returns an Array2<f32> of shape [n_frames, fft_size / 2 + 1].
Sourcepub fn compute_batch(
&self,
signals: &[Vec<f32>],
) -> Result<Vec<Array2<f32>>, GpuSpectrogramError>
pub fn compute_batch( &self, signals: &[Vec<f32>], ) -> Result<Vec<Array2<f32>>, GpuSpectrogramError>
Compute spectrograms for a batch of signals.
Each element of signals is processed independently. Returns a
Vec of Array2 in the same order as the input slice.
§Errors
Propagates errors from the single-signal GpuSpectrogram::compute
call for each element.
Auto Trait Implementations§
impl Freeze for GpuSpectrogram
impl RefUnwindSafe for GpuSpectrogram
impl Send for GpuSpectrogram
impl Sync for GpuSpectrogram
impl Unpin for GpuSpectrogram
impl UnsafeUnpin for GpuSpectrogram
impl UnwindSafe for GpuSpectrogram
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.