1 /* NCD Audio format - original code by Dave Lemke <lemke@verbosa.ncd.com> */
2 /* Modified by paul kendall for X Galaga. */
3
4 /*
5 * Include file dependencies:
6 */
7 #ifdef RSOUND
8 #include <stdio.h>
9 #include <fcntl.h>
10 #include <stdlib.h>
11 #include <stddef.h>
12 #include <ctype.h>
13 #include <errno.h>
14 #include <sys/stat.h>
15 #include <sys/fcntl.h>
16
17 #include "rplay.h"
18 #include <X11/Xlib.h>
19 #include "koules.h"
20
21 char *unixSoundPath = SOUNDDIR;
22 #define playSounds 1
23
24 /*
25 * Internal variable declarations:
26 */
27
28 static char *FILENAME[] =
29 {
30 "/start.au",
31 "/end.au",
32 "/colize.au",
33 "/destroy1.au",
34 "/destroy2.au",
35 "/creator1.au",
36 "/creator2.au"
37 };
38 #define NUM_SOUNDS (sizeof(FILENAME)/sizeof(char*))
39
40
41 #define MAX_SOUNDS 8
42 static int fd;
43
44 static int audio_on = False;
45
46 void
init_sound()47 init_sound ()
48 {
49 char *displayname = DisplayString (dp);
50 char host[256], *p, s[256];
51 int i;
52
53 if (audio_on)
54 return;
55 strcpy (host, displayname);
56
57 if ((p = strrchr (host, (int) ':')) != NULL)
58 *p = 0;
59
60 if (!*host)
61 strcat (host, "localhost");
62
63 printf ("Directing sound to: %s\n", host);
64
65 if ((fd = rplay_open (host)) < 0)
66 {
67 rplay_perror (host);
68 return;
69 }
70 audio_on = True;
71 for (i = 0; i < NUM_SOUNDS; i++)
72 {
73 s[0] = 0;
74 strcat (s, SOUNDDIR);
75 if (s[(int) strlen (s) - 1] == '/')
76 FILENAME[i]++;
77 strcat (s, FILENAME[i]);
78 FILENAME[i] = malloc ((int) strlen (s) + 1);
79 strcpy (FILENAME[i], s);
80 }
81
82
83 return;
84
85 }
86
87 static void *p[7];
88
89 void
playSoundFile(char * filename,int volume,void ** private)90 playSoundFile (char *filename, int volume, void **private)
91 {
92 RPLAY **p = (RPLAY **) private;
93
94
95 if (!*p)
96 {
97 printf ("loading sound %s\n", filename);
98 *p = rplay_create (RPLAY_PLAY);
99 rplay_set (*p, RPLAY_INSERT, 0, RPLAY_SOUND, strdup (filename), NULL);
100 }
101
102 rplay_set (*p, RPLAY_CHANGE, 0, RPLAY_VOLUME, volume, NULL);
103 rplay (fd, *p);
104
105 }
106
107
108 int
play_sound(k)109 play_sound (k)
110 int k;
111 {
112 char c;
113
114 c = k;
115 if (audio_on)
116 {
117 playSoundFile (FILENAME[k], 50, &p[k]);
118 }
119 return (0);
120 }
121
122
123 void
maybe_play_sound(k)124 maybe_play_sound (k)
125 int k;
126 {
127 }
128
129 void
sound_completed(k)130 sound_completed (k)
131 int k;
132 {
133 }
134
135 void
kill_sound()136 kill_sound ()
137 {
138 }
139 #endif
140