working on fixing wave and noise
This commit is contained in:
parent
e00b81304a
commit
0518c079cc
21
lib/audio.c
21
lib/audio.c
@ -96,9 +96,9 @@ static int audio_callback(const void* input_uffer, void *output_buffer,
|
||||
ctx.ch3_period_timer = ctx.ch3_period_reset;
|
||||
ctx.ch3_sample = (ctx.ch3_sample + 1) % 32;
|
||||
if(ctx.ch3_sample & 0b1) {
|
||||
ctx.ch3_last_sample = ctx.wave_ram[ctx.ch3_sample << 1] & 0xF;
|
||||
ctx.ch3_last_sample = ctx.wave_ram[ctx.ch3_sample >> 1] & 0xF;
|
||||
} else {
|
||||
ctx.ch3_last_sample = ctx.wave_ram[ctx.ch3_sample << 1] >> 4;
|
||||
ctx.ch3_last_sample = ctx.wave_ram[ctx.ch3_sample >> 1] >> 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,12 +106,12 @@ static int audio_callback(const void* input_uffer, void *output_buffer,
|
||||
for(;lfsr_timer >= lfsr_clock;lfsr_timer -= lfsr_clock) {
|
||||
if(lfsr_timer >= lfsr_clock && ctx.ch4_enable) {
|
||||
lfsr_timer = 0;
|
||||
ctx.ch4_lfsr = ctx.ch4_lfsr >> 1;
|
||||
u8 new = (!(ctx.ch4_lfsr & 0b1) ^ ((ctx.ch4_lfsr >> 1)) & 0b1);
|
||||
u8 new = !((ctx.ch4_lfsr & 0b1) ^ ((ctx.ch4_lfsr >> 1) & 0b1)) & 0b1;
|
||||
ctx.ch4_lfsr |= (new << 15);
|
||||
if(ctx.ch4_lfsr_width) {
|
||||
ctx.ch4_lfsr |= (new << 7);
|
||||
}
|
||||
ctx.ch4_lfsr = ctx.ch4_lfsr >> 1;
|
||||
//printf("lfsr: %02X, bit: %d\n", ctx.ch4_lfsr, new);
|
||||
}
|
||||
}
|
||||
@ -134,13 +134,20 @@ static int audio_callback(const void* input_uffer, void *output_buffer,
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx.ch3_enable) {
|
||||
if(ctx.ch3_enable && ctx.ch3_volume != 00) {
|
||||
u8 shift = 0;
|
||||
if(ctx.ch3_volume == 0b10) {
|
||||
shift = 1;
|
||||
}
|
||||
if(ctx.ch3_volume == 0b11) {
|
||||
shift = 2;
|
||||
}
|
||||
if(ctx.ch3_left) {
|
||||
left += ((float)ctx.ch3_volume/4.0f) * (((float)(ctx.ch3_last_sample) - 7.5f)/7.5f);
|
||||
left += (((float)(ctx.ch3_last_sample >> shift) - 7.5f)/7.5f);
|
||||
//printf("left: %d\n", ctx.ch3_volume);
|
||||
}
|
||||
if(ctx.ch3_right) {
|
||||
right += ((float)ctx.ch3_volume/4.0f) * (((float)(ctx.ch3_last_sample) - 7.5f)/7.5f);
|
||||
right += (((float)(ctx.ch3_last_sample >> shift) - 7.5f)/7.5f);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user