Skip to content

Commit

Permalink
make faust allocate on the heap instead of the stack
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed Apr 12, 2024
1 parent 0a2672c commit 44046aa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
23 changes: 22 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ description = "A lookahead compressor/limiter that's soft as a lamb"

[features]
faust-rebuild = ["dep:faust-build"]
default = ["default-boxed"]
default-boxed = ["dep:default-boxed"]

[workspace]
members = ["xtask"]
Expand All @@ -27,6 +29,7 @@ nih_plug = { git = "https://github.com/robbert-vdh/nih-plug.git", features = ["a
faust-types = { git = "https://github.com/Frando/rust-faust" }
nih_plug_vizia = { git = "https://github.com/robbert-vdh/nih-plug.git" }
atomic_float = "0.1"
default-boxed = { version = "0.2.0", optional=true }

[profile.release]
lto = "thin"
Expand All @@ -42,3 +45,4 @@ strip = "none"
# faust-build = { path = "../rust-faust/faust-build", optional = true }
faust-build = { git = "https://github.com/Frando/rust-faust", optional = true }
faust-types = { git = "https://github.com/Frando/rust-faust" }
default-boxed = { version = "0.2.0", optional=true }
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ mod buffer;
mod dsp;
use buffer::*;

use default_boxed::DefaultBoxed;

// this seems to be the number JUCE is using
// TODO: does this need to be set at runtime?
const MAX_SOUNDCARD_BUFFER_SIZE: usize = 32768;
Expand All @@ -17,7 +19,7 @@ const PEAK_METER_DECAY_MS: f64 = 150.0;

pub struct Lamb {
params: Arc<LambParams>,
dsp: dsp::LambRs,
dsp: Box<dsp::LambRs>,
accum_buffer: TempBuffer,
temp_output_buffer_l: [f64; MAX_SOUNDCARD_BUFFER_SIZE],
temp_output_buffer_r: [f64; MAX_SOUNDCARD_BUFFER_SIZE],
Expand Down Expand Up @@ -45,7 +47,7 @@ impl Default for Lamb {
gain_reduction_left: Arc::new(AtomicF32::new(0.0)),
gain_reduction_right: Arc::new(AtomicF32::new(0.0)),

dsp: dsp::LambRs::new(),
dsp: dsp::LambRs::default_boxed(),

accum_buffer: TempBuffer::default(),
temp_output_buffer_l: [0.0_f64; MAX_SOUNDCARD_BUFFER_SIZE],
Expand Down

1 comment on commit 44046aa

@magnetophon
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@obsoleszenz This fixed a stack overflow for me.
Might also be good for https://codeberg.org/obsoleszenz/lowpass-lr4-faust-nih-plug?
Also see Frando/rust-faust#14 and grame-cncm/faust#828

Please sign in to comment.