diff options
Diffstat (limited to 'examples/sinewave.c')
-rwxr-xr-x | examples/sinewave.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/examples/sinewave.c b/examples/sinewave.c index e45f71e..a1f19f8 100755 --- a/examples/sinewave.c +++ b/examples/sinewave.c @@ -49,12 +49,14 @@ b8 ui_button(f64 x, f64 y, f64 width, f64 height) { } void update_and_render_frame(void) { - p_handle_events(); + i32 num_events = p_handle_events(); - fill_rectangle(OP_SET, 0x202020, 0, 0, platform.frame_width, platform.frame_height); + if (num_events > 0) { + fill_rectangle(OP_SET, 0x202020, 0, 0, platform.frame_width, platform.frame_height); - if (ui_button(100, 100, 200, 200)) - p_queue_sound(0, AUDIO_SAMPLE_RATE, frames); + if (ui_button(100, 100, 200, 200)) + p_queue_sound(0, AUDIO_SAMPLE_RATE, frames); + } i64 samples_elapsed = ((p_time() - time_0) * AUDIO_SAMPLE_RATE) / 1000 - audio_samples; audio_samples += samples_elapsed; @@ -73,17 +75,17 @@ i32 main(i32 argc, c8 **argv) { .graceful_exit = 1, }; - f64 frequency = 440. * 6; + f64 frequency = 440.; for (i64 i = 0; i < AUDIO_SAMPLE_RATE; ++i) { f64 t = ((f64) i) / AUDIO_SAMPLE_RATE; - f64 x = sin(t * frequency); + f64 x = sin(t * (M_PI * 2.) * frequency); if (t < .005) x *= t / .005; if (t > .1) x *= (1. - t) / .9; - frames[i * 2] = (f32) x * .5; - frames[i * 2 + 1] = (f32) x * .5; + frames[i * 2] = (f32) (x * .5); + frames[i * 2 + 1] = (f32) (x * .5); } time_0 = p_time(); |