File: sound.c

package info (click to toggle)
youbin 2.13-12
  • links: PTS
  • area: main
  • in suites: potato
  • size: 556 kB
  • ctags: 416
  • sloc: ansic: 2,830; makefile: 60; sh: 24
file content (119 lines) | stat: -rw-r--r-- 2,922 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
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
/*
 * Program:     $RCSfile: sound.c,v $  $Revision: 4.3 $
 *
 * Author:      H.Ariga     ariga@agusa.nuie.nagoya-u.ac.jp
 *              S.Yamamoto  yamamoto@nuie.nagoya-u.ac.jp
 *
 * Date:        1993/07/24
 * Modified:    $Date: 1995/04/08 10:58:31 $
 *
 * Copyright:   H.Ariga and S.Yamamoto  1993 - 1995
 *
 * The X Consortium, and any party obtaining a copy of these files from
 * the X Consortium, directly or indirectly, is granted, free of charge,
 * a full and unrestricted irrevocable, world-wide, paid up, royalty-free,
 * nonexclusive right and license to deal in this software and documentation
 * files (the "Software"), including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons who receive copies from any such
 * party to do so. This license includes without limitation a license to do
 * the foregoing actions under any patents of the party supplying this
 * software to the X Consortium.
 */

#ifndef lint
static char rcsid[] =
    "$Id: sound.c,v 4.3 1995/04/08 10:58:31 yamamoto Exp $";
#endif

/*
 * Sound facility: xyoubin on NEWS-OS and SunOS can play sound.
 *
 * Function play_sound():
 *     Return 0 if can play sound.
 *     Return 1 otherwise.
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

#ifdef sony_news
#include <sys/file.h>
#include <newsiodev/sound.h>
#include <soundlib.h>
#endif

#ifdef sony_news
#define AUDIO_DEVICE    "/dev/sb0"
#else
#define AUDIO_DEVICE    "/dev/audio"
#endif

#ifndef R_OK
#define R_OK            4                   /* Test for read permission. */
#endif /* R_OK */

#ifdef sony_news

int
play_sound(sound_file_name)
char    *sound_file_name;
{
    SFILE           *fin;
    int             fout;
    struct sbparam  savedparam;
    char            buf[256];
    int             c;

    if ((fin = OpenSoundFile(sound_file_name)) == NULL) {
        return (1);
    }
    if ((fout = open(AUDIO_DEVICE, O_RDWR)) == NULL) {
        close(fin);
        return (1);
    }
    
    ioctl(fout, SBIOCGETPARAM, &savedparam);
    ioctl(fout, SBIOCSETPARAM, SbparamOfSoundFile(fin));
    while (c = ReadSoundFile(buf, 1, 256, fin)) {
        write(fout, buf, c);
    }
    ioctl(fout, SBIOCSETPARAM, &savedparam);
    close(fout);
    CloseSoundFile(fin);

    return (0);
}

#endif /* sony_news */

/******************************************************************************/

#ifdef sun

int
play_sound(sound_file_name)
char    *sound_file_name;
{
    FILE            *fin, *fout;
    int             c;

    if ((fin = fopen(sound_file_name, "r")) == NULL) {
        return (1);
    }
    if ((fout = fopen(AUDIO_DEVICE, "w")) == NULL) {
        fclose(fin);
        return (1);
    }
    
    while ((c = fgetc(fin)) != EOF) {
        fputc(c, fout);
    }
    fclose(fout);
    fclose(fin);

    return (0);
}

#endif /* sun */