File: exsample.c

package info (click to toggle)
allegro4 2%3A4.0.1-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 17,052 kB
  • ctags: 12,972
  • sloc: ansic: 109,525; asm: 16,672; cpp: 3,221; sh: 1,761; makefile: 556; pascal: 105; perl: 73
file content (89 lines) | stat: -rw-r--r-- 2,180 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 *    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[])
{
   SAMPLE *the_sample;
   int pan = 128;
   int pitch = 1000;

   allegro_init();

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

   install_keyboard(); 
   install_timer();

   /* install a digital sound driver */
   if (install_sound(DIGI_AUTODETECT, MIDI_NONE, argv[0]) != 0) {
      allegro_message("Error initialising sound system\n%s\n", allegro_error);
      return 1;
   }

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

   if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
      return 1;
   }
   set_palette(desktop_palette);
   clear_to_color(screen, makecol(255,255,255));
   text_mode(-1);

   textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/3, makecol(0, 0, 0),
		     "Driver: %s", digi_driver->name);
   textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0),
		     "Playing %s", argv[1]);
   textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H*2/3, makecol(0, 0, 0),
		     "Use the arrow keys to adjust it");

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

   do {
      poll_keyboard();

      /* alter the pan position? */
      if ((key[KEY_LEFT]) && (pan > 0))
	 pan--;
      else if ((key[KEY_RIGHT]) && (pan < 255))
	 pan++;

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

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

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

   } while ((!key[KEY_ESC]) && (!key[KEY_SPACE]));

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

   return 0;
}

END_OF_MAIN();