diff --git a/include/audio.h b/include/audio.h index 498690e..61f2e53 100644 --- a/include/audio.h +++ b/include/audio.h @@ -127,8 +127,6 @@ typedef struct { float right_cap; int history_timer; - float smooth_left; - float smooth_right; double cycles_needed; diff --git a/include/common.h b/include/common.h index 22b437a..653cb55 100644 --- a/include/common.h +++ b/include/common.h @@ -10,6 +10,7 @@ typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; +#define FAST_FORWARD_SPEED 2 #define BIT(a, n) ((a & (1 << n)) ? 1 : 0) #define BIT_SET(a, n, on) {if(on) a |= (1 << n); else a &= ~(1 << n);} #define BETWEEN(a, b, c) ((a >= b) && (a <= c)) diff --git a/include/emu.h b/include/emu.h index fda3c47..4720782 100644 --- a/include/emu.h +++ b/include/emu.h @@ -8,6 +8,7 @@ typedef struct { bool die; u64 ticks; const char *app_path; + bool fast_forward; } emu_context; int emu_run(int, char**); diff --git a/lib/audio.c b/lib/audio.c index ce6c991..c04d737 100644 --- a/lib/audio.c +++ b/lib/audio.c @@ -8,10 +8,9 @@ #include #include -#define SAMPLE_RATE 44100.0 +#define SAMPLE_RATE 192000.0 #define FRAMES_PER_BUFFER 64 #define SAMPLES_PER_AUDIO_TICK SAMPLE_RATE / 4194304.0 -#define LPF_BETA 0.025f #define HISTORY_INTERVAL 5 const u8 square_sample_00[8] = { @@ -282,19 +281,8 @@ void audio_sample_tick() { u8 right_vol = ctx.volume_right == 0 ? 1 : ctx.volume_right; left *= (float)left_vol/7.0f; right *= (float)right_vol/7.0f; - ctx.smooth_left = ctx.smooth_left - (LPF_BETA * (ctx.smooth_left - left)); - ctx.smooth_right = ctx.smooth_right - (LPF_BETA * (ctx.smooth_right - right)); - ctx.cycles_needed += SAMPLES_PER_AUDIO_TICK; + ctx.cycles_needed += emu_get_context()->fast_forward ? SAMPLES_PER_AUDIO_TICK/FAST_FORWARD_SPEED : SAMPLES_PER_AUDIO_TICK; if(ctx.cycles_needed > 1){ - //printf("tick\n"); - //if(ctx.buffer_cnt == AUDIO_BUFFER_SIZE){ - //ctx.buffer_cnt--; - //ctx.sq1_read_index++; - //ctx.sq1_read_index %= AUDIO_BUFFER_SIZE; - //delay(1); - //printf("overflow\n"); - //return; - //} ctx.cycles_needed -= 1; @@ -302,10 +290,10 @@ void audio_sample_tick() { float left_out = 0; float right_out = 0; if(dacs) { - left_out = ctx.smooth_left - ctx.left_cap; - right_out = ctx.smooth_right - ctx.right_cap; - ctx.left_cap = ctx.smooth_left - left_out * 0.999958; - ctx.right_cap = ctx.smooth_right - right_out * 0.999958; + left_out = left - ctx.left_cap; + right_out = right - ctx.right_cap; + ctx.left_cap = left - left_out * 0.999958; + ctx.right_cap = right - right_out * 0.999958; } @@ -324,11 +312,13 @@ void audio_sample_tick() { if(right_out > 1.0f) { right_out = 1; } - - ctx.left_audio_buffer[(ctx.buffer_write_index)] = left_out; - ctx.right_audio_buffer[(ctx.buffer_write_index)] = right_out; - ctx.buffer_write_index++; + if(ctx.buffer_write_index < FRAMES_PER_BUFFER){ + ctx.left_audio_buffer[(ctx.buffer_write_index)] = left_out; + ctx.right_audio_buffer[(ctx.buffer_write_index)] = right_out; + ctx.buffer_write_index++; + } + ctx.history_timer++; if(ctx.history_timer >= HISTORY_INTERVAL){ ctx.history_timer = 0; diff --git a/lib/ui.c b/lib/ui.c index 92a3d9d..a3084be 100644 --- a/lib/ui.c +++ b/lib/ui.c @@ -282,13 +282,11 @@ void ui_update() { update_debug_window(); } -static bool ff = false; - void ui_on_key(bool down, u32 key_code) { if(key_code == SDLK_SPACE && down == true) { - ff = !ff; - if(ff){ - ppu_get_context()->target_frame_time = 1000/300; + emu_get_context()->fast_forward = !emu_get_context()->fast_forward; + if(emu_get_context()->fast_forward){ + ppu_get_context()->target_frame_time = 1000/(60 * FAST_FORWARD_SPEED); } else { ppu_get_context()->target_frame_time = 1000/60; }