pub struct BandLayout {
pub bands: NonEmptyVec<Band>,
}Expand description
A non-empty ordered collection of Bands that together partition the
audible spectrum.
Construct using BandLayout::new for custom layouts, or the preset
constructors BandLayout::bark and BandLayout::mel for standard
perceptual scales (see bands).
Fields§
§bands: NonEmptyVec<Band>The ordered list of bands.
Implementations§
Source§impl BandLayout
impl BandLayout
Sourcepub fn bark(
n_bands: NonZeroUsize,
sample_rate_hz: f32,
n_bins: NonZeroUsize,
) -> Self
pub fn bark( n_bands: NonZeroUsize, sample_rate_hz: f32, n_bins: NonZeroUsize, ) -> Self
Creates a Bark-scale band layout.
Divides the spectrum from 0 Hz to Nyquist into n_bands bands spaced
evenly on the Bark scale. Bark bands closely model the ear’s critical
bands and are used by MPEG psychoacoustic models.
n_bins is the number of spectral bins in the caller’s frequency
representation (e.g. MdctParams::n_coefficients() for MDCT, or
n_fft / 2 + 1 for a real FFT). Bin indices in the returned bands
index into that array.
§Arguments
n_bands– Number of bands. 24 covers the full audible range.sample_rate_hz– Sample rate of the audio signal in Hz.n_bins– Total number of spectral bins.
§Returns
A BandLayout with n_bands entries.
§Examples
use audio_samples::BandLayout;
use std::num::NonZeroUsize;
let layout = BandLayout::bark(
NonZeroUsize::new(24).unwrap(),
44100.0,
NonZeroUsize::new(1024).unwrap(),
);
assert_eq!(layout.len().get(), 24);
// All bands fit within the bin range.
for band in layout.as_slice().iter() {
assert!(band.end_bin <= 1024);
assert!(band.end_bin > band.start_bin);
}Sourcepub fn mel(
n_bands: NonZeroUsize,
sample_rate_hz: f32,
n_bins: NonZeroUsize,
) -> Self
pub fn mel( n_bands: NonZeroUsize, sample_rate_hz: f32, n_bins: NonZeroUsize, ) -> Self
Creates a Mel-scale band layout.
Divides the spectrum from 0 Hz to Nyquist into n_bands bands spaced
evenly on the Mel scale. Mel bands are commonly used for speech and music
feature extraction.
n_bins is the number of spectral bins in the caller’s frequency
representation. Bin indices in the returned bands index into that array.
§Arguments
n_bands– Number of bands. 40–128 is typical for speech / music.sample_rate_hz– Sample rate of the audio signal in Hz.n_bins– Total number of spectral bins.
§Returns
A BandLayout with n_bands entries.
§Examples
use audio_samples::BandLayout;
use std::num::NonZeroUsize;
let layout = BandLayout::mel(
NonZeroUsize::new(40).unwrap(),
22050.0,
NonZeroUsize::new(512).unwrap(),
);
assert_eq!(layout.len().get(), 40);Sourcepub fn erb(
n_bands: NonZeroUsize,
sample_rate_hz: f32,
n_bins: NonZeroUsize,
) -> Self
pub fn erb( n_bands: NonZeroUsize, sample_rate_hz: f32, n_bins: NonZeroUsize, ) -> Self
Creates an ERB-scale band layout.
Divides the spectrum from 0 Hz to Nyquist into n_bands bands spaced
evenly on the ERB (Equivalent Rectangular Bandwidth) scale of Glasberg &
Moore (1990). ERB bands more accurately model auditory filter widths than
Bark bands, particularly at low frequencies, and are used in modern
perceptual models (Opus, EVS).
n_bins is the number of spectral bins in the caller’s frequency
representation. Bin indices in the returned bands index into that array.
§Arguments
n_bands– Number of bands. 32–64 is typical.sample_rate_hz– Sample rate of the audio signal in Hz.n_bins– Total number of spectral bins.
§Returns
A BandLayout with n_bands entries.
§Examples
use audio_samples::BandLayout;
use std::num::NonZeroUsize;
let layout = BandLayout::erb(
NonZeroUsize::new(32).unwrap(),
44100.0,
NonZeroUsize::new(1024).unwrap(),
);
assert_eq!(layout.len().get(), 32);
for band in layout.as_slice().iter() {
assert!(band.end_bin > band.start_bin);
}Source§impl BandLayout
impl BandLayout
Sourcepub fn new(bands: &NonEmptySlice<Band>) -> Self
pub fn new(bands: &NonEmptySlice<Band>) -> Self
Sourcepub fn len(&self) -> NonZeroUsize
pub fn len(&self) -> NonZeroUsize
Returns the number of bands.
Sourcepub fn as_slice(&self) -> &NonEmptySlice<Band>
pub fn as_slice(&self) -> &NonEmptySlice<Band>
Returns a view over all bands.
Trait Implementations§
Source§impl Clone for BandLayout
impl Clone for BandLayout
Source§fn clone(&self) -> BandLayout
fn clone(&self) -> BandLayout
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BandLayout
impl Debug for BandLayout
Source§impl PartialEq for BandLayout
impl PartialEq for BandLayout
Source§fn eq(&self, other: &BandLayout) -> bool
fn eq(&self, other: &BandLayout) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for BandLayout
Auto Trait Implementations§
impl Freeze for BandLayout
impl RefUnwindSafe for BandLayout
impl Send for BandLayout
impl Sync for BandLayout
impl Unpin for BandLayout
impl UnsafeUnpin for BandLayout
impl UnwindSafe for BandLayout
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Src, Dst> ConvertTo<Dst> for Srcwhere
Dst: ConvertFrom<Src>,
impl<Src, Dst> ConvertTo<Dst> for Srcwhere
Dst: ConvertFrom<Src>,
Source§fn convert_to(self) -> Dst
fn convert_to(self) -> Dst
Dst using audio-aware scaling. Read moreSource§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 more