Skip to content

Commit

Permalink
fix for high-frequency noise
Browse files Browse the repository at this point in the history
improves e.g. motorcross maniacs 2, track 3
  • Loading branch information
baines committed May 13, 2017
1 parent a5c2261 commit df3865f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,24 @@ void update_noise(void){
if(c->enabled){
update_env(c);

if(update_freq(c)){
float sample = c->val;
int count = update_freq(c);
for(int j = 0; j < count; ++j){
c->lfsr_reg = (c->lfsr_reg << 1) | (c->val == 1);

if(c->lfsr_wide){
c->val = !(((c->lfsr_reg >> 14) & 1) ^ ((c->lfsr_reg >> 13) & 1)) ? 1 : -1;
} else {
c->val = !(((c->lfsr_reg >> 6 ) & 1) ^ ((c->lfsr_reg >> 5 ) & 1)) ? 1 : -1;
}
sample += c->val;
}

if(count){
sample /= (float)count;
}

float sample = hipass(c, c->val * (c->volume / 15.0f));
sample = hipass(c, sample * (c->volume / 15.0f));
if(!c->user_mute){
samples[i+0] += sample * 0.25f * c->on_left * vol_l;
samples[i+1] += sample * 0.25f * c->on_right * vol_r;
Expand Down

0 comments on commit df3865f

Please sign in to comment.