Mercurial > hg > xemacs-beta
comparison 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 |
comparison
equal
deleted
inserted
replaced
287:13a0bd77a29d | 288:e11d67e05968 |
---|---|
20 | 20 |
21 #include <windows.h> | 21 #include <windows.h> |
22 #undef CONST | 22 #undef CONST |
23 #include <config.h> | 23 #include <config.h> |
24 #include <stdio.h> | 24 #include <stdio.h> |
25 #include "sysfile.h" | |
26 #include "lisp.h" | |
25 | 27 |
26 #ifdef __CYGWIN32__ | 28 #ifdef __CYGWIN32__ |
27 extern BOOL WINAPI PlaySound(LPCSTR,HMODULE,DWORD); | 29 extern BOOL WINAPI PlaySound(LPCSTR,HMODULE,DWORD); |
28 #endif | 30 #endif |
31 static void play_sound_data_1 (unsigned char *data, int length, | |
32 int volume, int convert); | |
29 | 33 |
30 void play_sound_file (char *sound_file, int volume); | |
31 void play_sound_file (char *sound_file, int volume) | 34 void play_sound_file (char *sound_file, int volume) |
32 { | 35 { |
33 DWORD flags = SND_ASYNC | SND_NODEFAULT | SND_FILENAME; | 36 DWORD flags = SND_ASYNC | SND_NODEFAULT | SND_FILENAME; |
34 char* dst=0; | 37 OFSTRUCT ofs; |
35 #ifdef __CYGWIN32__ | 38 Lisp_Object fname = Ffile_name_nondirectory (build_string (sound_file)); |
36 CYGWIN_WIN32_PATH(sound_file, dst); | 39 |
37 sound_file=dst; | 40 CHECK_STRING (fname); |
38 #endif | 41 if (OpenFile (XSTRING_DATA (fname), &ofs, OF_EXIST) < 0) |
39 if (PlaySound(sound_file, NULL, flags)==FALSE) | |
40 { | 42 { |
41 perror(sound_file); | 43 /* file isn't in the path so read it as data */ |
44 int size; | |
45 unsigned char* data; | |
46 int ofd = open (sound_file, O_RDONLY | OPEN_BINARY, 0); | |
47 | |
48 if (ofd <0) | |
49 return; | |
50 | |
51 size = lseek (ofd, 0, SEEK_END); | |
52 data = xmalloc (size); | |
53 lseek (ofd, 0, SEEK_SET); | |
54 | |
55 if (!data) | |
56 { | |
57 close (ofd); | |
58 return; | |
59 } | |
60 | |
61 if (read (ofd, data, size) != size) | |
62 { | |
63 close (ofd); | |
64 xfree (data); | |
65 return; | |
66 } | |
67 | |
68 play_sound_data_1 (data, size, 100, FALSE); | |
69 | |
70 xfree (data); | |
71 close (ofd); | |
42 } | 72 } |
73 else | |
74 PlaySound (XSTRING_DATA (fname), NULL, flags); | |
75 } | |
76 | |
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) | |
81 { | |
82 DWORD flags = SND_ASYNC | SND_MEMORY | SND_NODEFAULT; | |
83 unsigned char* sound_data; | |
84 if (convert_to_malloc) | |
85 { | |
86 sound_data = xmalloc (length); | |
87 memcpy (sound_data, data, length); | |
88 } | |
89 else | |
90 sound_data = data; | |
91 | |
92 PlaySound(sound_data, NULL, flags); | |
93 if (convert_to_malloc) | |
94 xfree (sound_data); | |
43 return; | 95 return; |
44 } | 96 } |
45 | 97 |
46 /* Call "linux_play_data_or_file" with the appropriate parameters for | |
47 playing pre-loaded data */ | |
48 void play_sound_data (unsigned char *data, int length, int volume); | |
49 void play_sound_data (unsigned char *data, int length, int volume) | 98 void play_sound_data (unsigned char *data, int length, int volume) |
50 { | 99 { |
51 DWORD flags = SND_ASYNC | SND_MEMORY | SND_NODEFAULT; | 100 play_sound_data_1 (data, length, volume, TRUE); |
52 if (PlaySound(data, NULL, flags)==FALSE) | |
53 { | |
54 perror("couldn't play sound file"); | |
55 } | |
56 return; | |
57 } | 101 } |