/* * Example program for the Allegro library. */ #include #include "allegro5/allegro.h" #include "allegro5/allegro_audio.h" #include "allegro5/allegro_font.h" #include "common.c" #define RESERVED_SAMPLES 16 #define PERIOD 5 static ALLEGRO_DISPLAY *display; static ALLEGRO_FONT *font; static ALLEGRO_SAMPLE *ping; static ALLEGRO_TIMER *timer; static ALLEGRO_EVENT_QUEUE *event_queue; static ALLEGRO_SAMPLE *create_sample_s16(int freq, int len) { char *buf = al_malloc(freq * len * sizeof(int16_t)); return al_create_sample(buf, len, freq, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_1, true); } /* Adapted from SPEED. */ static ALLEGRO_SAMPLE *generate_ping(void) { float osc1, osc2, vol, ramp; int16_t *p; int len; int i; /* ping consists of two sine waves */ len = 8192; ping = create_sample_s16(22050, len); if (!ping) return NULL; p = (int16_t *)al_get_sample_data(ping); osc1 = 0; osc2 = 0; for (i=0; i 1) { bps--; al_set_timer_speed(timer, 1.0 / bps); } } } else if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } if (redraw && al_is_event_queue_empty(event_queue)) { ALLEGRO_COLOR c; if (last_timer % PERIOD == 0) c = al_map_rgb_f(1, 1, 1); else c = al_map_rgb_f(0.5, 0.5, 1.0); al_clear_to_color(al_map_rgb(0, 0, 0)); al_draw_textf(font, c, 640/32, 480/32 - 4, ALLEGRO_ALIGN_CENTRE, "%u", last_timer); al_flip_display(); } } close_log(false); return 0; } /* vim: set sts=3 sw=3 et: */