extern crate alloc;
use alloc::boxed::Box;
use alloc::sync::Arc;
pub use super::audionode::*;
pub use super::audiounit::*;
pub use super::biquad::*;
pub use super::buffer::*;
pub use super::combinator::*;
pub use super::delay::*;
pub use super::dynamics::*;
pub use super::envelope::*;
pub use super::feedback::*;
pub use super::filter::*;
pub use super::fir::*;
pub use super::follow::*;
pub use super::granular::*;
pub use super::math::*;
pub use super::moog::*;
pub use super::net::*;
pub use super::noise::*;
pub use super::oscillator::*;
pub use super::oversample::*;
pub use super::pan::*;
pub use super::realnet::*;
pub use super::resample::*;
pub use super::resynth::*;
pub use super::reverb::*;
pub use super::rez::*;
pub use super::ring::*;
pub use super::sequencer::*;
pub use super::setting::*;
pub use super::shape::*;
pub use super::shared::*;
pub use super::signal::*;
pub use super::slot::*;
pub use super::snoop::*;
pub use super::svf::*;
pub use super::system::*;
pub use super::wave::*;
pub use super::wavetable::*;
pub use super::*;
pub type U0 = numeric_array::typenum::U0;
pub type U1 = numeric_array::typenum::U1;
pub type U2 = numeric_array::typenum::U2;
pub type U3 = numeric_array::typenum::U3;
pub type U4 = numeric_array::typenum::U4;
pub type U5 = numeric_array::typenum::U5;
pub type U6 = numeric_array::typenum::U6;
pub type U7 = numeric_array::typenum::U7;
pub type U8 = numeric_array::typenum::U8;
pub type U9 = numeric_array::typenum::U9;
pub type U10 = numeric_array::typenum::U10;
pub type U11 = numeric_array::typenum::U11;
pub type U12 = numeric_array::typenum::U12;
pub type U13 = numeric_array::typenum::U13;
pub type U14 = numeric_array::typenum::U14;
pub type U15 = numeric_array::typenum::U15;
pub type U16 = numeric_array::typenum::U16;
pub type U17 = numeric_array::typenum::U17;
pub type U18 = numeric_array::typenum::U18;
pub type U19 = numeric_array::typenum::U19;
pub type U20 = numeric_array::typenum::U20;
pub type U21 = numeric_array::typenum::U21;
pub type U22 = numeric_array::typenum::U22;
pub type U23 = numeric_array::typenum::U23;
pub type U24 = numeric_array::typenum::U24;
pub type U25 = numeric_array::typenum::U25;
pub type U26 = numeric_array::typenum::U26;
pub type U27 = numeric_array::typenum::U27;
pub type U28 = numeric_array::typenum::U28;
pub type U29 = numeric_array::typenum::U29;
pub type U30 = numeric_array::typenum::U30;
pub type U31 = numeric_array::typenum::U31;
pub type U32 = numeric_array::typenum::U32;
pub type U33 = numeric_array::typenum::U33;
pub type U34 = numeric_array::typenum::U34;
pub type U35 = numeric_array::typenum::U35;
pub type U36 = numeric_array::typenum::U36;
pub type U37 = numeric_array::typenum::U37;
pub type U38 = numeric_array::typenum::U38;
pub type U39 = numeric_array::typenum::U39;
pub type U40 = numeric_array::typenum::U40;
pub type U41 = numeric_array::typenum::U41;
pub type U42 = numeric_array::typenum::U42;
pub type U43 = numeric_array::typenum::U43;
pub type U44 = numeric_array::typenum::U44;
pub type U45 = numeric_array::typenum::U45;
pub type U46 = numeric_array::typenum::U46;
pub type U47 = numeric_array::typenum::U47;
pub type U48 = numeric_array::typenum::U48;
pub type U49 = numeric_array::typenum::U49;
pub type U50 = numeric_array::typenum::U50;
pub type U51 = numeric_array::typenum::U51;
pub type U52 = numeric_array::typenum::U52;
pub type U53 = numeric_array::typenum::U53;
pub type U54 = numeric_array::typenum::U54;
pub type U55 = numeric_array::typenum::U55;
pub type U56 = numeric_array::typenum::U56;
pub type U57 = numeric_array::typenum::U57;
pub type U58 = numeric_array::typenum::U58;
pub type U59 = numeric_array::typenum::U59;
pub type U60 = numeric_array::typenum::U60;
pub type U61 = numeric_array::typenum::U61;
pub type U62 = numeric_array::typenum::U62;
pub type U63 = numeric_array::typenum::U63;
pub type U64 = numeric_array::typenum::U64;
pub type U65 = numeric_array::typenum::U65;
pub type U66 = numeric_array::typenum::U66;
pub type U67 = numeric_array::typenum::U67;
pub type U68 = numeric_array::typenum::U68;
pub type U69 = numeric_array::typenum::U69;
pub type U70 = numeric_array::typenum::U70;
pub type U71 = numeric_array::typenum::U71;
pub type U72 = numeric_array::typenum::U72;
pub type U73 = numeric_array::typenum::U73;
pub type U74 = numeric_array::typenum::U74;
pub type U75 = numeric_array::typenum::U75;
pub type U76 = numeric_array::typenum::U76;
pub type U77 = numeric_array::typenum::U77;
pub type U78 = numeric_array::typenum::U78;
pub type U79 = numeric_array::typenum::U79;
pub type U80 = numeric_array::typenum::U80;
pub type U81 = numeric_array::typenum::U81;
pub type U82 = numeric_array::typenum::U82;
pub type U83 = numeric_array::typenum::U83;
pub type U84 = numeric_array::typenum::U84;
pub type U85 = numeric_array::typenum::U85;
pub type U86 = numeric_array::typenum::U86;
pub type U87 = numeric_array::typenum::U87;
pub type U88 = numeric_array::typenum::U88;
pub type U89 = numeric_array::typenum::U89;
pub type U90 = numeric_array::typenum::U80;
pub type U91 = numeric_array::typenum::U91;
pub type U92 = numeric_array::typenum::U92;
pub type U93 = numeric_array::typenum::U93;
pub type U94 = numeric_array::typenum::U94;
pub type U95 = numeric_array::typenum::U95;
pub type U96 = numeric_array::typenum::U96;
pub type U97 = numeric_array::typenum::U97;
pub type U98 = numeric_array::typenum::U98;
pub type U99 = numeric_array::typenum::U99;
pub type U100 = numeric_array::typenum::U100;
pub type U101 = numeric_array::typenum::U101;
pub type U102 = numeric_array::typenum::U102;
pub type U103 = numeric_array::typenum::U103;
pub type U104 = numeric_array::typenum::U104;
pub type U105 = numeric_array::typenum::U105;
pub type U106 = numeric_array::typenum::U106;
pub type U107 = numeric_array::typenum::U107;
pub type U108 = numeric_array::typenum::U108;
pub type U109 = numeric_array::typenum::U109;
pub type U110 = numeric_array::typenum::U110;
pub type U111 = numeric_array::typenum::U111;
pub type U112 = numeric_array::typenum::U112;
pub type U113 = numeric_array::typenum::U113;
pub type U114 = numeric_array::typenum::U114;
pub type U115 = numeric_array::typenum::U115;
pub type U116 = numeric_array::typenum::U116;
pub type U117 = numeric_array::typenum::U117;
pub type U118 = numeric_array::typenum::U118;
pub type U119 = numeric_array::typenum::U119;
pub type U120 = numeric_array::typenum::U120;
pub type U121 = numeric_array::typenum::U121;
pub type U122 = numeric_array::typenum::U122;
pub type U123 = numeric_array::typenum::U123;
pub type U124 = numeric_array::typenum::U124;
pub type U125 = numeric_array::typenum::U125;
pub type U126 = numeric_array::typenum::U126;
pub type U127 = numeric_array::typenum::U127;
pub type U128 = numeric_array::typenum::U128;
pub fn constant<X: ConstantFrame<Sample = f32>>(x: X) -> An<Constant<X::Size>>
where
X::Size: Size<f32>,
{
An(Constant::new(x.frame()))
}
pub fn dc<X: ConstantFrame<Sample = f32>>(x: X) -> An<Constant<X::Size>>
where
X::Size: Size<f32>,
{
An(Constant::new(x.frame()))
}
pub fn zero() -> An<Constant<U1>> {
dc(0.0)
}
pub fn multizero<N: Size<f32>>() -> An<Constant<N>> {
An(Constant::new(Frame::splat(0.0)))
}
pub fn update<X: AudioNode, F: FnMut(f32, f32, &mut X) + Clone + Send + Sync>(
x: An<X>,
dt: f32,
f: F,
) -> An<System<X, F>> {
An(System::new(x, dt, f))
}
pub fn pass() -> An<Pass> {
An(Pass::new())
}
pub fn multipass<N: Size<f32>>() -> An<MultiPass<N>> {
An(MultiPass::new())
}
pub fn monitor(shared: &Shared, meter: Meter) -> An<Monitor> {
An(Monitor::new(shared, meter))
}
pub fn meter(meter: Meter) -> An<MeterNode> {
An(MeterNode::new(meter))
}
pub fn sink() -> An<Sink<U1>> {
An(Sink::new())
}
pub fn multisink<N: Size<f32>>() -> An<Sink<N>> {
An(Sink::new())
}
pub fn reverse<N: Size<f32>>() -> An<Reverse<N>> {
An(Reverse::new())
}
pub fn sine<F: Real>() -> An<Sine<F>> {
An(Sine::new())
}
pub fn sine_hz<F: Real>(f: f32) -> An<Pipe<Constant<U1>, Sine<F>>> {
constant(f) >> sine()
}
pub fn sine_phase<F: Real>(phase: f32) -> An<Sine<F>> {
An(Sine::with_phase(phase))
}
pub fn ramp<F: Float>() -> An<Ramp<F>> {
An(Ramp::new())
}
pub fn ramp_hz<F: Float>(f: f32) -> An<Pipe<Constant<U1>, Ramp<F>>> {
constant(f) >> ramp()
}
pub fn ramp_phase<F: Float>(phase: f32) -> An<Ramp<F>> {
An(Ramp::with_phase(phase))
}
pub fn ramp_hz_phase<F: Float>(f: f32, phase: f32) -> An<Pipe<Constant<U1>, Ramp<F>>> {
constant(f) >> ramp_phase(phase)
}
pub fn rossler() -> An<Rossler> {
An(Rossler::new())
}
pub fn lorenz() -> An<Lorenz> {
An(Lorenz::new())
}
pub fn add<X: ConstantFrame<Sample = f32>>(
x: X,
) -> An<Binop<FrameAdd<X::Size>, MultiPass<X::Size>, Constant<X::Size>>>
where
X::Size: Size<f32> + Add<U0>,
<X::Size as Add<U0>>::Output: Size<f32>,
{
An(MultiPass::new()) + dc(x)
}
pub fn sub<X: ConstantFrame<Sample = f32>>(
x: X,
) -> An<Binop<FrameSub<X::Size>, MultiPass<X::Size>, Constant<X::Size>>>
where
X::Size: Size<f32> + Add<U0>,
<X::Size as Add<U0>>::Output: Size<f32>,
{
An(MultiPass::new()) - dc(x)
}
pub fn mul<X: ConstantFrame<Sample = f32>>(
x: X,
) -> An<Binop<FrameMul<X::Size>, MultiPass<X::Size>, Constant<X::Size>>>
where
X::Size: Size<f32> + Add<U0>,
<X::Size as Add<U0>>::Output: Size<f32>,
{
An(MultiPass::new()) * dc(x)
}
pub fn butterpass<F: Real>() -> An<ButterLowpass<F, U2>> {
An(ButterLowpass::new(F::new(440)))
}
pub fn butterpass_hz<F: Real>(f: F) -> An<ButterLowpass<F, U1>> {
An(ButterLowpass::new(f))
}
pub fn lowpole<F: Real>() -> An<Lowpole<F, U2>> {
An(Lowpole::new(F::new(440)))
}
pub fn lowpole_hz<F: Real>(cutoff: F) -> An<Lowpole<F, U1>> {
An(Lowpole::new(cutoff))
}
pub fn allpole<F: Float>() -> An<Allpole<F, U2>> {
An(Allpole::new(F::new(1)))
}
pub fn allpole_delay<F: Float>(delay: F) -> An<Allpole<F, U1>> {
An(Allpole::new(delay))
}
pub fn highpole<F: Real>() -> An<Highpole<F, U2>> {
An(Highpole::new(F::new(440)))
}
pub fn highpole_hz<F: Real>(cutoff: F) -> An<Highpole<F, U1>> {
An(Highpole::new(cutoff))
}
pub fn resonator<F: Real>() -> An<Resonator<F, U3>> {
An(Resonator::new(F::new(440), F::new(1)))
}
pub fn resonator_hz<F: Real>(center: F, q: F) -> An<Resonator<F, U1>> {
An(Resonator::new(center, q))
}
pub fn biquad<F: Real>(a1: F, a2: F, b0: F, b1: F, b2: F) -> An<Biquad<F>> {
An(Biquad::with_coefs(BiquadCoefs::arbitrary(
a1, a2, b0, b1, b2,
)))
}
pub fn moog<F: Real>() -> An<Moog<F, U3>> {
An(Moog::new(F::new(1000), F::from_f64(0.1)))
}
pub fn moog_q<F: Real>(q: F) -> An<Pipe<Stack<MultiPass<U2>, Constant<U1>>, Moog<F, U3>>> {
(multipass::<U2>() | dc(q.to_f32())) >> An(Moog::new(F::new(1000), q))
}
pub fn moog_hz<F: Real>(frequency: F, q: F) -> An<Moog<F, U1>> {
An(Moog::new(frequency, q))
}
pub fn envelope<F, E, R>(f: E) -> An<Envelope<F, E, R>>
where
F: Float,
E: FnMut(F) -> R + Clone + Send + Sync,
R: ConstantFrame<Sample = F>,
R::Size: Size<F> + Size<f32>,
{
An(Envelope::new(F::from_f64(0.002), f))
}
pub fn lfo<F, E, R>(f: E) -> An<Envelope<F, E, R>>
where
F: Float,
E: FnMut(F) -> R + Clone + Send + Sync,
R: ConstantFrame<Sample = F>,
R::Size: Size<F> + Size<f32>,
{
An(Envelope::new(F::from_f64(0.002), f))
}
pub fn envelope2<F, E, R>(
mut f: E,
) -> An<EnvelopeIn<F, impl FnMut(F, &Frame<f32, U1>) -> R + Clone, U1, R>>
where
F: Float,
E: FnMut(F, F) -> R + Clone + Send + Sync,
R: ConstantFrame<Sample = F>,
R::Size: Size<F> + Size<f32>,
{
An(EnvelopeIn::new(
F::from_f64(0.002),
move |t, i: &Frame<f32, U1>| f(t, convert(i[0])),
))
}
pub fn lfo2<F, E, R>(
mut f: E,
) -> An<EnvelopeIn<F, impl FnMut(F, &Frame<f32, U1>) -> R + Clone, U1, R>>
where
F: Float,
E: FnMut(F, F) -> R + Clone + Send + Sync,
R: ConstantFrame<Sample = F>,
R::Size: Size<F> + Size<f32>,
{
An(EnvelopeIn::new(
F::from_f64(0.002),
move |t, i: &Frame<f32, U1>| f(t, convert(i[0])),
))
}
pub fn envelope3<F, E, R>(
mut f: E,
) -> An<EnvelopeIn<F, impl FnMut(F, &Frame<f32, U2>) -> R + Clone, U2, R>>
where
F: Float,
E: FnMut(F, F, F) -> R + Clone + Send + Sync,
R: ConstantFrame<Sample = F>,
R::Size: Size<F> + Size<f32>,
{
An(EnvelopeIn::new(
F::from_f64(0.002),
move |t, i: &Frame<f32, U2>| f(t, convert(i[0]), convert(i[1])),
))
}
pub fn lfo3<F, E, R>(
mut f: E,
) -> An<EnvelopeIn<F, impl FnMut(F, &Frame<f32, U2>) -> R + Clone, U2, R>>
where
F: Float,
E: FnMut(F, F, F) -> R + Clone + Send + Sync,
R: ConstantFrame<Sample = F>,
R::Size: Size<F> + Size<f32>,
{
An(EnvelopeIn::new(
F::from_f64(0.002),
move |t, i: &Frame<f32, U2>| f(t, convert(i[0]), convert(i[1])),
))
}
pub fn envelope_in<F, E, I, R>(f: E) -> An<EnvelopeIn<F, E, I, R>>
where
F: Float,
E: FnMut(F, &Frame<f32, I>) -> R + Clone + Send + Sync,
I: Size<f32>,
R: ConstantFrame<Sample = F>,
R::Size: Size<F> + Size<f32>,
{
An(EnvelopeIn::new(F::from_f64(0.002), f))
}
pub fn lfo_in<F, E, I, R>(f: E) -> An<EnvelopeIn<F, E, I, R>>
where
F: Float,
E: FnMut(F, &Frame<f32, I>) -> R + Clone + Send + Sync,
I: Size<f32>,
R: ConstantFrame<Sample = F>,
R::Size: Size<F> + Size<f32>,
{
An(EnvelopeIn::new(F::from_f64(0.002), f))
}
pub fn adsr_live(
attack: f32,
decay: f32,
sustain: f32,
release: f32,
) -> An<EnvelopeIn<f32, impl FnMut(f32, &Frame<f32, U1>) -> f32 + Clone, U1, f32>> {
super::adsr::adsr_live(attack, decay, sustain, release)
}
pub fn mls_bits(n: u64) -> An<Mls> {
An(Mls::new(MlsState::new(n as u32)))
}
pub fn mls() -> An<Mls> {
mls_bits(29)
}
pub fn noise() -> An<Noise> {
An(Noise::new())
}
pub fn white() -> An<Noise> {
An(Noise::new())
}
pub fn hold(variability: f32) -> An<Hold> {
An(Hold::new(variability))
}
pub fn hold_hz(f: f32, variability: f32) -> An<Pipe<Stack<Pass, Constant<U1>>, Hold>> {
(pass() | dc(f)) >> hold(variability)
}
pub fn fir<X: ConstantFrame<Sample = f32>>(weights: X) -> An<Fir<X::Size>> {
An(Fir::new(weights))
}
pub fn fir3(gain: f32) -> An<Fir<U3>> {
let alpha = (gain + 1.0) / 2.0;
let beta = (1.0 - alpha) / 2.0;
An(Fir::new((beta, alpha, beta)))
}
pub fn tick() -> An<Tick<U1>> {
An(Tick::new())
}
pub fn multitick<N: Size<f32>>() -> An<Tick<N>> {
An(Tick::new())
}
pub fn delay(t: f64) -> An<Delay> {
An(Delay::new(t))
}
pub fn tap(min_delay: f32, max_delay: f32) -> An<Tap<U1>> {
An(Tap::new(min_delay, max_delay))
}
pub fn multitap<N>(min_delay: f32, max_delay: f32) -> An<Tap<N>>
where
N: Size<f32> + Add<U1>,
<N as Add<U1>>::Output: Size<f32>,
{
An(Tap::new(min_delay, max_delay))
}
pub fn tap_linear(min_delay: f32, max_delay: f32) -> An<TapLinear<U1>> {
An(TapLinear::new(min_delay, max_delay))
}
pub fn multitap_linear<N>(min_delay: f32, max_delay: f32) -> An<TapLinear<N>>
where
N: Size<f32> + Add<U1>,
<N as Add<U1>>::Output: Size<f32>,
{
An(TapLinear::new(min_delay, max_delay))
}
pub fn oversample<X>(node: An<X>) -> An<Oversampler<X>>
where
X: AudioNode,
X::Inputs: Size<f32>,
X::Outputs: Size<f32>,
X::Inputs: Size<Frame<f32, U128>>,
X::Outputs: Size<Frame<f32, U128>>,
{
An(Oversampler::new(DEFAULT_SR, node.0))
}
pub fn resample<X>(node: An<X>) -> An<Resampler<X>>
where
X: AudioNode<Inputs = U0>,
X::Outputs: Size<f32>,
X::Outputs: Size<Frame<f32, U128>>,
{
An(Resampler::new(DEFAULT_SR, node.0))
}
pub fn feedback<N, X>(node: An<X>) -> An<Feedback<N, X, FrameId<N>>>
where
N: Size<f32>,
X: AudioNode<Inputs = N, Outputs = N>,
X::Inputs: Size<f32>,
X::Outputs: Size<f32>,
{
An(Feedback::new(node.0, FrameId::new()))
}
pub fn feedback2<N, X, Y>(node: An<X>, loopback: An<Y>) -> An<Feedback2<N, X, Y, FrameId<N>>>
where
N: Size<f32>,
X: AudioNode<Inputs = N, Outputs = N>,
X::Inputs: Size<f32>,
X::Outputs: Size<f32>,
Y: AudioNode<Inputs = N, Outputs = N>,
Y::Inputs: Size<f32>,
Y::Outputs: Size<f32>,
{
An(Feedback2::new(node.0, loopback.0, FrameId::new()))
}
pub fn allnest_c<X>(coefficient: f32, x: An<X>) -> An<AllNest<U1, X>>
where
X: AudioNode<Inputs = U1, Outputs = U1>,
{
An(AllNest::new(coefficient, x.0))
}
pub fn allnest<X>(x: An<X>) -> An<AllNest<U2, X>>
where
X: AudioNode<Inputs = U1, Outputs = U1>,
{
An(AllNest::new(0.0, x.0))
}
pub fn map<M, I, O>(f: M) -> An<Map<M, I, O>>
where
M: Fn(&Frame<f32, I>) -> O + Clone + Send + Sync,
I: Size<f32>,
O: ConstantFrame<Sample = f32>,
O::Size: Size<f32>,
{
An(Map::new(f, Routing::Arbitrary(0.0)))
}
pub fn dcblock_hz<F: Real>(cutoff: F) -> An<DCBlock<F>> {
An(DCBlock::new(cutoff))
}
pub fn dcblock<F: Real>() -> An<DCBlock<F>> {
An(DCBlock::new(F::new(10)))
}
pub fn declick<F: Real>() -> An<Declick<F>> {
An(Declick::new(F::from_f64(0.010)))
}
pub fn declick_s<F: Real>(t: F) -> An<Declick<F>> {
An(Declick::new(t))
}
pub fn shape_fn<S: Fn(f32) -> f32 + Clone + Send + Sync>(f: S) -> An<Shaper<ShapeFn<S>>> {
An(Shaper::new(ShapeFn(f)))
}
pub fn shape<S: Shape>(mode: S) -> An<Shaper<S>> {
An(Shaper::new(mode))
}
pub fn clip() -> An<Shaper<Clip>> {
An(Shaper::new(Clip(1.0)))
}
pub fn clip_to(minimum: f32, maximum: f32) -> An<Shaper<ClipTo>> {
An(Shaper::new(ClipTo(minimum, maximum)))
}
pub fn panner() -> An<Panner<U2>> {
An(Panner::new(0.0))
}
pub fn pan(pan: f32) -> An<Panner<U1>> {
An(Panner::new(pan))
}
pub fn follow<F: Real>(response_time: F) -> An<Follow<F>> {
An(Follow::new(response_time))
}
pub fn afollow<F: Real>(attack_time: F, release_time: F) -> An<AFollow<F>> {
An(AFollow::new(attack_time, release_time))
}
pub fn limiter(attack_time: f32, release_time: f32) -> An<Limiter<U1>> {
An(Limiter::new(DEFAULT_SR, attack_time, release_time))
}
pub fn limiter_stereo(attack_time: f32, release_time: f32) -> An<Limiter<U2>> {
An(Limiter::new(DEFAULT_SR, attack_time, release_time))
}
pub fn pinkpass<F: Float>() -> An<Pinkpass<F>> {
An(Pinkpass::new())
}
pub fn pink<F: Float>() -> An<Pipe<Noise, Pinkpass<F>>> {
white() >> pinkpass::<F>()
}
pub fn brown<F: Real>() -> An<Pipe<Noise, Binop<FrameMul<U1>, Lowpole<F, U1>, Constant<U1>>>> {
white() >> lowpole_hz::<F>(F::from_f64(10.0)) * dc(13.7)
}
pub fn fdn<N, X>(x: An<X>) -> An<Feedback<N, X, FrameHadamard<N>>>
where
N: Size<f32>,
X: AudioNode<Inputs = N, Outputs = N>,
X::Inputs: Size<f32>,
X::Outputs: Size<f32>,
{
An(Feedback::new(x.0, FrameHadamard::new()))
}
pub fn fdn2<N, X, Y>(x: An<X>, y: An<Y>) -> An<Feedback2<N, X, Y, FrameHadamard<N>>>
where
N: Size<f32>,
X: AudioNode<Inputs = N, Outputs = N>,
X::Inputs: Size<f32>,
X::Outputs: Size<f32>,
Y: AudioNode<Inputs = N, Outputs = N>,
Y::Inputs: Size<f32>,
Y::Outputs: Size<f32>,
{
An(Feedback2::new(x.0, y.0, FrameHadamard::new()))
}
pub fn bus<X, Y>(x: An<X>, y: An<Y>) -> An<Bus<X, Y>>
where
X: AudioNode,
Y: AudioNode<Inputs = X::Inputs, Outputs = X::Outputs>,
{
x & y
}
pub fn busi<N, X, F>(f: F) -> An<MultiBus<N, X>>
where
N: Size<f32> + Size<X>,
X: AudioNode,
X::Inputs: Size<f32>,
X::Outputs: Size<f32>,
F: Fn(u64) -> An<X>,
{
assert!(N::USIZE > 0);
let nodes = Frame::generate(|i| f(i as u64).0);
An(MultiBus::new(nodes))
}
pub fn busf<N, X, Y, F>(f: Y) -> An<MultiBus<N, X>>
where
N: Size<f32> + Size<X>,
F: Float,
X: AudioNode,
X::Inputs: Size<f32>,
X::Outputs: Size<f32>,
Y: Fn(F) -> An<X>,
{
assert!(N::USIZE > 0);
let nodes = Frame::generate(|i| {
f(if N::USIZE > 1 {
F::from_f64(i as f64 / (N::USIZE - 1) as f64)
} else {
F::from_f64(0.5)
})
.0
});
An(MultiBus::new(nodes))
}
pub fn stack<X, Y>(x: An<X>, y: An<Y>) -> An<Stack<X, Y>>
where
X: AudioNode,
Y: AudioNode,
X::Inputs: Add<Y::Inputs>,
X::Outputs: Add<Y::Outputs>,
<X::Inputs as Add<Y::Inputs>>::Output: Size<f32>,
<X::Outputs as Add<Y::Outputs>>::Output: Size<f32>,
{
x | y
}
pub fn stacki<N, X, F>(f: F) -> An<MultiStack<N, X>>
where
N: Size<f32> + Size<X>,
X: AudioNode,
X::Inputs: Size<f32> + Mul<N>,
X::Outputs: Size<f32> + Mul<N>,
<X::Inputs as Mul<N>>::Output: Size<f32>,
<X::Outputs as Mul<N>>::Output: Size<f32>,
F: Fn(u64) -> An<X>,
{
assert!(N::USIZE > 0);
let nodes = Frame::generate(|i| f(i as u64).0);
An(MultiStack::new(nodes))
}
pub fn stackf<N, X, Y, F>(f: Y) -> An<MultiStack<N, X>>
where
N: Size<f32> + Size<X>,
F: Float,
X: AudioNode,
X::Inputs: Size<f32> + Mul<N>,
X::Outputs: Size<f32> + Mul<N>,
<X::Inputs as Mul<N>>::Output: Size<f32>,
<X::Outputs as Mul<N>>::Output: Size<f32>,
Y: Fn(F) -> An<X>,
{
assert!(N::USIZE > 0);
let nodes = Frame::generate(|i| {
f(if N::USIZE > 1 {
F::from_f64(i as f64 / (N::USIZE - 1) as f64)
} else {
F::from_f64(0.5)
})
.0
});
An(MultiStack::new(nodes))
}
pub fn branch<X, Y>(x: An<X>, y: An<Y>) -> An<Branch<X, Y>>
where
X: AudioNode,
Y: AudioNode<Inputs = X::Inputs>,
X::Outputs: Add<Y::Outputs>,
<X::Outputs as Add<Y::Outputs>>::Output: Size<f32>,
{
x ^ y
}
pub fn branchi<N, X, F>(f: F) -> An<MultiBranch<N, X>>
where
N: Size<f32> + Size<X>,
X: AudioNode,
X::Inputs: Size<f32>,
X::Outputs: Size<f32> + Mul<N>,
<X::Outputs as Mul<N>>::Output: Size<f32>,
F: Fn(u64) -> An<X>,
{
let nodes = Frame::generate(|i| f(i as u64).0);
An(MultiBranch::new(nodes))
}
pub fn branchf<N, X, Y, F>(f: Y) -> An<MultiBranch<N, X>>
where
N: Size<f32> + Size<X>,
F: Float,
X: AudioNode,
X::Inputs: Size<f32>,
X::Outputs: Size<f32> + Mul<N>,
<X::Outputs as Mul<N>>::Output: Size<f32>,
Y: Fn(F) -> An<X>,
{
let nodes = Frame::generate(|i| {
f(if N::USIZE > 1 {
F::from_f64(i as f64 / (N::USIZE - 1) as f64)
} else {
F::from_f64(0.5)
})
.0
});
An(MultiBranch::new(nodes))
}
pub fn thru<X>(x: An<X>) -> An<Thru<X>>
where
X: AudioNode,
{
!x
}
pub fn product<X, Y>(x: An<X>, y: An<Y>) -> An<Binop<FrameMul<X::Outputs>, X, Y>>
where
X: AudioNode,
Y: AudioNode<Outputs = X::Outputs>,
X::Inputs: Add<Y::Inputs>,
<X::Inputs as Add<Y::Inputs>>::Output: Size<f32>,
{
x * y
}
pub fn sum<X, Y>(x: An<X>, y: An<Y>) -> An<Binop<FrameAdd<X::Outputs>, X, Y>>
where
X: AudioNode,
Y: AudioNode<Outputs = X::Outputs>,
X::Inputs: Add<Y::Inputs>,
<X::Inputs as Add<Y::Inputs>>::Output: Size<f32>,
{
x + y
}
pub fn sumi<N, X, F>(f: F) -> An<Reduce<N, X, FrameAdd<X::Outputs>>>
where
N: Size<f32> + Size<X>,
X: AudioNode,
X::Inputs: Size<f32> + Mul<N>,
X::Outputs: Size<f32>,
<X::Inputs as Mul<N>>::Output: Size<f32>,
F: Fn(u64) -> An<X>,
{
let nodes = Frame::generate(|i| f(i as u64).0);
An(Reduce::new(nodes, FrameAdd::new()))
}
pub fn sumf<N, X, Y, F>(f: Y) -> An<Reduce<N, X, FrameAdd<X::Outputs>>>
where
N: Size<f32> + Size<X>,
F: Float,
X: AudioNode,
X::Inputs: Size<f32> + Mul<N>,
X::Outputs: Size<f32>,
<X::Inputs as Mul<N>>::Output: Size<f32>,
Y: Fn(F) -> An<X>,
{
let nodes = Frame::generate(|i| {
f(if N::USIZE > 1 {
F::from_f64(i as f64 / (N::USIZE - 1) as f64)
} else {
F::from_f64(0.5)
})
.0
});
An(Reduce::new(nodes, FrameAdd::new()))
}
pub fn pipe<X, Y>(x: An<X>, y: An<Y>) -> An<Pipe<X, Y>>
where
X: AudioNode,
Y: AudioNode<Inputs = X::Outputs>,
{
x >> y
}
pub fn pipei<N, X, F>(f: F) -> An<Chain<N, X>>
where
N: Size<f32> + Size<X>,
X: AudioNode,
F: Fn(u64) -> An<X>,
{
let nodes = Frame::generate(|i| f(i as u64).0);
An(Chain::new(nodes))
}
pub fn pipef<N, X, Y, F>(f: Y) -> An<Chain<N, X>>
where
N: Size<f32> + Size<X>,
F: Float,
X: AudioNode,
X::Inputs: Size<f32>,
X::Outputs: Size<f32>,
Y: Fn(F) -> An<X>,
{
let nodes = Frame::generate(|i| {
f(if N::USIZE > 1 {
F::from_f64(i as f64 / (N::USIZE - 1) as f64)
} else {
F::from_f64(0.5)
})
.0
});
An(Chain::new(nodes))
}
pub fn split<N>() -> An<Split<N>>
where
N: Size<f32>,
{
An(Split::new())
}
pub fn multisplit<M, N>() -> An<MultiSplit<M, N>>
where
M: Size<f32> + Mul<N>,
N: Size<f32>,
<M as Mul<N>>::Output: Size<f32>,
{
An(MultiSplit::new())
}
pub fn join<N>() -> An<Join<N>>
where
N: Size<f32>,
{
An(Join::new())
}
pub fn multijoin<M, N>() -> An<MultiJoin<M, N>>
where
N: Size<f32>,
M: Size<f32> + Mul<N>,
<M as Mul<N>>::Output: Size<f32>,
{
An(MultiJoin::new())
}
pub fn reverb_stereo(
room_size: f64,
time: f64,
damping: f64,
) -> An<impl AudioNode<Inputs = U2, Outputs = U2>> {
const DELAYS: [f64; 32] = [
0.073904, 0.052918, 0.066238, 0.066387, 0.037783, 0.080073, 0.050961, 0.075900, 0.043646,
0.072095, 0.056194, 0.045961, 0.058934, 0.068016, 0.047529, 0.058156, 0.072972, 0.036084,
0.062715, 0.076377, 0.044339, 0.076725, 0.077884, 0.046126, 0.067741, 0.049800, 0.051709,
0.082923, 0.070121, 0.079315, 0.055039, 0.081859,
];
let a = pow(db_amp(-60.0), 0.03 * room_size / 10.0 / time) as f32;
let weights = fir3(1.0 - damping as f32).weights() * Frame::splat(a);
let line =
stacki::<U32, _, _>(|i| delay(DELAYS[i as usize] * room_size / 10.0) >> fir(weights));
let reverb = fdn::<U32, _>(line);
multisplit::<U2, U16>()
>> reverb
>> sumf::<U32, _, _, f32>(|x| pan(lerp(-1.0, 1.0, smooth9(x))))
* dc((1.0 / 16.0, 1.0 / 16.0))
}
pub fn reverb2_stereo(
room_size: f64,
time: f64,
diffusion: f64,
modulation_speed: f64,
filter: An<impl AudioNode<Inputs = U1, Outputs = U1>>,
) -> An<impl AudioNode<Inputs = U2, Outputs = U2>> {
let room_size = clamp(10.0, 30.0, room_size);
let delays = [
11, 13, 17, 23, 31, 41, 53, 71, 97, 113, 131, 163, 193, 223, 241, 269, 293, 311, 337, 359,
397, 421, 449, 479, 503, 523, 557, 571, 601, 631, 653, 677, 709, 733, 757, 787, 809, 827,
857, 877, 911, 929, 953, 977, 1009,
];
let delay_min = 0.010 + room_size * 0.003;
let delay_max = max(delay_min * 2.0, delay_min + 0.002 * 31.0);
let delay_d = (delay_max - delay_min) / 32.0;
let a = pow(db_amp(-60.0), 0.5 * delay_min / time) as f32;
let coeff = lerp(0.5, 0.9, diffusion as f32);
let line = stacki::<U32, _, _>(|i| {
let j = if i < 16 { i * 2 } else { (31 - i) * 2 + 1 };
let allpass_delay = delays[j as usize] as f64 / DEFAULT_SR;
let d = delay_min as f32 + j as f32 * delay_d as f32 - allpass_delay as f32;
let dv = 0.001;
let min_d = d - dv;
let max_d = d + dv;
(filter.clone() * dc(a)
| An(Envelope::<f32, _, _>::new(0.01, move |t| {
lerp11(
min_d,
max_d,
spline_noise(i, t * modulation_speed as f32 * 0.5),
)
})))
>> tap_linear(min_d, max_d)
>> allnest_c(coeff, delay(allpass_delay - 1.0 / DEFAULT_SR))
});
let lpass =
allnest_c(0.618, delay(224.0 / DEFAULT_SR)) >> allnest_c(0.618, delay(340.0 / DEFAULT_SR));
let rpass =
allnest_c(0.618, delay(247.0 / DEFAULT_SR)) >> allnest_c(0.618, delay(366.0 / DEFAULT_SR));
(lpass | rpass)
>> multisplit::<U2, U16>()
>> fdn(line)
>> sumf::<U32, _, _, f32>(|x| pan(lerp(-1.0, 1.0, smooth9(x)))) * (1.0 / 8.0)
}
pub fn reverb3_stereo(
time: f64,
diffusion: f64,
filter: An<impl AudioNode<Inputs = U1, Outputs = U1>>,
) -> An<impl AudioNode<Inputs = U2, Outputs = U2>> {
An(super::reverb::Reverb::new(time, diffusion, filter.0))
}
pub fn reverb4_stereo(room_size: f64, time: f64) -> An<impl AudioNode<Inputs = U2, Outputs = U2>> {
let mut delays = [
0.059326634,
0.04778291,
0.06995449,
0.0393001,
0.041604012,
0.06215825,
0.052269846,
0.043227978,
0.06966107,
0.031615064,
0.068442,
0.037332155,
0.032944717,
0.034493037,
0.06787566,
0.038824916,
0.068260126,
0.068044715,
0.0688076,
0.066724524,
0.051293883,
0.06023173,
0.040897705,
0.031507637,
0.060309593,
0.049584292,
0.04532072,
0.056379095,
0.035180368,
0.041291796,
0.046129026,
0.05504605,
];
for delay in delays.iter_mut() {
*delay *= (max(room_size as f32, 15.0)) / 10.0;
}
reverb4_stereo_delays(&delays, time)
}
pub fn reverb4_stereo_delays(
delays: &[f32],
time: f64,
) -> An<impl AudioNode<Inputs = U2, Outputs = U2>> {
assert!(delays.len() == 32);
let room_size = 10.0; let a = pow(db_amp(-60.0), 0.03 * room_size / 10.0 / time) as f32;
let line1 = stacki::<U16, _, _>(|i| {
delay(delays[i as usize] as f64) >> fir((-a / 4.0, -a / 2.0, -a / 4.0))
});
let line2 = stacki::<U16, _, _>(|i| {
delay(delays[16 + i as usize] as f64) >> fir((-a / 4.0, -a / 2.0, -a / 4.0))
});
let fdn1 = fdn(line1);
let fdn2 = fdn(line2);
multisplit::<U2, U8>()
>> fdn1
>> multijoin::<U2, U8>()
>> multisplit::<U2, U8>()
>> fdn2
>> sumf::<U16, _, _, f32>(|x| pan(lerp(-1.0, 1.0, smooth9(x)))) * dc((1.0 / 4.0, 1.0 / 4.0))
}
pub fn dsf_saw() -> An<Dsf<U2>> {
An(Dsf::new(1.0, 0.5))
}
pub fn dsf_saw_r(roughness: f32) -> An<Dsf<U1>> {
An(Dsf::new(1.0, roughness))
}
pub fn dsf_square() -> An<Dsf<U2>> {
An(Dsf::new(2.0, 0.5))
}
pub fn dsf_square_r(roughness: f32) -> An<Dsf<U1>> {
An(Dsf::new(2.0, roughness))
}
pub fn pluck(frequency: f32, gain_per_second: f32, high_frequency_damping: f32) -> An<Pluck> {
An(Pluck::new(
frequency,
gain_per_second,
high_frequency_damping,
))
}
pub fn saw() -> An<WaveSynth<U1>> {
An(WaveSynth::new(saw_table()))
}
pub fn square() -> An<WaveSynth<U1>> {
An(WaveSynth::new(square_table()))
}
pub fn triangle() -> An<WaveSynth<U1>> {
An(WaveSynth::new(triangle_table()))
}
pub fn organ() -> An<WaveSynth<U1>> {
An(WaveSynth::new(organ_table()))
}
pub fn soft_saw() -> An<WaveSynth<U1>> {
An(WaveSynth::new(soft_saw_table()))
}
pub fn hammond() -> An<WaveSynth<U1>> {
An(WaveSynth::new(hammond_table()))
}
pub fn saw_hz(f: f32) -> An<Pipe<Constant<U1>, WaveSynth<U1>>> {
constant(f) >> saw()
}
pub fn square_hz(f: f32) -> An<Pipe<Constant<U1>, WaveSynth<U1>>> {
constant(f) >> square()
}
pub fn triangle_hz(f: f32) -> An<Pipe<Constant<U1>, WaveSynth<U1>>> {
constant(f) >> triangle()
}
pub fn organ_hz(f: f32) -> An<Pipe<Constant<U1>, WaveSynth<U1>>> {
constant(f) >> organ()
}
pub fn soft_saw_hz(f: f32) -> An<Pipe<Constant<U1>, WaveSynth<U1>>> {
constant(f) >> soft_saw()
}
pub fn hammond_hz(f: f32) -> An<Pipe<Constant<U1>, WaveSynth<U1>>> {
constant(f) >> hammond()
}
pub fn lowpass<F: Real>() -> An<Svf<F, LowpassMode<F>>> {
An(Svf::new(
LowpassMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: F::one(),
gain: F::one(),
},
))
}
pub fn lowpass_hz<F: Real>(f: F, q: F) -> An<FixedSvf<F, LowpassMode<F>>> {
An(FixedSvf::new(
LowpassMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: f,
q,
gain: F::one(),
},
))
}
pub fn lowpass_q<F: Real>(
q: F,
) -> An<Pipe<Stack<MultiPass<U2>, Constant<U1>>, Svf<F, LowpassMode<F>>>> {
(multipass::<U2>() | dc(q.to_f32()))
>> An(Svf::new(
LowpassMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q,
gain: F::one(),
},
))
}
pub fn highpass<F: Real>() -> An<Svf<F, HighpassMode<F>>> {
An(Svf::new(
HighpassMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: F::one(),
gain: F::one(),
},
))
}
pub fn highpass_hz<F: Real>(f: F, q: F) -> An<FixedSvf<F, HighpassMode<F>>> {
An(FixedSvf::new(
HighpassMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: f,
q,
gain: F::one(),
},
))
}
pub fn highpass_q<F: Real>(
q: F,
) -> An<Pipe<Stack<MultiPass<U2>, Constant<U1>>, Svf<F, HighpassMode<F>>>> {
(multipass::<U2>() | dc(q.to_f32()))
>> An(Svf::new(
HighpassMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: convert(q),
gain: F::one(),
},
))
}
pub fn bandpass<F: Real>() -> An<Svf<F, BandpassMode<F>>> {
An(Svf::new(
BandpassMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: F::one(),
gain: F::one(),
},
))
}
pub fn bandpass_hz<F: Real>(f: F, q: F) -> An<FixedSvf<F, BandpassMode<F>>> {
An(FixedSvf::new(
BandpassMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: f,
q,
gain: F::one(),
},
))
}
pub fn bandpass_q<F: Real>(
q: F,
) -> An<Pipe<Stack<MultiPass<U2>, Constant<U1>>, Svf<F, BandpassMode<F>>>> {
(multipass::<U2>() | dc(q.to_f32()))
>> An(Svf::new(
BandpassMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: convert(q),
gain: F::one(),
},
))
}
pub fn notch<F: Real>() -> An<Svf<F, NotchMode<F>>> {
An(Svf::new(
NotchMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: F::one(),
gain: F::one(),
},
))
}
pub fn notch_hz<F: Real>(f: F, q: F) -> An<FixedSvf<F, NotchMode<F>>> {
An(FixedSvf::new(
NotchMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: f,
q,
gain: F::one(),
},
))
}
pub fn notch_q<F: Real>(
q: F,
) -> An<Pipe<Stack<MultiPass<U2>, Constant<U1>>, Svf<F, NotchMode<F>>>> {
(multipass::<U2>() | dc(q.to_f32()))
>> An(Svf::new(
NotchMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: convert(q),
gain: F::one(),
},
))
}
pub fn peak<F: Real>() -> An<Svf<F, PeakMode<F>>> {
An(Svf::new(
PeakMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: F::one(),
gain: F::one(),
},
))
}
pub fn peak_hz<F: Real>(f: F, q: F) -> An<FixedSvf<F, PeakMode<F>>> {
An(FixedSvf::new(
PeakMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: f,
q,
gain: F::one(),
},
))
}
pub fn peak_q<F: Real>(q: F) -> An<Pipe<Stack<MultiPass<U2>, Constant<U1>>, Svf<F, PeakMode<F>>>> {
(multipass::<U2>() | dc(q.to_f32()))
>> An(Svf::new(
PeakMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: convert(q),
gain: F::one(),
},
))
}
pub fn allpass<F: Real>() -> An<Svf<F, AllpassMode<F>>> {
An(Svf::new(
AllpassMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: F::one(),
gain: F::one(),
},
))
}
pub fn allpass_hz<F: Real>(f: F, q: F) -> An<FixedSvf<F, AllpassMode<F>>> {
An(FixedSvf::new(
AllpassMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: f,
q,
gain: F::one(),
},
))
}
pub fn allpass_q<F: Real>(
q: F,
) -> An<Pipe<Stack<MultiPass<U2>, Constant<U1>>, Svf<F, AllpassMode<F>>>> {
(multipass::<U2>() | dc(q.to_f32()))
>> An(Svf::new(
AllpassMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: convert(q),
gain: F::one(),
},
))
}
pub fn bell<F: Real>() -> An<Svf<F, BellMode<F>>> {
An(Svf::new(
BellMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: F::one(),
gain: F::one(),
},
))
}
pub fn bell_hz<F: Real>(f: F, q: F, gain: F) -> An<FixedSvf<F, BellMode<F>>> {
An(FixedSvf::new(
BellMode::default(),
&SvfParams::<F> {
sample_rate: convert(DEFAULT_SR),
cutoff: f,
q,
gain,
},
))
}
pub fn bell_q<F: Real>(
q: F,
gain: F,
) -> An<Pipe<Stack<MultiPass<U2>, Constant<U2>>, Svf<F, BellMode<F>>>> {
(multipass::<U2>() | dc((q.to_f32(), gain.to_f32())))
>> An(Svf::new(
BellMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: convert(q),
gain: convert(gain),
},
))
}
pub fn lowshelf<F: Real>() -> An<Svf<F, LowshelfMode<F>>> {
An(Svf::new(
LowshelfMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: F::one(),
gain: F::one(),
},
))
}
pub fn lowshelf_hz<F: Real>(f: F, q: F, gain: F) -> An<FixedSvf<F, LowshelfMode<F>>> {
An(FixedSvf::new(
LowshelfMode::default(),
&SvfParams::<F> {
sample_rate: convert(DEFAULT_SR),
cutoff: f,
q,
gain,
},
))
}
pub fn lowshelf_q<F: Real>(
q: F,
gain: F,
) -> An<Pipe<Stack<MultiPass<U2>, Constant<U2>>, Svf<F, LowshelfMode<F>>>> {
(multipass::<U2>() | dc((q.to_f32(), gain.to_f32())))
>> An(Svf::new(
LowshelfMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: convert(440.0),
q: convert(q),
gain: F::one(),
},
))
}
pub fn highshelf<F: Real>() -> An<Svf<F, HighshelfMode<F>>> {
An(Svf::new(
HighshelfMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: F::new(440),
q: F::one(),
gain: F::one(),
},
))
}
pub fn highshelf_hz<F: Real>(f: F, q: F, gain: F) -> An<FixedSvf<F, HighshelfMode<F>>> {
An(FixedSvf::new(
HighshelfMode::default(),
&SvfParams::<F> {
sample_rate: convert(DEFAULT_SR),
cutoff: f,
q,
gain,
},
))
}
pub fn highshelf_q<F: Real>(
q: F,
gain: F,
) -> An<Pipe<Stack<MultiPass<U2>, Constant<U2>>, Svf<F, HighshelfMode<F>>>> {
(multipass::<U2>() | dc((q.to_f32(), gain.to_f32())))
>> An(Svf::new(
HighshelfMode::default(),
&SvfParams {
sample_rate: convert(DEFAULT_SR),
cutoff: convert(440.0),
q: convert(q),
gain: F::one(),
},
))
}
pub fn lowrez<F: Real>() -> An<Rez<F, U3>> {
An(Rez::new(F::zero(), F::new(440), F::one()))
}
pub fn lowrez_hz<F: Real>(cutoff: F, q: F) -> An<Rez<F, U1>> {
An(Rez::new(F::zero(), cutoff, q))
}
pub fn lowrez_q<F: Real>(q: F) -> An<Pipe<Stack<MultiPass<U2>, Constant<U1>>, Rez<F, U3>>> {
(multipass::<U2>() | dc(q.to_f32())) >> lowrez()
}
pub fn bandrez<F: Real>() -> An<Rez<F, U3>> {
An(Rez::new(F::one(), F::new(440), F::one()))
}
pub fn bandrez_hz<F: Real>(center: F, q: F) -> An<Rez<F, U1>> {
An(Rez::new(F::one(), center, q))
}
pub fn bandrez_q<F: Real>(q: F) -> An<Pipe<Stack<MultiPass<U2>, Constant<U1>>, Rez<F, U3>>> {
(multipass::<U2>() | dc(q.to_f32())) >> bandrez()
}
pub fn pulse() -> An<PulseWave> {
An(PulseWave::new())
}
pub fn morph<F: Real>() -> An<Morph<F>> {
An(Morph::new(F::new(440), F::one(), F::zero()))
}
pub fn morph_hz<F: Real>(f: F, q: F, morph: F) -> An<Pipe<Stack<Pass, Constant<U3>>, Morph<F>>> {
(pass() | dc((f.to_f32(), q.to_f32(), morph.to_f32()))) >> An(Morph::new(f, q, morph))
}
pub fn wavech(wave: &Arc<Wave>, channel: usize, loop_point: Option<usize>) -> An<WavePlayer> {
An(WavePlayer::new(wave, channel, 0, wave.length(), loop_point))
}
pub fn wavech_at(
wave: &Arc<Wave>,
channel: usize,
start_point: usize,
end_point: usize,
loop_point: Option<usize>,
) -> An<WavePlayer> {
An(WavePlayer::new(
wave,
channel,
start_point,
end_point,
loop_point,
))
}
pub fn chorus(
seed: u64,
separation: f32,
variation: f32,
mod_frequency: f32,
) -> An<impl AudioNode<Inputs = U1, Outputs = U1>> {
(pass()
& (pass()
| lfo(move |t| {
(
lerp11(
separation,
separation + variation,
spline_noise(seed, t * mod_frequency),
),
lerp11(
separation * 2.0,
separation * 2.0 + variation,
spline_noise(hash1(seed), t * (mod_frequency + 0.02)),
),
lerp11(
separation * 3.0,
separation * 3.0 + variation,
spline_noise(hash2(seed), t * (mod_frequency + 0.04)),
),
lerp11(
separation * 4.0,
separation * 4.0 + variation,
spline_noise(hash1(seed ^ 0xfedcba), t * (mod_frequency + 0.06)),
),
)
}))
>> multitap::<U4>(separation, separation * 4.0 + variation))
* dc(0.2)
}
pub fn flanger<X: Fn(f32) -> f32 + Clone + Send + Sync>(
feedback_amount: f32,
minimum_delay: f32,
maximum_delay: f32,
delay_f: X,
) -> An<impl AudioNode<Inputs = U1, Outputs = U1>> {
pass()
& feedback2(
(pass() | lfo(delay_f)) >> tap(minimum_delay, maximum_delay),
shape(Tanh(feedback_amount.to_f32())),
)
}
pub fn phaser<X: Fn(f32) -> f32 + Clone + Send + Sync>(
feedback_amount: f32,
phase_f: X,
) -> An<impl AudioNode<Inputs = U1, Outputs = U1>> {
pass()
& feedback(
(pass() | lfo(move |t| lerp(2.0, 20.0, clamp01(phase_f(t)))))
>> pipei::<U10, _, _>(|_i| (pass() | add(0.05)) >> !allpole::<f32>())
>> (mul(feedback_amount) | sink()),
)
}
pub fn shared(value: f32) -> Shared {
Shared::new(value)
}
pub fn var(shared: &Shared) -> An<Var> {
An(Var::new(shared))
}
pub fn var_fn<F, R>(shared: &Shared, f: F) -> An<VarFn<F, R>>
where
F: Clone + Fn(f32) -> R + Send + Sync,
R: ConstantFrame<Sample = f32>,
R::Size: Size<f32>,
{
An(VarFn::new(shared, f))
}
pub fn timer(shared: &Shared) -> An<Timer> {
An(Timer::new(shared))
}
pub fn snoop(capacity: usize) -> (Snoop, An<SnoopBackend>) {
let (snoop, backend) = Snoop::new(capacity);
(snoop, An(backend))
}
pub fn resynth<I, O, F>(window_length: usize, processing: F) -> An<Resynth<I, O, F>>
where
I: Size<f32>,
O: Size<f32>,
F: FnMut(&mut FftWindow) + Clone + Send + Sync,
{
An(Resynth::new(window_length, processing))
}
pub fn impulse<N: Size<f32>>() -> An<Impulse<N>> {
An(Impulse::new())
}
pub fn rotate(angle: f32, gain: f32) -> An<Mixer<U2, U2>> {
An(Mixer::new(
[
[cos(angle) * gain, -sin(angle) * gain].into(),
[sin(angle) * gain, cos(angle) * gain].into(),
]
.into(),
))
}
pub fn unit<I: Size<f32>, O: Size<f32>>(unit: Box<dyn AudioUnit>) -> An<Unit<I, O>> {
An(Unit::new(unit))
}
pub fn dbell<F: Real, S: Shape>(shape: S) -> An<DirtyBiquad<F, BellBiquad<F>, S>> {
An(DirtyBiquad::new(BellBiquad::new(), shape))
}
pub fn dbell_hz<F: Real, S: Shape>(
shape: S,
center: F,
q: F,
gain: F,
) -> An<FixedDirtyBiquad<F, BellBiquad<F>, S>> {
let mut filter = FixedDirtyBiquad::new(BellBiquad::new(), shape);
filter.set_center_q_gain(center, q, gain);
An(filter)
}
pub fn fbell<F: Real, S: Shape>(shape: S) -> An<FbBiquad<F, BellBiquad<F>, S>> {
An(FbBiquad::new(BellBiquad::new(), shape))
}
pub fn fbell_hz<F: Real, S: Shape>(
shape: S,
center: F,
q: F,
gain: F,
) -> An<FixedFbBiquad<F, BellBiquad<F>, S>> {
let mut filter = FixedFbBiquad::new(BellBiquad::new(), shape);
filter.set_center_q_gain(center, q, gain);
An(filter)
}
pub fn dhighpass<F: Real, S: Shape>(shape: S) -> An<DirtyBiquad<F, HighpassBiquad<F>, S>> {
An(DirtyBiquad::new(HighpassBiquad::new(), shape))
}
pub fn dhighpass_hz<F: Real, S: Shape>(
shape: S,
cutoff: F,
q: F,
) -> An<FixedDirtyBiquad<F, HighpassBiquad<F>, S>> {
let mut filter = FixedDirtyBiquad::new(HighpassBiquad::new(), shape);
filter.set_center_q(cutoff, q);
An(filter)
}
pub fn fhighpass<F: Real, S: Shape>(shape: S) -> An<FbBiquad<F, HighpassBiquad<F>, S>> {
An(FbBiquad::new(HighpassBiquad::new(), shape))
}
pub fn fhighpass_hz<F: Real, S: Shape>(
shape: S,
cutoff: F,
q: F,
) -> An<FixedFbBiquad<F, HighpassBiquad<F>, S>> {
let mut filter = FixedFbBiquad::new(HighpassBiquad::new(), shape);
filter.set_center_q(cutoff, q);
An(filter)
}
pub fn dlowpass<F: Real, S: Shape>(shape: S) -> An<DirtyBiquad<F, LowpassBiquad<F>, S>> {
An(DirtyBiquad::new(LowpassBiquad::new(), shape))
}
pub fn dlowpass_hz<F: Real, S: Shape>(
shape: S,
cutoff: F,
q: F,
) -> An<FixedDirtyBiquad<F, LowpassBiquad<F>, S>> {
let mut filter = FixedDirtyBiquad::new(LowpassBiquad::new(), shape);
filter.set_center_q(cutoff, q);
An(filter)
}
pub fn flowpass<F: Real, S: Shape>(shape: S) -> An<FbBiquad<F, LowpassBiquad<F>, S>> {
An(FbBiquad::new(LowpassBiquad::new(), shape))
}
pub fn flowpass_hz<F: Real, S: Shape>(
shape: S,
cutoff: F,
q: F,
) -> An<FixedFbBiquad<F, LowpassBiquad<F>, S>> {
let mut filter = FixedFbBiquad::new(LowpassBiquad::new(), shape);
filter.set_center_q(cutoff, q);
An(filter)
}
pub fn dresonator<F: Real, S: Shape>(shape: S) -> An<DirtyBiquad<F, ResonatorBiquad<F>, S>> {
An(DirtyBiquad::new(ResonatorBiquad::new(), shape))
}
pub fn dresonator_hz<F: Real, S: Shape>(
shape: S,
center: F,
q: F,
) -> An<FixedDirtyBiquad<F, ResonatorBiquad<F>, S>> {
let mut filter = FixedDirtyBiquad::new(ResonatorBiquad::new(), shape);
filter.set_center_q(center, q);
An(filter)
}
pub fn fresonator<F: Real, S: Shape>(shape: S) -> An<FbBiquad<F, ResonatorBiquad<F>, S>> {
An(FbBiquad::new(ResonatorBiquad::new(), shape))
}
pub fn fresonator_hz<F: Real, S: Shape>(
shape: S,
center: F,
q: F,
) -> An<FixedFbBiquad<F, ResonatorBiquad<F>, S>> {
let mut filter = FixedFbBiquad::new(ResonatorBiquad::new(), shape);
filter.set_center_q(center, q);
An(filter)
}