Esempio n. 1
0
  int play() {
    duhPlayer = al_start_duh(tune, 2, 0, 1.0, 8192, 22050);
    al_duh_set_loop(duhPlayer, repeat);
    set_volume(vol);

    return 1;
  }  
Esempio n. 2
0
 void restart()
 {
   if (tune != NULL) {
     al_stop_duh(duhPlayer);
     done = 0;
     duhPlayer = al_start_duh(tune, 2, 0, 1.0, 8192, 22050);
   }
 }
Esempio n. 3
0
int main(int argc, char *argv[]) {
	printf("Initializing Allegro.\n");
	allegro_init();
	install_keyboard();
	install_timer();
	install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL);
	
	printf("Initializing DUMB.\n");
	atexit(&dumb_exit);
	dumb_register_dat_s3m_quick(DUMB_DAT_S3M);
	
	printf("Loading datafile.\n");
	DATAFILE *music = load_datafile("music.dat");
	if(!music) {
		printf("Error loading music datafile.\n");
		return 1;
	}
	
	
	printf("Loading DUH.\n");
	DUH *bgsong = (DUH*)music[0].dat;
	if(!bgsong) {
		printf("Error getting song from datafile.\n");
		return 1;
	}
	
	printf("Starting DUH player.\n");
	AL_DUH_PLAYER *bgsong_player = al_start_duh(bgsong, 2, 0, 1.0f, 4096, 48000);
	if(!bgsong_player) {
		printf("Error starting player.\n");
		return 1;
	}
	
	
	printf("Entering main loop.\n");
	while(!key[KEY_ESC]) {
		al_poll_duh(bgsong_player);
		rest(0);
	}
	
	printf("Exiting successfully.\n");
	return 0;
}
Esempio n. 4
0
void playMusic(std::string file, float volume)
{
	if (playingFile == file) {
		return;
	}

	if (playing != NULL) {
		al_stop_duh(player);
		unload_duh(playing);
	}

	std::string fileName = ResourceHandler::getInstance()->getRealFilename(file);

	if (!exists(fileName.c_str())) {
		throw DBSH07_EXCEPTION("Unable to load " + fileName);
	}

	playing = dumb_load_xm_quick(fileName.c_str());
	player = al_start_duh(playing, 2, 0, volume, 4096, 44100);
	playingFile = file;

	pollMusic();
}
Esempio n. 5
0
int main(int argc, const char *const *argv) /* I'm const-crazy! */
{
	DUH *duh;          /* Encapsulates the music file. */
	AL_DUH_PLAYER *dp; /* Holds the current playback state. */

	/* Initialise Allegro */
	if (allegro_init())
		return EXIT_FAILURE;

	/* Check that we have one argument (plus the executable name). */
	if (argc != 2)
		usage(argv[0]);

	/* Tell Allegro where to find configuration data. This means you can
	 * put any settings for Allegro in dumb.ini. See Allegro's
	 * documentation for more information.
	 */
	set_config_file("dumb.ini");

	/* Initialise Allegro's keyboard input. */
	if (install_keyboard()) {
		allegro_message("Failed to initialise keyboard driver!\n");
		return EXIT_FAILURE;
	}

	/* This function call is appropriate for a program that will play one
	 * sample or one audio stream at a time. If you have sound effects
	 * too, you may want to increase the parameter. See Allegro's
	 * documentation for details on what the parameter means. Note that
	 * newer versions of Allegro act as if set_volume_per_voice() was
	 * called with parameter 1 initially, while older versions behave as
	 * if -1 was passed, so you should call the function if you want
	 * consistent behaviour.
	 */
	set_volume_per_voice(0);

	/* Initialise Allegro's sound output system. */
	if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL)) {
		allegro_message("Failed to initialise sound driver!\n%s\n", allegro_error);
		return EXIT_FAILURE;
	}

	/* dumb_exit() is a function defined by DUMB. This operation arranges
	 * for dumb_exit() to be called last thing before the program exits.
	 * dumb_exit() does a bit of cleaning up for you. atexit() is
	 * declared in stdlib.h.
	 */
	atexit(&dumb_exit);

	/* DUMB defines its own wrappers for file input. There is a struct
	 * called DUMBFILE that holds function pointers for the various file
	 * operations needed by DUMB. You can decide whether to use stdio
	 * FILE objects, Allegro's PACKFILEs or something else entirely. No
	 * wrapper is installed initially, so you must call this or
	 * dumb_register_stdfiles() or set up your own before trying to load
	 * modules by file name. (If you are using another method, such as
	 * loading an Allegro datafile with modules embedded in it, then DUMB
	 * never opens a file by file name so this doesn't apply.)
	 */
	dumb_register_packfiles();

	/* Load the module file into a DUH object. Quick and dirty: try the
	 * loader for each format until one succeeds. Note that 15-sample
	 * mods have no identifying features, so dumb_load_mod() may succeed
	 * on files that aren't mods at all. We therefore try that one last.
	 */
	duh = dumb_load_it(argv[1]);
	if (!duh) {
		duh = dumb_load_xm(argv[1]);
		if (!duh) {
			duh = dumb_load_s3m(argv[1]);
			if (!duh) {
				duh = dumb_load_mod(argv[1]);
				if (!duh) {
					allegro_message("Failed to load %s!\n", argv[1]);
					return EXIT_FAILURE;
				}
			}
		}
	}

	/* Read the quality values from the config file we told Allegro to
	 * use. You may want to hardcode these or provide a more elaborate
	 * interface via which the user can control them.
	 */
	dumb_resampling_quality = get_config_int("sound", "dumb_resampling_quality", 4);
	dumb_it_max_to_mix = get_config_int("sound", "dumb_it_max_to_mix", 128);

	/* If we're not in DOS, show a window and register our close hook
	 * function.
	 */
#	ifndef ALLEGRO_DOS
		{
			const char *fn = get_filename(argv[1]);
			gfx_half_width = strlen(fn);
			if (gfx_half_width < 22) gfx_half_width = 22;
			gfx_half_width = (gfx_half_width + 2) * 4;

			/* set_window_title() is not const-correct (yet). */
			set_window_title((char *)"DUMB Music Player");

			if (set_gfx_mode(GFX_DUMB_MODE, gfx_half_width*2, 80, 0, 0) == 0) {
				acquire_screen();
				textout_centre(screen, font, fn, gfx_half_width, 20, 14);
				textout_centre(screen, font, "Press any key to exit.", gfx_half_width, 52, 11);
				release_screen();
			} else
				gfx_half_width = 0;
		}

		/* Silly check to get around the fact that someone stupidly removed
		 * an old function from Allegro instead of deprecating it. The old
		 * function was put back a version later, but we may as well use the
		 * new one if it's there!
		 */
#		if ALLEGRO_VERSION*10000 + ALLEGRO_SUB_VERSION*100 + ALLEGRO_WIP_VERSION >= 40105
			set_close_button_callback(&closehook);
#		else
			set_window_close_hook(&closehook);
#		endif

#	endif

	/* We want to continue running if the user switches to another
	 * application.
	 */
	set_display_switch_mode(SWITCH_BACKGROUND);

	/* We have the music loaded, but it isn't playing yet. This starts it
	 * playing. We construct a second object, the AL_DUH_PLAYER, to
	 * represent the playing music. This means you can play the music
	 * twice at the same time should you want to!
	 *
	 * Specify the number of channels (2 for stereo), which 'signal' to
	 * play (always 0 for modules), the volume (1.0f for default), the
	 * buffer size (4096 generally works well) and the sampling frequency
	 * (ideally match the final output frequency Allegro is using). An
	 * Allegro audio stream will be started.
	 */
	dp = al_start_duh(duh, 2, 0, 1.0f,
		get_config_int("sound", "buffer_size", 4096),
		get_config_int("sound", "sound_freq", 44100));

	/* Register our callback functions so that they are called when the
	 * music loops or stops. See docs/howto.txt for more information.
	 * There is no threading issue: DUMB will only process playback
	 * in al_poll_duh(), which we call below.
	 */
	{
		DUH_SIGRENDERER *sr = al_duh_get_sigrenderer(dp);
		DUMB_IT_SIGRENDERER *itsr = duh_get_it_sigrenderer(sr);
		dumb_it_set_loop_callback(itsr, &loop_callback, NULL);
		dumb_it_set_xm_speed_zero_callback(itsr, &xm_speed_zero_callback, NULL);
	}

	/* Main loop. */
	for (;;) {
		/* Check for keys in the buffer. If we get one, discard it
		 * and exit the main loop.
		 */
		if (keypressed()) {
			readkey();
			break;
		}

		/* Poll the music. We exit the loop if al_poll_duh() has
		 * returned nonzero (music finished) or the window has been
		 * closed. al_poll_duh() might return nonzero if you have set
		 * up a callback that tells the music to stop.
		 */
		if (al_poll_duh(dp) || closed)
			break;

		/* Give other threads a look-in, or allow the processor to
		 * sleep for a bit. YIELD() is defined further up in this
		 * file.
		 */
		YIELD();
	}

	/* Remove the audio stream and deallocate the memory being used for
	 * the playback state. We set dp to NULL to emphasise that the object
	 * has gone.
	 */
	al_stop_duh(dp);
	dp = NULL;

	/* Free the DUH object containing the actual music data. */
	unload_duh(duh);
	duh = NULL;

	/* All done! */
	return EXIT_SUCCESS;
}
Esempio n. 6
0
void showIntro(void)
{
	allegro_gl_begin();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0, 800, 0, 600, -1, 1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glClearColor(0, 0, 0, 0);
	glShadeModel(GL_SMOOTH);
	glDepthFunc(GL_LEQUAL);
	glClearDepth(1.0);
	glEnable(GL_DEPTH_TEST);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	glEnable(GL_TEXTURE_2D);
	allegro_gl_end();

	GLuint machineballtex;
	allegro_gl_set_texture_format(GL_RGBA);
	BITMAP *bmp = create_bitmap_ex(32, 256, 64);
	blit(&mb_machineball_bmp, bmp, 0, 0, 0, 0, 256, 64);
	machineballtex = allegro_gl_make_masked_texture(bmp);
	destroy_bitmap(bmp);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	dp = al_start_duh(menuduh, 2, 0, (float)options.musicvol/255.0, 2048, 22050);
	menumusicisplaying=1;

	timer.install();
	double time;
	time=0;
	while(!(key[KEY_ESC] || time>23))
	{
		rest(1);
		time=timer.seconds();

		al_poll_duh(dp);

		allegro_gl_begin();
		
		glLoadIdentity();
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		if(time<4)
		{
			glColor3f(time/4, time/4, time/4);
			text.print(120, 280, "BENNY KRAMEK PRESENTS");
			glBindTexture(GL_TEXTURE_2D, bennykramekwebtex);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex2i(242, 180);
			glTexCoord2f(1, 0);
			glVertex2i(498, 180);
			glTexCoord2f(1, 1);
			glVertex2i(498, 212);
			glTexCoord2f(0, 1);
			glVertex2i(242, 212);
			glEnd();
		}
		else if(time<8)
		{
			glColor3f(1-((time-4)/4), 1-((time-4)/4), 1-((time-4)/4));
			text.print(120, 280, "BENNY KRAMEK PRESENTS");
			glBindTexture(GL_TEXTURE_2D, bennykramekwebtex);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex2i(242, 180);
			glTexCoord2f(1, 0);
			glVertex2i(498, 180);
			glTexCoord2f(1, 1);
			glVertex2i(498, 212);
			glTexCoord2f(0, 1);
			glVertex2i(242, 212);
			glEnd();
		}

		glColor3f(0.5, 0.5, 0.5);
		text.begin();
		text.print(20, (int)(60*(time-8.7)),     "THIS IS THE FUTURE.");
		text.print(20, (int)(60*(time-8.7))-50,  "A FUTURE WHERE PRIMITIVE SPORTS");
		text.print(20, (int)(60*(time-8.7))-100, "NO LONGER EXIST. IN THIS WORLD,");
		text.print(20, (int)(60*(time-8.7))-150, "THERE IS ONLY ONE SPORT.");
		text.print(20, (int)(60*(time-8.7))-200, "THERE IS ONLY...");
		text.end();

		if(time>22 && time<=22.5)
		{
			glColor3f(1, 1, 1);
			glBindTexture(GL_TEXTURE_2D, machineballtex);
			glTranslatef(400, 300, 0);
			glScalef((time-22)*200, (time-22)*200, (time-22)*200);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex2i(-4, -1);
			glTexCoord2f(1, 0);
			glVertex2i(4, -1);
			glTexCoord2f(1, 1);
			glVertex2i(4, 1);
			glTexCoord2f(0, 1);
			glVertex2i(-4, 1);
			glEnd();

		}
		if(time>22.5)
		{
			glColor3f(1, 1, 1);
			glBindTexture(GL_TEXTURE_2D, machineballtex);
			glTranslatef(400, 300+(time-22.5)*240, 0);
			glScalef(100-(time-22.5)*50, 100-(time-22.5)*50, 100-(time-22.5)*50);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex2i(-4, -1);
			glTexCoord2f(1, 0);
			glVertex2i(4, -1);
			glTexCoord2f(1, 1);
			glVertex2i(4, 1);
			glTexCoord2f(0, 1);
			glVertex2i(-4, 1);
			glEnd();
			glColor4f(1, 1, 1, 1-((time-22.5)));
			glLoadIdentity();
			glDisable(GL_TEXTURE_2D);
			glBegin(GL_QUADS);
			glVertex2i(0, 0);
			glVertex2i(800, 0);
			glVertex2i(800, 600);
			glVertex2i(0, 600);
			glEnd();
			glEnable(GL_TEXTURE_2D);
		}
		
		glFlush();
		allegro_gl_flip();
		allegro_gl_end();
	}

	glDeleteTextures(1, &machineballtex);
}