[go: up one dir, main page]

Menu

[2234d2]: / koules / sound.c  Maximize  Restore  History

Download this file

132 lines (110 with data), 2.3 kB

  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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* sound.c - Platform Independant Sound Support - Apr. 1995
*
* Copyright 1994-1995 Sujal M. Patel (smpatel@wam.umd.edu)
* Conditions in "copyright.h"
*
* Modified for koules and bugfixed by Jan Hubicka
*/
#ifdef SOUND
#include <stdio.h>
#ifdef __STDC__
#include <stdlib.h>
#endif
#include <unistd.h>
#include <sys/time.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/stat.h>
char *unixSoundPath = SOUNDDIR;
char *unixSoundDev = SOUNDDEV;
#define playSounds 1
static int soundfd;
static char audioOK = 1;
static char sound_flags[20]; /* Sound Flag for sound 1-19 */
int child;
void
test_sound ()
{
if (audioOK)
if (kill (child, 0))
{
audioOK = 0;
close (soundfd);
};
}
void
init_sound ()
{
int i, fd[2];
char *argv[4];
char filename[512];
signal (SIGCHLD, SIG_IGN);
signal (SIGPIPE, SIG_IGN);
if (unixSoundPath[0] == '?')
{
audioOK = 0;
return;
};
/* Create a pipe, set the write end to close when we exec the sound server,
and set both (is the write end necessary?) ends to non-blocking */
pipe (fd);
soundfd = fd[1];
if (!(child = fork ()))
{
close (fd[1]);
dup2 (fd[0], STDIN_FILENO);
close (fd[0]);
sprintf (filename, SOUNDSERVER);
argv[0] = filename;
argv[1] = unixSoundPath;
argv[2] = unixSoundDev;
argv[3] = NULL;
execvp (filename, argv);
fprintf (stderr, "Couldn't Execute Sound Server %s!\n", filename);
exit (0);
};
close (fd[0]);
for (i = 0; i < 19; i++)
sound_flags[i] = 0;
}
int
play_sound (k)
int k;
{
char c;
test_sound ();
c = k;
if ((playSounds) && (audioOK))
write (soundfd, &c, sizeof (c));
return 0;
}
void
maybe_play_sound (k)
int k;
{
char c;
if (sound_flags[k] & 1)
return;
sound_flags[k] |= 1;
test_sound ();
c = (unsigned char) (k);
if ((playSounds) && (audioOK))
write (soundfd, &c, sizeof (c));
}
void
sound_completed (k)
int k;
{
sound_flags[k] &= ~1;
}
void
kill_sound ()
{
signed char c;
c = -1;
test_sound ();
if ((playSounds) && (audioOK))
write (soundfd, &c, sizeof (c));
}
#endif