home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
MM1
/
SOUNDUTILS
/
audioplay.lzh
/
AUDIOPLAY
/
SRC
/
play.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-19
|
3KB
|
182 lines
#define MAIN
#include "play.h"
extern int auplay(), iffplay(), wavplay();
int32 value;
static int locked = FALSE;
void gotsignl(signum)
signal_code signum;
{
sigarrived = signum;
if (signum == 2 || signum == 3 ) {
cleanup(0, NULL);
}
return;
}
main(argc,argv)
int argc;
char *argv[];
{
u_int32 magic;
path_id fd;
u_int32 isFile;
char **p;
/* set defaults */
debug = 0;
quiet = 0;
force = 0;
file[0] = NULL;
sig = 0;
pid = 0;
eventID = -1;
bufferSize = DEFAULT_BUFFER;
/* parse command line arguments */
p = argv + 1;
while (*p != NULL) {
if (**p == '-') {
optparse(*p);
} else {
isFile = 1;
}
p++;
}
if (isFile == 0) {
/* no files were specified */
printuse();
exit(0);
}
/* set up signal handler */
intercept(gotsignl);
/* create/link to the sound event */
eventID = _ev_creat(SND_FREE ,SND_WAIT_INC, SND_SIG_INC, SND_EVENT_NAME);
if (eventID == -1) {
/* event probably already exists, link to it */
if ((eventID = _ev_link(SND_EVENT_NAME)) == -1) {
eventID = -1;
cleanup(0, "cannot create/link to event");
}
if (force) {
while(_ev_delete(SND_EVENT_NAME) == -1)
_ev_unlink(eventID);
eventID = _ev_creat(SND_FREE ,SND_WAIT_INC, SND_SIG_INC, SND_EVENT_NAME);
if (eventID == -1) {
cleanup(0, "cannot create/link to event");
}
}
}
#if 0
/* wait for resource to free up */
value = _ev_wait(eventID, SND_FREE, SND_FREE);
/* we have the event! now let's play sound */
#endif
fileCount = 0;
p = argv + 1;
while (*p != NULL) {
if (**p == '-') {
p++;
continue;
}
if ((fd = open(*p, S_IREAD)) == -1) {
cleanup(errno, "cannot open file");
}
size = 4;
if (read(fd, &magic, size) == -1) {
cleanup(errno, "cannot read header");
}
/* seek back to beginning of file */
lseek(fd,0,SEEK_SET);
if (!quiet) {
fprintf(stderr, "\nFile: %s\n", *p);
}
lock_snd();
switch (magic) {
case MagicSun :
case MagicSunI :
case MagicDec :
case MagicDecI :
case DecDiva :
auplay(fd);
break;
case MagicIFF :
iffplay(fd,*p);
break;
case MagicVOC :
vocplay(fd);
break;
case MagicRIFF :
wavplay(fd);
break;
default:
cleanup(0, "unknown sound format");
}
unlock_snd();
p++;
}
cleanup(0, NULL);
}
cleanup(error, string)
int error;
char *string;
{
if (!quiet && string != NULL) {
fprintf(stderr, "%s\n", string);
}
if (eventID != -1) {
unlock_snd();
/* unlink event */
_ev_unlink(eventID);
}
if (pid != 0 && sig != 0) {
/* notify pid with sig */
kill(pid, sig);
}
exit(error);
}
lock_snd()
{
int value;
if (!locked) {
/* wait for resource to free up */
value = _ev_wait(eventID, SND_FREE, SND_FREE);
locked = TRUE;
}
}
unlock_snd()
{
if (locked) {
_ev_signal(eventID, SND_FREE);
/* unlink event */
locked = FALSE;
}
}