annotate src/sunplay.c @ 4522:fc7067b7f407

Backout last patch; forgot to specify file.
author Stephen J. Turnbull <stephen@xemacs.org>
date Wed, 29 Oct 2008 03:37:16 +0900
parents 3d8143fc88e1
children aa5ed11f473b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* play.c - play a sound file on the speaker
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ** Copyright (C) 1989 by Jef Poskanzer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ** Modified 24-May-91 by Jamie Zawinski (for Lucid Emacs).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ** Modified 17-Dec-92 by Jamie Zawinski (largely rewritten for SunOS 4.1.3).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ** Permission to use, copy, modify, and distribute this software and its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ** documentation for any purpose and without fee is hereby granted, provided
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 ** that the above copyright notice appear in all copies and that both that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ** copyright notice and this permission notice appear in supporting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ** documentation. This software is provided "as is" without express or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ** implied warranty.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 /* Synched up with: Not in FSF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
18 /* This file Mule-ized by Ben Wing, 5-15-01. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
20 #include <config.h>
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
21 #include "lisp.h"
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
22 #include "sound.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
24 #include "sysdep.h"
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
25 #include "sysfile.h"
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
26 #include "syssignal.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include <multimedia/libaudio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include <multimedia/audio_device.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 static SIGTYPE (*sighup_handler) (int sig);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 static SIGTYPE (*sigint_handler) (int sig);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 static SIGTYPE sighandler (int sig);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 static int audio_fd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #define audio_open() open ("/dev/audio", (O_WRONLY | O_NONBLOCK), 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
39 static int initialized_device_p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 static int reset_volume_p, reset_device_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 static double old_volume;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 static Audio_hdr dev_hdr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 static int
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 771
diff changeset
45 init_device (int volume, Binbyte *data, int fd,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 unsigned int *header_length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 #ifdef SUNOS4_0_3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 if (header_length) *header_length = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 Audio_hdr file_hdr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 reset_volume_p = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 reset_device_p = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2367
diff changeset
57 if (data && fd) ABORT (); /* one or the other */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 if (AUDIO_SUCCESS != audio_get_play_config (audio_fd, &dev_hdr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
61 sound_perror ("Not a valid audio device");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 if (AUDIO_SUCCESS != (data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 ? audio_decode_filehdr (data, &file_hdr, header_length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 : audio_read_filehdr (fd, &file_hdr, 0, 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 if (data)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
70 sound_perror ("invalid audio data");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
72 sound_perror ("invalid audio file");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 audio_flush_play (audio_fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
78 if (!initialized_device_p || (0 != audio_cmp_hdr (&dev_hdr, &file_hdr)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 Audio_hdr new_hdr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 new_hdr = file_hdr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 reset_device_p = 1;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
83 initialized_device_p = 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 if (AUDIO_SUCCESS != audio_set_play_config (audio_fd, &new_hdr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
86 Extbyte buf1 [100], buf2 [100], buf3 [250];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 audio_enc_to_str (&file_hdr, buf1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 audio_enc_to_str (&new_hdr, buf2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 sprintf (buf3, "wanted %s, got %s", buf1, buf2);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
90 sound_warn (buf3);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 if (volume < 0 || volume > 100)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
97 Extbyte buf [255];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 sprintf (buf, "volume must be between 0 and 100 (not %d)", volume);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
99 sound_warn (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 /* set the volume; scale it to 0.0 - 1.0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 double V = (volume / 100.0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 audio_get_play_gain (audio_fd, &old_volume);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 reset_volume_p = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 audio_set_play_gain (audio_fd, &V);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 reset_device (int wait_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 if (wait_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 audio_drain (audio_fd, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 audio_flush_play (audio_fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 if (reset_device_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 audio_set_play_config (audio_fd, &dev_hdr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 if (reset_volume_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 audio_set_play_gain (audio_fd, &old_volume);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 void
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
130 play_sound_file (Extbyte *sound_file, int volume)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 int rrtn, wrtn;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 771
diff changeset
133 Binbyte buf [255];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 int file_fd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 audio_fd = audio_open ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 if (audio_fd < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
140 sound_perror ("open /dev/audio");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 /* where to find the proto for signal()... */
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 609
diff changeset
145 sighup_handler = (SIGTYPE (*) (int)) EMACS_SIGNAL (SIGHUP, sighandler);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 609
diff changeset
146 sigint_handler = (SIGTYPE (*) (int)) EMACS_SIGNAL (SIGINT, sighandler);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 file_fd = open (sound_file, O_RDONLY, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 if (file_fd < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
151 sound_perror (sound_file);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 goto END_OF_PLAY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 771
diff changeset
155 if (init_device (volume, (Binbyte *) 0, file_fd, (unsigned int *) 0))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 goto END_OF_PLAY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 {
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 771
diff changeset
160 rrtn = read (file_fd, (CBinbyte *) buf, sizeof (buf));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 if (rrtn < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
163 sound_perror ("read");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 goto END_OF_PLAY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 if (rrtn == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 {
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 771
diff changeset
171 wrtn = write (audio_fd, (CBinbyte *) buf, rrtn);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 if (wrtn < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
174 sound_perror ("write");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 goto END_OF_PLAY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 if (wrtn != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 if (AUDIO_ERR_INTERRUPTED == audio_drain (audio_fd, 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 goto END_OF_PLAY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 if (wrtn != rrtn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
185 Extbyte warn_buf [255];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 sprintf (warn_buf, "play: rrtn = %d, wrtn = %d", rrtn, wrtn);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
187 sound_warn (warn_buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 goto END_OF_PLAY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 END_OF_PLAY:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 if (file_fd > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 close (file_fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 if (audio_fd > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 reset_device (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 close (audio_fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 609
diff changeset
203 EMACS_SIGNAL (SIGHUP, sighup_handler);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 609
diff changeset
204 EMACS_SIGNAL (SIGINT, sigint_handler);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
208 int
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 771
diff changeset
209 play_sound_data (Binbyte *data, int length, int volume)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 int wrtn, start = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 unsigned int ilen;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
213 int result = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 audio_fd = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
217 if (length == 0) return 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 /* this is just to get a better error message */
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 771
diff changeset
220 if (strncmp (".snd\0", (CBinbyte *) data, 4))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
222 sound_warn ("Not valid audio data (bad magic number)");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 goto END_OF_PLAY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 if (length <= sizeof (Audio_hdr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
227 sound_warn ("Not valid audio data (too short)");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 goto END_OF_PLAY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 audio_fd = audio_open ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 if (audio_fd < 0)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
233 return 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 /* where to find the proto for signal()... */
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 609
diff changeset
236 sighup_handler = (SIGTYPE (*) (int)) EMACS_SIGNAL (SIGHUP, sighandler);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 609
diff changeset
237 sigint_handler = (SIGTYPE (*) (int)) EMACS_SIGNAL (SIGINT, sighandler);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 if (init_device (volume, data, 0, &ilen))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 goto END_OF_PLAY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 data += (ilen<<2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 length -= (ilen<<2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 if (length <= 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 goto END_OF_PLAY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 {
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 771
diff changeset
249 wrtn = write (audio_fd, (CBinbyte *) (data+start), length-start);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 if (wrtn < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
252 sound_perror ("write");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 goto END_OF_PLAY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 if (wrtn != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 start += wrtn;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 if (AUDIO_ERR_INTERRUPTED == audio_drain (audio_fd, 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 goto END_OF_PLAY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 if (wrtn != length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
265 Extbyte buf [255];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 sprintf (buf, "play: rrtn = %d, wrtn = %d", length, wrtn);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
267 sound_warn (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 goto END_OF_PLAY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
271 result = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
272
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 END_OF_PLAY:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 if (audio_fd > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 reset_device (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 close (audio_fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 609
diff changeset
281 EMACS_SIGNAL (SIGHUP, sighup_handler);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 609
diff changeset
282 EMACS_SIGNAL (SIGINT, sigint_handler);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
283
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
284 return result;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 /* #### sigcontext doesn't exist in Solaris. This should be updated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 to be correct for Solaris. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
289 static SIGTYPE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 sighandler (int sig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 if (audio_fd > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 reset_device (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 close (audio_fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 if (sig == SIGHUP && sighup_handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 sighup_handler (sig);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 else if (sig == SIGINT && sigint_handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 sigint_handler (sig);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 }