Skip to content

Commit

Permalink
Rename Stream to Resampler (#23)
Browse files Browse the repository at this point in the history
* Rename `Stream` to `Resampler`

* Format code
  • Loading branch information
AldaronLau authored Oct 14, 2024
1 parent 28868f7 commit 5762f6b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 22 deletions.
4 changes: 2 additions & 2 deletions examples/mix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::num::NonZeroU32;

use fon::{
samp::{Samp32, Sample},
Audio, Frame, Sink, Stream,
Audio, Frame, Resampler, Sink,
};

#[derive(Debug)]
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -60,7 +60,7 @@ impl<Samp: Sample, const COUNT: usize> Audio<Samp, COUNT> {
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);
Expand Down Expand Up @@ -130,7 +130,7 @@ impl<Samp: Sample, const COUNT: usize> Audio<Samp, COUNT> {
}
}

/// 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 {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
21 changes: 6 additions & 15 deletions src/stream.rs → src/resampler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::vec::Vec;
use core::{mem, num::NonZeroU32};
use core::{array, mem, num::NonZeroU32};

use crate::{
frame::Frame,
Expand All @@ -21,39 +21,30 @@ const WINDOW_FN_KAISER_TABLE: &[f64] = &[
];
const WINDOW_FN_OVERSAMPLE: usize = 32;

/// Stream resampler.
/// Resampler stream
#[derive(Debug)]
pub struct Stream<const N: usize> {
pub struct Resampler<const N: usize> {
/// Target sample rate (constant).
output_sample_rate: u32,
/// Source sample rate (changeable)
input_sample_rate: Option<NonZeroU32>,
/// 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<const N: usize> Stream<N> {
impl<const N: usize> Resampler<N> {
/// Create a new stream at target sample rate.
pub fn new(target_hz: u32) -> Self {
assert_ne!(target_hz, 0);
Self {
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,
}
}
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 5762f6b

Please sign in to comment.