Skip to content

Commit

Permalink
src/oscillators.c: Two-zeros at Nyquist to make white noise pinker.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpwe committed Aug 18, 2024
1 parent 2aadc8d commit 503f020
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/amy.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ void osc_note_on(uint16_t osc, float initial_freq) {
if(synth[osc].wave==PULSE) pulse_note_on(osc, initial_freq);
if(synth[osc].wave==PCM) pcm_note_on(osc);
if(synth[osc].wave==ALGO) algo_note_on(osc);
if(synth[osc].wave==NOISE) noise_note_on(osc);
if(AMY_HAS_PARTIALS == 1) {
if(synth[osc].wave==PARTIAL) partial_note_on(osc);
if(synth[osc].wave==PARTIALS) partials_note_on(osc);
Expand Down
1 change: 1 addition & 0 deletions src/amy.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ extern void saw_down_note_on(uint16_t osc, float initial_freq);
extern void saw_up_note_on(uint16_t osc, float initial_freq);
extern void triangle_note_on(uint16_t osc, float initial_freq);
extern void pulse_note_on(uint16_t osc, float initial_freq);
extern void noise_note_on(uint16_t osc);
extern void pcm_note_on(uint16_t osc);
extern void pcm_note_off(uint16_t osc);
extern void custom_note_on(uint16_t osc, float freq);
Expand Down
15 changes: 14 additions & 1 deletion src/oscillators.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,15 +486,28 @@ SAMPLE amy_get_random() {

/* noise */

void noise_note_on(uint16_t osc) {
synth[osc].last_two[0] = 0;
synth[osc].last_two[1] = 0;
}

SAMPLE render_noise(SAMPLE *buf, uint16_t osc) {
SAMPLE amp = F2S(msynth[osc].amp);
SAMPLE max_value = 0;
SAMPLE last_white = synth[osc].last_two[0];
SAMPLE last_last_white = synth[osc].last_two[1];
for(uint16_t i=0;i<AMY_BLOCK_SIZE;i++) {
SAMPLE value = MUL4_SS(amy_get_random(), amp);
SAMPLE white = MUL4_SS(amy_get_random(), amp);
// Two-zero LPF to make the noise a little more pink, closer to Juno noise.
SAMPLE value = white + last_white + last_white + last_last_white;
last_last_white = last_white;
last_white = white;
buf[i] += value;
if (value < 0) value = -value;
if (value > max_value) max_value = value;
}
synth[osc].last_two[0] = last_white;
synth[osc].last_two[1] = last_last_white;
return max_value;
}

Expand Down

0 comments on commit 503f020

Please sign in to comment.