Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// This module is used in a special way: it is (re)compiled into each and every top-level example.
// Every example uses only a subset of its functionality, hence we get a lot of artificial unused
// warnings.
// Unfortunate consequence is that we lose the genuine unused warnings.
#![allow(unused)]

use indicatif::{ProgressBar, ProgressStyle};
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
use std::sync::Arc;
Expand Down
30 changes: 15 additions & 15 deletions src/audio_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ impl<S: RawData> AudioBufferBase<S> {

impl<S: Data> AudioBufferBase<S> {
/// Return an immutable audio buffer view, sharing the data with this buffer.
pub fn as_ref(&self) -> AudioRef<S::Elem> {
pub fn as_ref(&self) -> AudioRef<'_, S::Elem> {
AudioRef {
storage: self.storage.view(),
}
}

/// Slice the contents of this audio buffer, returning an immutable view of this buffer
/// containing only the audio samples at indices within the provided range.
pub fn slice(&self, range: impl RangeBounds<usize>) -> AudioRef<S::Elem> {
pub fn slice(&self, range: impl RangeBounds<usize>) -> AudioRef<'_, S::Elem> {
let start = match range.start_bound() {
Bound::Included(i) => *i,
Bound::Excluded(i) => *i + 1,
Expand All @@ -148,7 +148,7 @@ impl<S: Data> AudioBufferBase<S> {
}

/// Iterate over non-overlapping chunks of this audio buffer.
pub fn chunks(&self, size: usize) -> impl Iterator<Item = AudioRef<S::Elem>> {
pub fn chunks(&self, size: usize) -> impl Iterator<Item = AudioRef<'_, S::Elem>> {
let mut i = 0;
std::iter::from_fn(move || {
if i >= self.num_samples() {
Expand All @@ -162,7 +162,7 @@ impl<S: Data> AudioBufferBase<S> {

/// Iterate over non-overlapping chunks of this audio buffer. If the last chunk has a smaller length than the
/// requested size, it will not be yielded.
pub fn chunks_exact(&self, size: usize) -> impl Iterator<Item = AudioRef<S::Elem>> {
pub fn chunks_exact(&self, size: usize) -> impl Iterator<Item = AudioRef<'_, S::Elem>> {
let mut i = 0;
std::iter::from_fn(move || {
if i + size >= self.num_samples() {
Expand All @@ -179,7 +179,7 @@ impl<S: Data> AudioBufferBase<S> {
/// # Arguments
///
/// - `size`: Size of the window
pub fn windows(&self, size: usize) -> impl Iterator<Item = AudioRef<S::Elem>> {
pub fn windows(&self, size: usize) -> impl Iterator<Item = AudioRef<'_, S::Elem>> {
let mut i = 0;
std::iter::from_fn(move || {
if i + size >= self.num_samples() {
Expand All @@ -193,24 +193,24 @@ impl<S: Data> AudioBufferBase<S> {

/// Return an immutable view of a single channel. Panics when the requested channel does not
/// exist.
pub fn get_channel(&self, channel: usize) -> ArrayView1<S::Elem> {
pub fn get_channel(&self, channel: usize) -> ArrayView1<'_, S::Elem> {
self.storage.row(channel)
}

/// Return an iterator of immutable views of the channels present in this audio buffer.
pub fn channels(&self) -> impl '_ + Iterator<Item = ArrayView1<S::Elem>> {
pub fn channels(&self) -> impl '_ + Iterator<Item = ArrayView1<'_, S::Elem>> {
self.storage.rows().into_iter()
}

/// Get a single frame, that is all channels at the specified sample index. Panics when the
/// sample is out of range.
pub fn get_frame(&self, sample: usize) -> ArrayView1<S::Elem> {
pub fn get_frame(&self, sample: usize) -> ArrayView1<'_, S::Elem> {
self.storage.column(sample)
}

/// Return an immutable interleaved 2-D array view, where samples are in rows and channels are
/// in columns.
pub fn as_interleaved(&self) -> ArrayView2<S::Elem> {
pub fn as_interleaved(&self) -> ArrayView2<'_, S::Elem> {
self.storage.t()
}

Expand Down Expand Up @@ -247,15 +247,15 @@ impl<S: Data> AudioBufferBase<S> {

impl<S: DataMut> AudioBufferBase<S> {
/// Return a mutable audio buffer view.
pub fn as_mut(&mut self) -> AudioMut<S::Elem> {
pub fn as_mut(&mut self) -> AudioMut<'_, S::Elem> {
AudioMut {
storage: self.storage.view_mut(),
}
}

/// Slice the contents of this audio buffer, returning a mutable view of this buffer
/// containing only the audio samples at indices within the provided range.
pub fn slice_mut(&mut self, range: impl RangeBounds<usize>) -> AudioMut<S::Elem> {
pub fn slice_mut(&mut self, range: impl RangeBounds<usize>) -> AudioMut<'_, S::Elem> {
let start = match range.start_bound() {
Bound::Included(i) => *i,
Bound::Excluded(i) => *i + 1,
Expand All @@ -272,17 +272,17 @@ impl<S: DataMut> AudioBufferBase<S> {

/// Return a mutable view of a single channel. Panics when the requested channel does not
/// exist.
pub fn get_channel_mut(&mut self, channel: usize) -> ArrayViewMut1<S::Elem> {
pub fn get_channel_mut(&mut self, channel: usize) -> ArrayViewMut1<'_, S::Elem> {
self.storage.row_mut(channel)
}

/// Return an iterator of mutable views of the channels present in this audio buffer.
pub fn channels_mut(&mut self) -> impl '_ + Iterator<Item = ArrayViewMut1<S::Elem>> {
pub fn channels_mut(&mut self) -> impl '_ + Iterator<Item = ArrayViewMut1<'_, S::Elem>> {
self.storage.rows_mut().into_iter()
}
/// Return a mutable interleaved 2-D array view, where samples are in rows and channels are in
/// columns.
pub fn as_interleaved_mut(&mut self) -> ArrayViewMut2<S::Elem> {
pub fn as_interleaved_mut(&mut self) -> ArrayViewMut2<'_, S::Elem> {
self.storage.view_mut().reversed_axes()
}

Expand Down Expand Up @@ -395,7 +395,7 @@ where
/// Panics if the sample index is out of range.
///
/// returns: ArrayBase<ViewRepr<&mut <S as RawData>::Elem>, Dim<[usize; 1]>>
pub fn get_frame_mut(&mut self, sample: usize) -> ArrayViewMut1<S::Elem> {
pub fn get_frame_mut(&mut self, sample: usize) -> ArrayViewMut1<'_, S::Elem> {
self.storage.column_mut(sample)
}

Expand Down
8 changes: 4 additions & 4 deletions src/backends/alsa/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl fmt::Debug for AlsaDevice {
impl AudioDevice for AlsaDevice {
type Error = AlsaError;

fn name(&self) -> Cow<str> {
fn name(&self) -> Cow<'_, str> {
Cow::Borrowed(self.name.as_str())
}

Expand All @@ -40,7 +40,7 @@ impl AudioDevice for AlsaDevice {
}
}

fn channel_map(&self) -> impl IntoIterator<Item = Channel> {
fn channel_map(&self) -> impl IntoIterator<Item = Channel<'_>> {
[]
}

Expand Down Expand Up @@ -112,7 +112,7 @@ impl AlsaDevice {
})
}

fn get_hwp(&self, config: &StreamConfig) -> Result<pcm::HwParams, alsa::Error> {
fn get_hwp(&self, config: &StreamConfig) -> Result<pcm::HwParams<'_>, alsa::Error> {
let hwp = pcm::HwParams::any(&self.pcm)?;
hwp.set_channels(config.channels as _)?;
hwp.set_rate(config.samplerate as _, alsa::ValueOr::Nearest)?;
Expand All @@ -130,7 +130,7 @@ impl AlsaDevice {
pub(super) fn apply_config(
&self,
config: &StreamConfig,
) -> Result<(pcm::HwParams, pcm::SwParams, pcm::IO<f32>), alsa::Error> {
) -> Result<(pcm::HwParams<'_>, pcm::SwParams<'_>, pcm::IO<'_, f32>), alsa::Error> {
let hwp = self.get_hwp(config)?;
self.pcm.hw_params(&hwp)?;
let io = self.pcm.io_f32()?;
Expand Down
2 changes: 1 addition & 1 deletion src/backends/alsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl AudioDriver for AlsaDriver {

const DISPLAY_NAME: &'static str = "ALSA";

fn version(&self) -> Result<Cow<str>, Self::Error> {
fn version(&self) -> Result<Cow<'_, str>, Self::Error> {
Ok(Cow::Borrowed("unknown"))
}

Expand Down
4 changes: 2 additions & 2 deletions src/backends/pipewire/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl PipewireDevice {
impl AudioDevice for PipewireDevice {
type Error = PipewireError;

fn name(&self) -> Cow<str> {
fn name(&self) -> Cow<'_, str> {
let Some(node_id) = self.target_node else {
return Cow::Borrowed("Default");
};
Expand All @@ -56,7 +56,7 @@ impl AudioDevice for PipewireDevice {
self.device_type
}

fn channel_map(&self) -> impl IntoIterator<Item = Channel> {
fn channel_map(&self) -> impl IntoIterator<Item = Channel<'_>> {
[]
}

Expand Down
2 changes: 1 addition & 1 deletion src/backends/pipewire/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl AudioDriver for PipewireDriver {
type Device = PipewireDevice;
const DISPLAY_NAME: &'static str = "Pipewire";

fn version(&self) -> Result<Cow<str>, Self::Error> {
fn version(&self) -> Result<Cow<'_, str>, Self::Error> {
// TODO: Figure out how to get version
Ok(Cow::Borrowed("unknown"))
}
Expand Down
4 changes: 2 additions & 2 deletions src/backends/pipewire/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,13 @@ impl<Callback: 'static + Send + AudioInputCallback> StreamHandle<Callback> {
config,
properties,
callback,
pipewire::spa::utils::Direction::Input,
Direction::Input,
|datas, inner, channels| {
// TODO: also take chunk offset into account to index into the data?
let mut frames_total = 0;

for (chunk, data) in datas.iter_mut().enumerate() {
let samples = data.chunk().size() as usize / size_of::<f32>() as usize;
let samples = data.chunk().size() as usize / size_of::<f32>();
if let Some(bytes) = data.data() {
let frames = samples / channels;
frames_total += frames;
Expand Down
2 changes: 1 addition & 1 deletion src/channel_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub trait CreateBitset: Bitset {
/// # Arguments
///
/// - `indices`: [`IntoIterator`] implementation that returns [`usize`] values corresponding to the indices to
/// set in the bitset.
/// set in the bitset.
fn from_indices(indices: impl IntoIterator<Item = usize>) -> Self;
}

Expand Down
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

use bitflags::bitflags;
use std::borrow::Cow;
use std::fmt;
use std::fmt::Formatter;

use crate::audio_buffer::{AudioMut, AudioRef};
use crate::channel_map::ChannelMap32;
Expand Down Expand Up @@ -55,7 +53,7 @@ pub trait AudioDriver {

/// Runtime version of the audio driver. If there is a difference between "client" and
/// "server" versions, then this should reflect the server version.
fn version(&self) -> Result<Cow<str>, Self::Error>;
fn version(&self) -> Result<Cow<'_, str>, Self::Error>;

/// Default device of the given type. This is most often tied to the audio settings at the
/// operating system level.
Expand Down Expand Up @@ -137,14 +135,14 @@ pub trait AudioDevice {
type Error: std::error::Error;

/// Device display name
fn name(&self) -> Cow<str>;
fn name(&self) -> Cow<'_, str>;

/// Device type. Either input, output, or duplex.
fn device_type(&self) -> DeviceType;

/// Iterator of the available channels in this device. Channel indices are used when
/// specifying which channels to open when creating an audio stream.
fn channel_map(&self) -> impl IntoIterator<Item = Channel>;
fn channel_map(&self) -> impl IntoIterator<Item = Channel<'_>>;

/// Not all configuration values make sense for a particular device, and this method tests a
/// configuration to see if it can be used in an audio stream.
Expand Down
Loading