Mercurial > ~darius > hgwebdir.cgi > paradise_client
comparison sound.c @ 3:5a977ccbc7a9 default tip
Empty changelog
author | darius |
---|---|
date | Sat, 06 Dec 1997 05:41:29 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:fba0b6e6cdc7 | 3:5a977ccbc7a9 |
---|---|
1 /* | |
2 * sound.c - Platform Independant Sound Support - July 1996 | |
3 * Sujal M. Patel (smpatel@umiacs.umd.edu) | |
4 * | |
5 * | |
6 * Copyright (c) 1994-1996, Sujal M. Patel | |
7 * All rights reserved. | |
8 * | |
9 * Redistribution and use in source and binary forms, with or without | |
10 * modification, are permitted provided that the following conditions | |
11 * are met: | |
12 * 1. Redistributions of source code must retain the above copyright | |
13 * notice, this list of conditions and the following disclaimer. | |
14 * 2. Redistributions in binary form must reproduce the above copyright | |
15 * notice, this list of conditions and the following disclaimer in the | |
16 * documentation and/or other materials provided with the distribution. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
28 * SUCH DAMAGE. | |
29 * | |
30 * $Id: sound.c,v 1.1.1.1 1997/12/06 05:41:30 darius Exp $ | |
31 */ | |
32 | |
33 #include <stdio.h> | |
34 #ifdef __STDC__ | |
35 #include <stdlib.h> | |
36 #endif | |
37 #include <unistd.h> | |
38 #include <sys/time.h> | |
39 #include <fcntl.h> | |
40 #include <signal.h> | |
41 #include <sys/stat.h> | |
42 #include "data.h" | |
43 | |
44 | |
45 | |
46 static int soundfd; | |
47 static char audioOK = 1; | |
48 static char sound_flags[20]; /* Sound Flag for sound 1-19 */ | |
49 | |
50 | |
51 | |
52 void init_sound () | |
53 { | |
54 int i, pid, child,fd[2]; | |
55 char *argv[4]; | |
56 char filename[512]; | |
57 #ifdef linux | |
58 char *arch = "linux"; | |
59 #else | |
60 #ifdef __FreeBSD__ | |
61 char *arch = "freebsd"; | |
62 #else | |
63 #ifdef __NetBSD__ | |
64 char *arch = "netbsd"; | |
65 #else | |
66 #ifdef sun | |
67 char *arch = "sun"; | |
68 #else | |
69 #ifdef foo | |
70 char *arch = "foobar"; | |
71 #else | |
72 char *arch = "generic"; | |
73 #endif | |
74 #endif | |
75 #endif | |
76 #endif | |
77 #endif | |
78 | |
79 signal(SIGCHLD, SIG_IGN); | |
80 | |
81 if(unixSoundPath[0] == '?') { | |
82 audioOK = 0; | |
83 return; | |
84 }; | |
85 | |
86 /* Create a pipe, set the write end to close when we exec the sound server, | |
87 and set both (is the write end necessary?) ends to non-blocking */ | |
88 pipe(fd); | |
89 soundfd=fd[1]; | |
90 | |
91 if( !(child=fork()) ) { | |
92 close(fd[1]); | |
93 dup2(fd[0],STDIN_FILENO); | |
94 close(fd[0]); | |
95 sprintf (filename, "paradise.sndsrv.%s", arch); | |
96 argv[0] = filename; | |
97 argv[1] = unixSoundPath; | |
98 argv[2] = unixSoundDev; | |
99 argv[3] = NULL; | |
100 execvp(filename, argv); | |
101 fprintf (stderr, "Couldn't Execute Sound Server (paradise.sndsrv.%s)!\n", arch); | |
102 exit (0); | |
103 }; | |
104 close(fd[0]); | |
105 | |
106 sleep(1); | |
107 | |
108 if (kill(child, 0)) { | |
109 audioOK = 0; | |
110 close(soundfd); | |
111 }; | |
112 | |
113 for (i = 0; i < 19; i++) sound_flags[i] = 0; | |
114 } | |
115 | |
116 void play_sound (k) | |
117 int k; | |
118 { | |
119 char c; | |
120 | |
121 c = k; | |
122 if ((playSounds) && (audioOK)) write (soundfd, &c, sizeof (c)); | |
123 } | |
124 | |
125 | |
126 | |
127 void maybe_play_sound (k) | |
128 int k; | |
129 { | |
130 char c; | |
131 | |
132 if (sound_flags[k] & 1) return; | |
133 | |
134 sound_flags[k] |= 1; | |
135 | |
136 c = (unsigned char)(k); | |
137 if ((playSounds) && (audioOK)) write (soundfd, &c, sizeof (c)); | |
138 } | |
139 | |
140 | |
141 | |
142 void sound_completed (k) | |
143 int k; | |
144 { | |
145 sound_flags[k] &= ~1; | |
146 } | |
147 | |
148 | |
149 | |
150 void kill_sound () | |
151 { | |
152 char c; | |
153 | |
154 c = -1; | |
155 if ((playSounds) && (audioOK)) write (soundfd, &c, sizeof (c)); | |
156 } |