use std::{
any::TypeId,
ffi::{CStr, c_double, c_int, c_long},
marker::PhantomData,
ptr,
};
use crate::{
audio_buffer::AudioChannelLayout, consts::{MAX_RESAMPLE_RATIO, MIN_RESAMPLE_RATIO}, ffi::libsamplerate::{
SRC_CONVERTER_TYPE, SRC_DATA, SRC_STATE, src_delete, src_new, src_process, src_reset,
src_strerror,
}, float_type::FloatType
};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ResamplerQuality {
Linear,
SincLow,
SincMedium,
SincHigh,
}
pub trait ResamplerImpl<T: FloatType>: Sized {
fn new(quality: ResamplerQuality, layout: AudioChannelLayout) -> Resampler<T>;
fn process(&mut self, input: &[T], output: &mut [T], src_ratio: f64) -> usize;
fn set_quality(&mut self, quality: ResamplerQuality);
fn get_quality(&self) -> ResamplerQuality;
fn get_channel_layout(&self) -> AudioChannelLayout;
fn set_channel_layout(&mut self, layout: AudioChannelLayout);
fn reset(&mut self);
}
#[cfg(feature = "libsamplerate")]
pub struct Resampler<T: FloatType> {
pub(super) state: *mut SRC_STATE,
pub(super) ch_layout: AudioChannelLayout,
pub(super) quality: ResamplerQuality,
pub(super) _phantom: PhantomData<T>,
}
#[cfg(not(feature = "libsamplerate"))]
pub struct Resampler<T: FloatType> {
pub(super) ch_layout: AudioChannelLayout,
pub(super) _ph: PhantomData<T>,
pub(super) kernel_size: usize,
pub(super) window: Vec<T>,
pub(super) quality: ResamplerQuality
}
#[cfg(not(feature = "libsamplerate"))]
pub enum QTable {
Linear = 16,
SincLow = 32,
SincMedium = 64,
SincHigh = 128,
}