diff --git a/examples/mix.rs b/examples/mix.rs index 6490ffb..13e70bd 100644 --- a/examples/mix.rs +++ b/examples/mix.rs @@ -4,7 +4,7 @@ use std::num::NonZeroU32; use fon::{ samp::{Samp32, Sample}, - Audio, Frame, Sink, Stream, + Audio, Frame, Resampler, Sink, }; #[derive(Debug)] @@ -105,7 +105,7 @@ fn main() -> std::io::Result<()> { let mut mixer = Mixer::new(&mut out); // Create a stream to convert to 48k - let mut stream = Stream::<2>::new(48_000); + let mut stream = Resampler::<2>::new(48_000); stream.pipe(&source, &mut mixer); stream.flush(&mut mixer); diff --git a/src/audio.rs b/src/audio.rs index 749d8fb..db3b8f5 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -14,7 +14,7 @@ use crate::math::Libm; use crate::{ frame::Frame, samp::{Samp16, Samp24, Samp32, Samp64, Sample}, - Sink, Stream, + Resampler, Sink, }; /// Audio buffer (fixed-size array of audio [`Frame`](crate::frame::Frame)s at @@ -60,7 +60,7 @@ impl Audio { let len = audio.len() as f64 * hz as f64 / audio.sample_rate().get() as f64; let mut output = Self::with_silence(hz, len.ceil() as usize); - let mut stream = Stream::new(hz); + let mut stream = Resampler::new(hz); let mut sink = crate::SinkTo::<_, Samp, _, COUNT, N>::new(output.sink()); stream.pipe(audio, &mut sink); @@ -130,7 +130,7 @@ impl Audio { } } - /// Sink audio into this audio buffer from a `Stream`. + /// Sink audio into this audio buffer from a [`Resampler`]. #[inline(always)] pub fn sink(&mut self) -> AudioSink<'_, Samp, COUNT> { AudioSink { diff --git a/src/lib.rs b/src/lib.rs index 529fdc4..a4fcd2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,13 +100,13 @@ mod audio; mod frame; mod math; mod private; +mod resampler; mod sink; -mod stream; pub mod pos; pub mod samp; pub use audio::{Audio, AudioSink}; pub use frame::Frame; +pub use resampler::Resampler; pub use sink::{Sink, SinkTo}; -pub use stream::Stream; diff --git a/src/stream.rs b/src/resampler.rs similarity index 93% rename from src/stream.rs rename to src/resampler.rs index 909f85a..81a1ac2 100644 --- a/src/stream.rs +++ b/src/resampler.rs @@ -1,5 +1,5 @@ use alloc::vec::Vec; -use core::{mem, num::NonZeroU32}; +use core::{array, mem, num::NonZeroU32}; use crate::{ frame::Frame, @@ -21,9 +21,9 @@ const WINDOW_FN_KAISER_TABLE: &[f64] = &[ ]; const WINDOW_FN_OVERSAMPLE: usize = 32; -/// Stream resampler. +/// Resampler stream #[derive(Debug)] -pub struct Stream { +pub struct Resampler { /// Target sample rate (constant). output_sample_rate: u32, /// Source sample rate (changeable) @@ -31,12 +31,12 @@ pub struct Stream { /// Simplified ratio of input รท output samples. ratio: (u32, u32), /// Sample data. - samples: [Resampler32; 8], + samples: [Resampler32; N], /// Calculated input latency for resampler. input_latency: u32, } -impl Stream { +impl Resampler { /// Create a new stream at target sample rate. pub fn new(target_hz: u32) -> Self { assert_ne!(target_hz, 0); @@ -44,16 +44,7 @@ impl Stream { output_sample_rate: target_hz, input_sample_rate: None, ratio: (0, 1), - samples: [ - Default::default(), - Default::default(), - Default::default(), - Default::default(), - Default::default(), - Default::default(), - Default::default(), - Default::default(), - ], + samples: array::from_fn(|_| Default::default()), input_latency: 0, } } diff --git a/src/stream/LICENSE.BSD-3 b/src/resampler/LICENSE.BSD-3 similarity index 100% rename from src/stream/LICENSE.BSD-3 rename to src/resampler/LICENSE.BSD-3 diff --git a/src/stream/speex.rs b/src/resampler/speex.rs similarity index 100% rename from src/stream/speex.rs rename to src/resampler/speex.rs