11use core:: { array:: from_fn, num:: NonZeroU32 } ;
22
33use firewheel_core:: {
4- channel_config:: { ChannelConfig , NonZeroChannelCount } ,
4+ channel_config:: ChannelConfig ,
55 diff:: { Diff , Notify , Patch } ,
66 dsp:: {
77 buffer:: ChannelBuffer ,
@@ -27,6 +27,9 @@ use firewheel_core::{
2727#[ cfg( not( feature = "std" ) ) ]
2828use num_traits:: Float ;
2929
30+ pub type EchoNodeMono = EchoNode < 1 > ;
31+ pub type EchoNodeStereo = EchoNode < 2 > ;
32+
3033const DEFAULT_DELAY_SMOOTH_SECONDS : f32 = 0.25 ;
3134
3235/// The configuration for an [`EchoNode`]
@@ -37,41 +40,30 @@ const DEFAULT_DELAY_SMOOTH_SECONDS: f32 = 0.25;
3740pub struct EchoNodeConfig {
3841 /// The maximum amount of samples available per channel
3942 pub buffer_capacity : usize ,
40- /// The number of supported channels
41- pub channels : NonZeroChannelCount ,
4243}
4344
4445impl EchoNodeConfig {
4546 /// Create a configuration that can hold up to a specified number of seconds
4647 /// of audio
47- pub fn new (
48- max_duration_seconds : f32 ,
49- sample_rate : impl Into < NonZeroU32 > ,
50- channels : impl Into < NonZeroChannelCount > ,
51- ) -> Self {
48+ pub fn new ( max_duration_seconds : f32 , sample_rate : impl Into < NonZeroU32 > ) -> Self {
5249 Self {
5350 buffer_capacity : ( max_duration_seconds * sample_rate. into ( ) . get ( ) as f32 ) . ceil ( )
5451 as usize ,
55- channels : channels. into ( ) ,
5652 }
5753 }
5854}
5955
6056impl Default for EchoNodeConfig {
6157 fn default ( ) -> Self {
6258 // Assume a common rate, as it cannot be known at compile time
63- Self :: new (
64- 5.0 ,
65- NonZeroU32 :: new ( 44_100 ) . unwrap ( ) ,
66- NonZeroChannelCount :: STEREO ,
67- )
59+ Self :: new ( 5.0 , NonZeroU32 :: new ( 44_100 ) . unwrap ( ) )
6860 }
6961}
7062
7163#[ derive( Diff , Patch , Debug , Clone , Copy , PartialEq ) ]
7264#[ cfg_attr( feature = "bevy" , derive( bevy_ecs:: prelude:: Component ) ) ]
7365#[ cfg_attr( feature = "bevy_reflect" , derive( bevy_reflect:: Reflect ) ) ]
74- pub struct EchoNode < const CHANNELS : usize > {
66+ pub struct EchoNode < const CHANNELS : usize = 2 > {
7567 /// The lowpass frequency in hertz in the range
7668 /// `[20.0, 20480.0]`.
7769 pub feedback_lpf : f32 ,
0 commit comments