Add a basic version of Crisp
This commit is contained in:
parent
4cca7af930
commit
46901bf5c9
2 changed files with 14 additions and 10 deletions
|
@ -15,6 +15,7 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use nih_plug::prelude::*;
|
use nih_plug::prelude::*;
|
||||||
|
use pcg::Pcg32iState;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
|
||||||
mod pcg;
|
mod pcg;
|
||||||
|
@ -23,7 +24,7 @@ mod pcg;
|
||||||
const NUM_CHANNELS: usize = 2;
|
const NUM_CHANNELS: usize = 2;
|
||||||
|
|
||||||
/// These seeds being fixed makes bouncing deterministic.
|
/// These seeds being fixed makes bouncing deterministic.
|
||||||
const INITIAL_PRNG_SEEDS: [u32; 2] = [69, 420];
|
const INITIAL_PRNG_SEED: Pcg32iState = Pcg32iState::new(69, 420);
|
||||||
|
|
||||||
/// This plugin essentially layers the sound with another copy of the signal AM'ed with white (or
|
/// This plugin essentially layers the sound with another copy of the signal AM'ed with white (or
|
||||||
/// filtered) noise. That other copy of the sound may have a low pass filter applied to it since
|
/// filtered) noise. That other copy of the sound may have a low pass filter applied to it since
|
||||||
|
@ -31,9 +32,9 @@ const INITIAL_PRNG_SEEDS: [u32; 2] = [69, 420];
|
||||||
struct Crisp {
|
struct Crisp {
|
||||||
params: Pin<Box<CrispParams>>,
|
params: Pin<Box<CrispParams>>,
|
||||||
|
|
||||||
/// The OS RNG is only used for the initial seeds, after that we'll implement PCG ourselves so
|
/// A PRNG for generating noise, after that we'll implement PCG ourselves so we can easily
|
||||||
/// we can easily SIMD-ify this in the future.
|
/// SIMD-ify this in the future.
|
||||||
prng_seeds: [u32; NUM_CHANNELS],
|
prng: Pcg32iState,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Filters
|
// TODO: Filters
|
||||||
|
@ -51,7 +52,7 @@ impl Default for Crisp {
|
||||||
Self {
|
Self {
|
||||||
params: Box::pin(CrispParams::default()),
|
params: Box::pin(CrispParams::default()),
|
||||||
|
|
||||||
prng_seeds: INITIAL_PRNG_SEEDS,
|
prng: INITIAL_PRNG_SEED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +92,7 @@ impl Plugin for Crisp {
|
||||||
|
|
||||||
fn reset(&mut self) {
|
fn reset(&mut self) {
|
||||||
// By using the same seeds each time bouncing can be made deterministic
|
// By using the same seeds each time bouncing can be made deterministic
|
||||||
self.prng_seeds = INITIAL_PRNG_SEEDS;
|
self.prng = INITIAL_PRNG_SEED;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process(
|
fn process(
|
||||||
|
@ -103,9 +104,12 @@ impl Plugin for Crisp {
|
||||||
let amount = self.params.amount.smoothed.next();
|
let amount = self.params.amount.smoothed.next();
|
||||||
|
|
||||||
// TODO: SIMD-ize this to process both channels at once
|
// TODO: SIMD-ize this to process both channels at once
|
||||||
for (channel_idx, sample) in channel_samples.into_iter().enumerate() {
|
// TODO: This does not sound quite right
|
||||||
// TODO: Calculate some uniformly (or Gaussian?) distributed white noise in the
|
for sample in channel_samples.into_iter() {
|
||||||
// range of `[-1, 1]`, add that scaled by `amount` to `sample`.
|
let noise = self.prng.next_f32() * 2.0 - 1.0;
|
||||||
|
let am = *sample * noise;
|
||||||
|
|
||||||
|
*sample += am * amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ impl Pcg32iState {
|
||||||
.wrapping_mul(PCG_DEFAULT_MULTIPLIER_32)
|
.wrapping_mul(PCG_DEFAULT_MULTIPLIER_32)
|
||||||
.wrapping_add(self.inc);
|
.wrapping_add(self.inc);
|
||||||
|
|
||||||
let word = ((old_state >> ((old_state >> 28) + 4)) ^ old_state) * 277803737;
|
let word = ((old_state >> ((old_state >> 28) + 4)) ^ old_state).wrapping_mul(277803737);
|
||||||
(word >> 22) ^ word
|
(word >> 22) ^ word
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue