428
|
1 /* Sound in windows nt XEmacs.
|
|
2 Copyright (C) 1998 Andy Piper.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to the Free
|
|
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
19 02111-1307, USA.*/
|
|
20
|
563
|
21 /* Synched up with: Not in FSF. */
|
|
22
|
|
23 /* This file Mule-ized by Ben Wing, 5-15-01. */
|
|
24
|
593
|
25 #define DONT_ENCAPSULATE
|
|
26
|
428
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29
|
563
|
30 #include "sound.h"
|
442
|
31 #include "nt.h"
|
563
|
32
|
|
33 #include "sysfile.h"
|
442
|
34
|
563
|
35 static int play_sound_data_1 (UChar_Binary *data, int length,
|
|
36 int volume, int convert);
|
428
|
37
|
563
|
38 void
|
|
39 play_sound_file (Extbyte *sound_file, int volume)
|
428
|
40 {
|
|
41 DWORD flags = SND_ASYNC | SND_NODEFAULT | SND_FILENAME;
|
|
42 OFSTRUCT ofs;
|
563
|
43 Lisp_Object fname =
|
|
44 Ffile_name_nondirectory (build_ext_string (sound_file, Qmswindows_tstr));
|
|
45 Extbyte *fnameext;
|
428
|
46
|
|
47 CHECK_STRING (fname);
|
563
|
48 LISP_STRING_TO_EXTERNAL (fname, fnameext, Qmswindows_tstr);
|
|
49
|
|
50 if (OpenFile (fnameext, &ofs, OF_EXIST) < 0)
|
428
|
51 {
|
|
52 /* file isn't in the path so read it as data */
|
|
53 int size;
|
593
|
54 UChar_Binary *data;
|
428
|
55 int ofd = open (sound_file, O_RDONLY | OPEN_BINARY, 0);
|
|
56
|
|
57 if (ofd <0)
|
|
58 return;
|
|
59
|
|
60 size = lseek (ofd, 0, SEEK_END);
|
593
|
61 data = (UChar_Binary *) xmalloc (size);
|
428
|
62 lseek (ofd, 0, SEEK_SET);
|
|
63
|
|
64 if (!data)
|
|
65 {
|
|
66 close (ofd);
|
|
67 return;
|
|
68 }
|
|
69
|
|
70 if (read (ofd, data, size) != size)
|
|
71 {
|
|
72 close (ofd);
|
|
73 xfree (data);
|
|
74 return;
|
|
75 }
|
|
76 close (ofd);
|
|
77
|
|
78 play_sound_data_1 (data, size, 100, FALSE);
|
|
79 }
|
|
80 else
|
563
|
81 PlaySound (fnameext, NULL, flags);
|
428
|
82 }
|
|
83
|
|
84 /* mswindows can't cope with playing a sound from alloca space so we
|
|
85 have to convert if necessary */
|
563
|
86 static int
|
|
87 play_sound_data_1 (UChar_Binary *data, int length, int volume,
|
|
88 int convert_to_malloc)
|
428
|
89 {
|
|
90 DWORD flags = SND_ASYNC | SND_MEMORY | SND_NODEFAULT;
|
593
|
91 static UChar_Binary *sound_data = 0;
|
428
|
92 if (sound_data)
|
|
93 {
|
|
94 PlaySound (NULL, NULL, flags);
|
|
95 xfree (sound_data);
|
593
|
96 sound_data = 0;
|
428
|
97 }
|
|
98
|
|
99 if (convert_to_malloc)
|
|
100 {
|
593
|
101 sound_data = (UChar_Binary *) xmalloc (length);
|
428
|
102 memcpy (sound_data, data, length);
|
|
103 }
|
|
104 else
|
|
105 sound_data = data;
|
|
106
|
593
|
107 PlaySound ((Extbyte *) sound_data, NULL, flags);
|
428
|
108
|
442
|
109 /* #### Error handling? */
|
|
110 return 1;
|
428
|
111 }
|
|
112
|
563
|
113 int
|
|
114 play_sound_data (UChar_Binary *data, int length, int volume)
|
428
|
115 {
|
442
|
116 return play_sound_data_1 (data, length, volume, TRUE);
|
428
|
117 }
|