Code Search for Developers
 
 
  

exsample.c from Allegro game programming library at Krugle


Show exsample.c syntax highlighted

/*
 *    Example program for the Allegro library, by Shawn Hargreaves.
 *
 *    This program demonstrates how to play samples.
 */


#include "allegro.h"



int main(int argc, char *argv[])
{
   AL_SAMPLE *the_sample;
   int pan = 128;
   int pitch = 1000;

   allegro_init();

   if (argc != 2) {
      al_show_message("Usage: 'exsample filename.[wav|voc]'\n");
      return 1;
   }

   al_install_keyboard(); 
   al_install_timer();

   /* install a digital sound driver */
   if (al_install_sound(DIGI_AUTODETECT, AL_MIDI_NONE, argv[0]) != 0) {
      al_show_message("Error initialising sound system\n%s\n", al_error);
      return 1;
   }

   /* read in the WAV file */
   the_sample = al_load_sample(argv[1]);
   if (!the_sample) {
      al_show_message("Error reading WAV file '%s'\n", argv[1]);
      return 1;
   }

   if (al_set_gfx_mode(AL_GFX_SAFE, 320, 200, 0, 0) != 0) {
      al_set_gfx_mode(AL_GFX_NONE, 0, 0, 0, 0);
      al_show_message("Unable to set any graphic mode\n%s\n", al_error);
      return 1;
   }
   al_set_palette(al_desktop_palette);
   al_clear_to_color(al_screen, al_make_color(255,255,255));
   al_text_mode(-1);

   al_printf_text_centre(al_screen, al_font_8x8, AL_SCREEN_W/2, AL_SCREEN_H/3, al_make_color(0, 0, 0),
		     "Driver: %s", digi_driver->name);
   al_printf_text_centre(al_screen, al_font_8x8, AL_SCREEN_W/2, AL_SCREEN_H/2, al_make_color(0, 0, 0),
		     "Playing %s", argv[1]);
   al_printf_text_centre(al_screen, al_font_8x8, AL_SCREEN_W/2, AL_SCREEN_H*2/3, al_make_color(0, 0, 0),
		     "Use the arrow keys to adjust it");

   /* start up the sample */
   al_play_sample(the_sample, 255, pan, pitch, TRUE);

   do {
      al_poll_keyboard();

      /* alter the pan position? */
      if ((al_key[AL_KEY_LEFT]) && (pan > 0))
	 pan--;
      else if ((al_key[AL_KEY_RIGHT]) && (pan < 255))
	 pan++;

      /* alter the pitch? */
      if ((al_key[AL_KEY_UP]) && (pitch < 16384))
	 pitch = ((pitch * 513) / 512) + 1; 
      else if ((al_key[AL_KEY_DOWN]) && (pitch > 64))
	 pitch = ((pitch * 511) / 512) - 1; 

      /* adjust the sample */
      al_adjust_sample(the_sample, 255, pan, pitch, TRUE);

      /* delay a bit */
      al_rest(2);

   } while ((!al_key[AL_KEY_ESC]) && (!al_key[AL_KEY_SPACE]));

   /* destroy the sample */
   al_destroy_sample(the_sample);

   return 0;
}

AL_END_OF_MAIN();




See more files for this project here

Allegro game programming library

Allegro is a cross-platform library intended for use in computer games and other types of multimedia programming.

Project homepage: http://sourceforge.net/projects/alleg
Programming language(s): Assembly,C,Shell Script
License: other

  allegro.pcx
  ex12bit.c
  ex3buf.c
  ex3d.c
  exaccel.c
  exalpha.c
  example.dat
  example.h
  examples.txt
  exbitmap.c
  exblend.c
  excamera.c
  excolmap.c
  excustom.c
  exdata.c
  exdbuf.c
  exdodgy.c
  exexedat.c
  exfixed.c
  exflame.c
  exflip.c
  exgui.c
  exhello.c
  exjoy.c
  exkeys.c
  exlights.c
  exmem.c
  exmidi.c
  exmouse.c
  expal.c
  expat.c
  exquat.c
  exrgbhsv.c
  exsample.c
  exscale.c
  exscn3d.c
  exscroll.c
  exshade.c
  exspline.c
  exsprite.c
  exstars.c
  exstream.c
  exswitch.c
  extimer.c
  extrans.c
  extruec.c
  exunicod.c
  exupdate.c
  exxfade.c
  exzbuf.c
  mysha.pcx
  planet.pcx
  running.dat
  running.h
  unifont.dat