Skip to content

Commit 6126465

Browse files
piedoomdoomy
authored andcommitted
added const defaults and types for mono and stereo echo, removed unnecessary config field
1 parent 24ee20b commit 6126465

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

crates/firewheel-nodes/src/echo.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::{array::from_fn, num::NonZeroU32};
22

33
use 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"))]
2828
use num_traits::Float;
2929

30+
pub type EchoNodeMono = EchoNode<1>;
31+
pub type EchoNodeStereo = EchoNode<2>;
32+
3033
const 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;
3740
pub 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

4445
impl 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

6056
impl 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,

examples/visual_node_graph/src/system.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use firewheel::{
88
nodes::{
99
beep_test::BeepTestNode,
1010
convolution::{ConvolutionNode, ConvolutionNodeConfig},
11-
echo::EchoNode,
11+
echo::{EchoNodeMono, EchoNodeStereo},
1212
fast_filters::{
1313
bandpass::FastBandpassNode, highpass::FastHighpassNode, lowpass::FastLowpassNode,
1414
},
@@ -182,8 +182,8 @@ impl AudioSystem {
182182
}),
183183
),
184184
NodeType::ConvolutionStereo => self.cx.add_node(ConvolutionNode::<2>::default(), None),
185-
NodeType::EchoMono => self.cx.add_node(EchoNode::<1>::default(), None),
186-
NodeType::EchoStereo => self.cx.add_node(EchoNode::<2>::default(), None),
185+
NodeType::EchoMono => self.cx.add_node(EchoNodeMono::default(), None),
186+
NodeType::EchoStereo => self.cx.add_node(EchoNodeStereo::default(), None),
187187
};
188188

189189
match node_type {

0 commit comments

Comments
 (0)