1 /* Sound in windows nt XEmacs.
2 Copyright (C) 1998 Andy Piper.
4 This file is part of XEmacs.
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
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
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
27 #if (defined (__CYGWIN32__) || defined(__MINGW32__)) && \
28 CYGWIN_VERSION_DLL_MAJOR < 21
29 extern BOOL WINAPI PlaySound(LPCSTR,HMODULE,DWORD);
33 static void play_sound_data_1 (unsigned char *data, int length,
34 int volume, int convert);
36 void play_sound_file (char *sound_file, int volume)
38 DWORD flags = SND_ASYNC | SND_NODEFAULT | SND_FILENAME;
40 Lisp_Object fname = Ffile_name_nondirectory (build_string (sound_file));
43 if (OpenFile (XSTRING_DATA (fname), &ofs, OF_EXIST) < 0)
45 /* file isn't in the path so read it as data */
48 int ofd = open (sound_file, O_RDONLY | OPEN_BINARY, 0);
53 size = lseek (ofd, 0, SEEK_END);
54 data = xmalloc (size);
55 lseek (ofd, 0, SEEK_SET);
63 if (read (ofd, data, size) != size)
71 play_sound_data_1 (data, size, 100, FALSE);
74 PlaySound (XSTRING_DATA (fname), NULL, flags);
77 /* mswindows can't cope with playing a sound from alloca space so we
78 have to convert if necessary */
79 static void play_sound_data_1 (unsigned char *data, int length, int volume,
80 int convert_to_malloc)
82 DWORD flags = SND_ASYNC | SND_MEMORY | SND_NODEFAULT;
83 static unsigned char* sound_data=0;
86 PlaySound (NULL, NULL, flags);
91 if (convert_to_malloc)
93 sound_data = xmalloc (length);
94 memcpy (sound_data, data, length);
99 PlaySound(sound_data, NULL, flags);
104 void play_sound_data (unsigned char *data, int length, int volume)
106 play_sound_data_1 (data, length, volume, TRUE);