audio_master/resampler/
base.rs1use std::{
4 any::TypeId,
5 ffi::{CStr, c_double, c_int, c_long},
6 marker::PhantomData,
7 ptr,
8};
9
10use crate::{
11 audio_buffer::AudioChannelLayout, consts::{MAX_RESAMPLE_RATIO, MIN_RESAMPLE_RATIO}, ffi::libsamplerate::{
12 SRC_CONVERTER_TYPE, SRC_DATA, SRC_STATE, src_delete, src_new, src_process, src_reset,
13 src_strerror,
14 }, float_type::FloatType
15};
16
17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
18pub enum ResamplerQuality {
19 Linear,
21
22 SincLow,
24
25 SincMedium,
27
28 SincHigh,
30}
31
32pub trait ResamplerImpl<T: FloatType>: Sized {
34 fn new(quality: ResamplerQuality, layout: AudioChannelLayout) -> Resampler<T>;
35
36 fn process(&mut self, input: &[T], output: &mut [T], src_ratio: f64) -> usize;
38
39 fn set_quality(&mut self, quality: ResamplerQuality);
42
43 fn get_quality(&self) -> ResamplerQuality;
45
46 fn get_channel_layout(&self) -> AudioChannelLayout;
47 fn set_channel_layout(&mut self, layout: AudioChannelLayout);
48
49 fn reset(&mut self);
51}
52
53#[cfg(feature = "libsamplerate")]
54pub struct Resampler<T: FloatType> {
55 pub(super) state: *mut SRC_STATE,
57
58 pub(super) ch_layout: AudioChannelLayout,
59 pub(super) quality: ResamplerQuality,
60
61 pub(super) _phantom: PhantomData<T>,
62}
63
64#[cfg(not(feature = "libsamplerate"))]
65pub struct Resampler<T: FloatType> {
66 pub(super) ch_layout: AudioChannelLayout,
67
68 pub(super) _ph: PhantomData<T>,
69 pub(super) kernel_size: usize,
70 pub(super) window: Vec<T>,
71 pub(super) quality: ResamplerQuality
72}
73
74#[cfg(not(feature = "libsamplerate"))]
75pub enum QTable {
77 Linear = 16,
78 SincLow = 32,
79 SincMedium = 64,
80 SincHigh = 128,
81}