annotate src/ntplay.c @ 316:512e409c26a2 r21-0b56

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