Skip to content

Commit

Permalink
Dynamically allocate saw table
Browse files Browse the repository at this point in the history
In debug builds, this gets stack allocated, which can cause stack
overflow. See:

https://users.rust-lang.org/t/how-do-i-use-lazy-static-to-initialize-a-large-static-array/22184
  • Loading branch information
raphlinus committed Jan 30, 2019
1 parent 09810aa commit 9f7975e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions synthesizer-io-core/src/modules/saw.rs
Expand Up @@ -31,9 +31,10 @@ const N_SLICES: usize = 36;
const SLICE_BASE: f32 = -9.609300863499751;
const SLICE_OVERLAP: f32 = 0.125;

// TODO: it might be better to include this as a literal, generated by script
lazy_static! {
static ref SAWTAB: [[f32; N_SAMPLES + 1]; N_SLICES] = {
let mut t = [[0.0; N_SAMPLES + 1]; N_SLICES];
static ref SAWTAB: Box<[[f32; N_SAMPLES + 1]]> = {
let mut t = vec![[0.0; N_SAMPLES + 1]; N_SLICES];

let mut lut = [0.0; N_SAMPLES / 2];
let slice_inc = (1.0 / SLICES_PER_OCTAVE as f32).exp2();
Expand Down Expand Up @@ -68,7 +69,7 @@ lazy_static! {
n_partials_last = n_partials;
f_0 *= 1.0 / slice_inc;
}
t
t.into_boxed_slice()
};
}

Expand Down

0 comments on commit 9f7975e

Please sign in to comment.