annotate src/ntplay.c @ 288:e11d67e05968 r21-0b42

Import from CVS: tag r21-0b42
author cvs
date Mon, 13 Aug 2007 10:35:54 +0200
parents 90d73dddcdc4
children 6cb5e14cd98e
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);
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
30 #endif
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
31 static void play_sound_data_1 (unsigned char *data, int length,
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
32 int volume, int convert);
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
33
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
34 void play_sound_file (char *sound_file, int volume)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
35 {
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
36 DWORD flags = SND_ASYNC | SND_NODEFAULT | SND_FILENAME;
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
37 OFSTRUCT ofs;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
38 Lisp_Object fname = Ffile_name_nondirectory (build_string (sound_file));
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
39
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
40 CHECK_STRING (fname);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
41 if (OpenFile (XSTRING_DATA (fname), &ofs, OF_EXIST) < 0)
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
42 {
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
43 /* file isn't in the path so read it as data */
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
44 int size;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
45 unsigned char* data;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
46 int ofd = open (sound_file, O_RDONLY | OPEN_BINARY, 0);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
47
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
48 if (ofd <0)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
49 return;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
50
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
51 size = lseek (ofd, 0, SEEK_END);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
52 data = xmalloc (size);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
53 lseek (ofd, 0, SEEK_SET);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
54
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
55 if (!data)
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 close (ofd);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
58 return;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
59 }
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
60
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
61 if (read (ofd, data, size) != size)
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 close (ofd);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
64 xfree (data);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
65 return;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
66 }
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
67
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
68 play_sound_data_1 (data, size, 100, FALSE);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
69
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
70 xfree (data);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
71 close (ofd);
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;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
83 unsigned char* sound_data;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
84 if (convert_to_malloc)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
85 {
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
86 sound_data = xmalloc (length);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
87 memcpy (sound_data, data, length);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
88 }
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
89 else
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
90 sound_data = data;
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
91
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
92 PlaySound(sound_data, NULL, flags);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
93 if (convert_to_malloc)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
94 xfree (sound_data);
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
95 return;
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
96 }
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
97
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
98 void play_sound_data (unsigned char *data, int length, int volume)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
99 {
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 278
diff changeset
100 play_sound_data_1 (data, length, volume, TRUE);
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents:
diff changeset
101 }