int main(void) { int i; if (!al_init()) { abort_example("Could not init Allegro.\n"); } al_install_keyboard(); open_log(); display = al_create_display(640, 100); if (!display) { abort_example("Could not create display.\n"); } if (!al_install_audio()) { abort_example("Could not init sound.\n"); } al_reserve_samples(N); al_set_mixer_postprocess_callback(al_get_default_mixer(), update_waveform, NULL); mainloop(); close_log(false); for (i = 0; i < N; i++) { al_destroy_audio_stream(stream[i]); } al_uninstall_audio(); return 0; }
int main(int argc, char *argv[]) { ALLEGRO_DISPLAY *display; (void)argc; (void)argv; if (!al_init()) { abort_example("Could not init Allegro.\n"); } open_log(); al_install_keyboard(); al_install_mouse(); al_init_primitives_addon(); al_init_font_addon(); al_init_ttf_addon(); al_set_new_display_flags(ALLEGRO_GENERATE_EXPOSE_EVENTS); display = al_create_display(800, 600); if (!display) { abort_example("Unable to create display\n"); } al_set_window_title(display, "Synthesiser of sorts"); font_gui = al_load_ttf_font("data/DejaVuSans.ttf", 12, 0); if (!font_gui) { abort_example("Failed to load data/fixed_font.tga\n"); } if (!al_install_audio()) { abort_example("Could not init sound!\n"); } if (!al_reserve_samples(0)) { abort_example("Could not set up voice and mixer.\n"); } size_t buffers = 8; unsigned samples = SAMPLES_PER_BUFFER; unsigned freq = STREAM_FREQUENCY; ALLEGRO_AUDIO_DEPTH depth = ALLEGRO_AUDIO_DEPTH_FLOAT32; ALLEGRO_CHANNEL_CONF ch = ALLEGRO_CHANNEL_CONF_1; stream1 = al_create_audio_stream(buffers, samples, freq, depth, ch); stream2 = al_create_audio_stream(buffers, samples, freq, depth, ch); stream3 = al_create_audio_stream(buffers, samples, freq, depth, ch); stream4 = al_create_audio_stream(buffers, samples, freq, depth, ch); stream5 = al_create_audio_stream(buffers, samples, freq, depth, ch); if (!stream1 || !stream2 || !stream3 || !stream4 || !stream5) { abort_example("Could not create stream.\n"); } ALLEGRO_MIXER *mixer = al_get_default_mixer(); if ( !al_attach_audio_stream_to_mixer(stream1, mixer) || !al_attach_audio_stream_to_mixer(stream2, mixer) || !al_attach_audio_stream_to_mixer(stream3, mixer) || !al_attach_audio_stream_to_mixer(stream4, mixer) || !al_attach_audio_stream_to_mixer(stream5, mixer) ) { abort_example("Could not attach stream to mixer.\n"); } al_set_mixer_postprocess_callback(mixer, mixer_pp_callback, mixer); /* Prog is destroyed at the end of this scope. */ { Theme theme(font_gui); Prog prog(theme, display); prog.run(); } al_destroy_audio_stream(stream1); al_destroy_audio_stream(stream2); al_destroy_audio_stream(stream3); al_destroy_audio_stream(stream4); al_destroy_audio_stream(stream5); al_uninstall_audio(); al_destroy_font(font_gui); al_fclose(save_fp); close_log(false); return 0; }
int main(int argc, char **argv) { const char *filename = "../demos/cosmic_protector/data/sfx/title_music.ogg"; ALLEGRO_VOICE *voice; ALLEGRO_MIXER *mixer; ALLEGRO_AUDIO_STREAM *stream; if (argc > 1) { filename = argv[1]; } if (!al_init()) { abort_example("Could not init Allegro.\n"); return 1; } al_init_primitives_addon(); al_init_image_addon(); al_init_acodec_addon(); al_install_keyboard(); display = al_create_display(640, 480); if (!display) { abort_example("Could not create display.\n"); return 1; } dbuf = al_create_bitmap(640, 480); bmp = al_load_bitmap("data/mysha.pcx"); if (!bmp) { abort_example("Could not load data/mysha.pcx\n"); return 1; } if (!al_install_audio()) { abort_example("Could not init sound.\n"); return 1; } voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2); if (!voice) { abort_example("Could not create voice.\n"); return 1; } mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2); if (!mixer) { abort_example("Could not create mixer.\n"); return 1; } if (!al_attach_mixer_to_voice(mixer, voice)) { abort_example("al_attach_mixer_to_voice failed.\n"); return 1; } stream = al_load_audio_stream(filename, 4, 2048); if (!stream) { abort_example("Could not load '%s'\n", filename); return 1; } al_set_audio_stream_playmode(stream, ALLEGRO_PLAYMODE_LOOP); al_attach_audio_stream_to_mixer(stream, mixer); al_set_mixer_postprocess_callback(mixer, update_meter, NULL); main_loop(); al_destroy_audio_stream(stream); al_destroy_mixer(mixer); al_destroy_voice(voice); al_uninstall_audio(); al_destroy_bitmap(dbuf); al_destroy_bitmap(bmp); return 0; }