summaryrefslogtreecommitdiff
path: root/examples/sinewave.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/sinewave.c')
-rw-r--r--examples/sinewave.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/examples/sinewave.c b/examples/sinewave.c
index f2b2580..0c33803 100644
--- a/examples/sinewave.c
+++ b/examples/sinewave.c
@@ -1,9 +1,6 @@
#include "../graphics.c"
-i64 time_0 = 0;
-i64 audio_samples = 0;
-
-f32 frames[SOUND_SAMPLE_RATE * NUM_SOUND_CHANNELS] = {0};
+f32 frames[PRIMARY_SOUND_SAMPLE_RATE * NUM_PRIMARY_SOUND_CHANNELS] = {0};
b8 ui_button(f64 x, f64 y, f64 width, f64 height) {
b8 has_cursor = g_platform.cursor_x >= x && g_platform.cursor_x < x + width &&
@@ -22,21 +19,18 @@ b8 ui_button(f64 x, f64 y, f64 width, f64 height) {
}
void update_and_render_frame(void) {
- i32 num_events = p_handle_events();
+ i32 num_events = handle_main_window_events();
if (num_events > 0) {
fill_rectangle(RGB(.1f, .1f, .1f), 0, 0, g_platform.frame_width, g_platform.frame_height);
if (ui_button(100, 100, 200, 200))
- p_queue_sound(0, SOUND_SAMPLE_RATE, frames);
+ queue_primary_sound(0, PRIMARY_SOUND_SAMPLE_RATE, frames);
}
- i64 samples_elapsed = ((p_time() - time_0) * SOUND_SAMPLE_RATE) / 1000 - audio_samples;
- audio_samples += samples_elapsed;
-
- p_handle_sound();
- p_render_frame();
- p_sleep_for(0);
+ handle_primary_sound();
+ render_main_window_frame();
+ suspend_thread_for_milliseconds(0);
}
i32 main(i32 argc, c8 **argv) {
@@ -44,14 +38,14 @@ i32 main(i32 argc, c8 **argv) {
(void) argv;
g_platform = (Platform) {
- .title = "Sine Wave",
- .graceful_exit = 1,
+ .title = "Sine Wave",
+ .graceful_shutdown = 1,
};
f64 frequency = 440.;
- for (i64 i = 0; i < SOUND_SAMPLE_RATE; ++i) {
- f64 t = ((f64) i) / SOUND_SAMPLE_RATE;
+ for (i64 i = 0; i < PRIMARY_SOUND_SAMPLE_RATE; ++i) {
+ f64 t = ((f64) i) / PRIMARY_SOUND_SAMPLE_RATE;
f64 x = sin(t * (M_PI * 2.) * frequency);
if (t < .005)
x *= t / .005;
@@ -61,8 +55,6 @@ i32 main(i32 argc, c8 **argv) {
frames[i * 2 + 1] = (f32) (x * .5);
}
- time_0 = p_time();
-
- p_event_loop();
+ run_main_window_event_loop();
return 0;
}