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