Mercurial > hg > xemacs-beta
annotate src/esd.c @ 5436:da1365dd3f07
Added GPLv3 or later license to modules/README.
author | Mats Lidell <matsl@xemacs.org> |
---|---|
date | Sat, 13 Nov 2010 00:15:58 +0100 |
parents | 308d34e9f07d |
children | 90dcf2376909 |
rev | line source |
---|---|
398 | 1 /* esd.c - play a sound over ESD |
2 | |
3 This file is part of XEmacs. | |
4 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2367
diff
changeset
|
5 XEmacs is free software: you can redistribute it and/or modify it |
398 | 6 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2367
diff
changeset
|
7 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2367
diff
changeset
|
8 option) any later version. |
398 | 9 |
10 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2367
diff
changeset
|
16 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
398 | 17 |
18 /* Synched up with: Not in FSF. */ | |
19 | |
563 | 20 /* This file Mule-ized by Ben Wing, 5-15-01. */ |
21 | |
398 | 22 #include <config.h> |
563 | 23 #include "lisp.h" |
398 | 24 |
25 #include "miscplay.h" | |
563 | 26 #include "sound.h" |
27 | |
28 #include "sysfile.h" | |
398 | 29 |
30 #include <esd.h> | |
31 | |
32 | |
33 /* the name given to ESD - I think this should identify ourselves */ | |
34 #define ESD_NAME "xemacs" | |
35 | |
563 | 36 int esd_play_sound_file (Extbyte *file, int vol); |
609 | 37 int |
2286 | 38 esd_play_sound_file (Extbyte *file, int UNUSED (vol)) |
398 | 39 { /* #### FIXME: vol is ignored */ |
40 return esd_play_file(ESD_NAME, file, 0); | |
41 } | |
42 | |
2367 | 43 int esd_play_sound_data (Binbyte *data, size_t length, int vol); |
609 | 44 int |
2367 | 45 esd_play_sound_data (Binbyte *data, size_t length, int UNUSED (vol)) |
398 | 46 { /* #### FIXME: vol is ignored */ |
47 size_t (*parsesndfile)(void **dayta,size_t *sz,void **outbuf); | |
48 size_t (*sndcnv)(void **dayta,size_t *sz,void **); | |
49 fmtType ffmt; | |
50 int fmt,speed,tracks; | |
51 unsigned char *pptr,*optr,*cptr,*sptr; | |
1261 | 52 Bytecount wrtn, crtn; |
398 | 53 size_t prtn; |
54 int flags, sock; | |
55 | |
56 /* analyze_format needs at least this many bytes to work with */ | |
57 if (length < HEADERSZ) | |
58 return 0; | |
59 | |
60 ffmt = analyze_format(data,&fmt,&speed,&tracks,&parsesndfile); | |
61 | |
62 if (ffmt != fmtRaw && ffmt != fmtSunAudio && ffmt != fmtWave) { | |
564 | 63 sound_warn("Unsupported file format (neither RAW, nor Sun/DECAudio, nor WAVE)"); |
398 | 64 return 0; |
65 } | |
66 | |
67 /* convert header information into ESD flags */ | |
68 flags = ESD_STREAM|ESD_PLAY; | |
69 sndcnv = sndcnvnop; | |
70 switch (fmt) | |
71 { | |
72 case AFMT_MU_LAW: | |
73 sndcnv = sndcnvULaw_2linear; | |
74 flags |= ESD_BITS8; | |
75 break; | |
76 case AFMT_S8: | |
77 sndcnv = sndcnv2unsigned; /* ESD needs unsigned bytes */ | |
78 case AFMT_U8: | |
79 flags |= ESD_BITS8; | |
80 break; | |
81 case AFMT_S16_BE: | |
82 sndcnv = sndcnv16swap; /* ESD wants little endian */ | |
83 case AFMT_S16_LE: | |
84 flags |= ESD_BITS16; | |
85 break; | |
86 default: | |
564 | 87 { |
88 Extbyte warn_buf[255]; | |
89 sprintf (warn_buf, "byte format %d unimplemented", fmt); | |
90 sound_warn (warn_buf); | |
91 return 0; | |
92 } | |
398 | 93 } |
94 switch (tracks) | |
95 { | |
96 case 1: flags |= ESD_MONO; break; | |
97 case 2: flags |= ESD_STEREO; break; | |
98 default: | |
564 | 99 { |
100 Extbyte warn_buf[255]; | |
101 sprintf (warn_buf, "%d channels - only 1 or 2 supported", tracks); | |
102 sound_warn (warn_buf); | |
103 return 0; | |
104 } | |
398 | 105 } |
106 | |
107 sock = esd_play_stream(flags, speed, NULL, "xemacs"); | |
108 if (sock < 0) | |
109 return 0; | |
110 | |
111 reset_parsestate(); | |
112 | |
113 for (pptr = data; (prtn = parsesndfile((void **)&pptr,&length, | |
114 (void **)&optr)) > 0; ) | |
115 for (cptr = optr; (crtn = sndcnv((void **)&cptr,&prtn, | |
1261 | 116 (void **)&sptr)) > 0; ) |
117 { | |
118 if ((wrtn = write(sock,sptr,crtn)) < 0) | |
119 { | |
120 sound_perror ("write error"); | |
121 goto END_OF_PLAY; | |
122 } | |
123 if (wrtn != crtn) | |
124 { | |
125 Extbyte warn_buf[255]; | |
126 sprintf (warn_buf, "only wrote %ld of %ld bytes", wrtn, crtn); | |
127 sound_warn (warn_buf); | |
128 goto END_OF_PLAY; | |
129 } | |
398 | 130 } |
131 | |
132 if (ffmt == fmtWave) | |
133 parse_wave_complete(); | |
134 | |
135 END_OF_PLAY: | |
136 /* Now cleanup all used resources */ | |
137 | |
138 close(sock); | |
139 return 1; | |
140 } |