annotate src/ntplay.c @ 450:98528da0b7fc r21-2-40

Import from CVS: tag r21-2-40
author cvs
date Mon, 13 Aug 2007 11:39:20 +0200
parents abe6d1db359e
children 183866b06e0b
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 /* Sound in windows nt XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1998 Andy Piper.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 for more details.
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 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to the Free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 02111-1307, USA.*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
24 #include "sysfile.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
25 #include "nt.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
26 #include "nativesound.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
27
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
28 static int play_sound_data_1 (unsigned char *data, int length,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 int volume, int convert);
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 void play_sound_file (char *sound_file, int volume)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 DWORD flags = SND_ASYNC | SND_NODEFAULT | SND_FILENAME;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 OFSTRUCT ofs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 Lisp_Object fname = Ffile_name_nondirectory (build_string (sound_file));
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 CHECK_STRING (fname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 if (OpenFile (XSTRING_DATA (fname), &ofs, OF_EXIST) < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 /* file isn't in the path so read it as data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 int size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 unsigned char* data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 int ofd = open (sound_file, O_RDONLY | OPEN_BINARY, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 if (ofd <0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 return;
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 size = lseek (ofd, 0, SEEK_END);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
49 data = (unsigned char *)xmalloc (size);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 lseek (ofd, 0, SEEK_SET);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 if (!data)
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 close (ofd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 if (read (ofd, data, size) != size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 close (ofd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 xfree (data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 return;
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 close (ofd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 play_sound_data_1 (data, size, 100, FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 PlaySound (XSTRING_DATA (fname), NULL, flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 /* mswindows can't cope with playing a sound from alloca space so we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 have to convert if necessary */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
74 static int play_sound_data_1 (unsigned char *data, int length, int volume,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 int convert_to_malloc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 DWORD flags = SND_ASYNC | SND_MEMORY | SND_NODEFAULT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 static unsigned char* sound_data=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 if (sound_data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 PlaySound (NULL, NULL, flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 xfree (sound_data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 sound_data=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 if (convert_to_malloc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
88 sound_data = (unsigned char *)xmalloc (length);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 memcpy (sound_data, data, length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 sound_data = data;
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 PlaySound(sound_data, NULL, flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
96 /* #### Error handling? */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
97 return 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
100 int play_sound_data (unsigned char *data, int length, int volume)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
102 return play_sound_data_1 (data, length, volume, TRUE);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 }