Mercurial > pidgin.yaz
comparison src/sound.c @ 4581:4b1e24835bbf
[gaim-migrate @ 4864]
put NAS sound support back in, and re-wrote a lot of the libao stuff
this should mostly put an end to people having to make a ~/.libao file
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 14 Feb 2003 20:57:32 +0000 |
parents | 0ea6a4c53f38 |
children | b69bbf9b1044 |
comparison
equal
deleted
inserted
replaced
4580:3fef2d45dce0 | 4581:4b1e24835bbf |
---|---|
26 #include <stdio.h> | 26 #include <stdio.h> |
27 #include <stdlib.h> | 27 #include <stdlib.h> |
28 #include <string.h> | 28 #include <string.h> |
29 | 29 |
30 #ifndef _WIN32 | 30 #ifndef _WIN32 |
31 #include <sys/time.h> | |
32 #include <unistd.h> | |
33 #include <sys/wait.h> | |
34 #include <unistd.h> | 31 #include <unistd.h> |
35 #else | 32 #else |
36 #include <windows.h> | 33 #include <windows.h> |
37 #include <mmsystem.h> | 34 #include <mmsystem.h> |
38 #endif | 35 #endif |
39 | 36 |
40 #include <fcntl.h> | |
41 #include <sys/types.h> | |
42 #include <sys/stat.h> | |
43 | |
44 #ifdef USE_AO | 37 #ifdef USE_AO |
45 #include <ao/ao.h> | 38 #include <ao/ao.h> |
46 #include <audiofile.h> | 39 #include <audiofile.h> |
47 #endif /* USE_AO */ | 40 #endif /* USE_AO */ |
41 #ifdef USE_NAS_AUDIO | |
42 #include <audio/audiolib.h> | |
43 #include <audio/soundlib.h> | |
44 #endif /* USE_NAS_AUDIO */ | |
48 | 45 |
49 #include "gaim.h" | 46 #include "gaim.h" |
50 #include "sound.h" | 47 #include "sound.h" |
51 | 48 |
52 #ifdef _WIN32 | 49 #ifdef _WIN32 |
58 guint opt; | 55 guint opt; |
59 char *def; | 56 char *def; |
60 }; | 57 }; |
61 | 58 |
62 #ifdef USE_AO | 59 #ifdef USE_AO |
63 static int ao_driver; | 60 static gboolean ao_initialized=FALSE; |
61 static int ao_driver = -1; | |
64 #endif /* USE_AO */ | 62 #endif /* USE_AO */ |
65 | 63 |
66 | 64 |
67 static gboolean mute_login_sounds = FALSE; | 65 static gboolean mute_login_sounds = FALSE; |
68 static gboolean mute_sounds = FALSE; | 66 static gboolean mute_sounds = FALSE; |
87 {N_("Someone says your name in chat"), OPT_SOUND_CHAT_NICK, "redalert.wav"} | 85 {N_("Someone says your name in chat"), OPT_SOUND_CHAT_NICK, "redalert.wav"} |
88 }; | 86 }; |
89 | 87 |
90 static char *sound_file[GAIM_NUM_SOUNDS]; | 88 static char *sound_file[GAIM_NUM_SOUNDS]; |
91 | 89 |
92 void gaim_sound_init() | 90 |
93 { | 91 #ifdef USE_AO |
94 #ifdef USE_AO | 92 static void check_ao_init() |
95 | 93 { |
96 ao_initialize(); | 94 if(!ao_initialized) { |
97 ao_driver = ao_default_driver_id(); | 95 debug_printf("Initializing sound ouput drivers.\n"); |
98 | 96 ao_initialize(); |
99 if(ao_driver == -1) { | 97 ao_initialized = TRUE; |
100 debug_printf("No suitable sound ouput driver found.\n"); | 98 } |
101 } else { | 99 } |
100 #endif /* USE_AO */ | |
101 | |
102 void gaim_sound_change_output_method() { | |
103 #ifdef USE_AO | |
104 ao_driver = -1; | |
105 | |
106 if ((sound_options & OPT_SOUND_ESD) || (sound_options & OPT_SOUND_ARTS) || | |
107 (sound_options & OPT_SOUND_NORMAL)) { | |
108 check_ao_init(); | |
109 if (ao_driver == -1 && (sound_options & OPT_SOUND_ESD)) { | |
110 ao_driver = ao_driver_id("esd"); | |
111 } | |
112 if(ao_driver == -1 && (sound_options & OPT_SOUND_ARTS)) { | |
113 ao_driver = ao_driver_id("arts"); | |
114 } | |
115 if (ao_driver == -1) { | |
116 ao_driver = ao_default_driver_id(); | |
117 } | |
118 } | |
119 if(ao_driver != -1) { | |
102 ao_info *info = ao_driver_info(ao_driver); | 120 ao_info *info = ao_driver_info(ao_driver); |
103 debug_printf("Sound output driver loaded: %s\n", info->name); | 121 debug_printf("Sound output driver loaded: %s\n", info->name); |
104 } | 122 } |
105 | 123 #endif /* USE_AO */ |
106 #endif | 124 #ifdef USE_NAS |
125 if((sound_options & OPT_SOUND_NAS)) | |
126 debug_printf("Sound output driver loaded: NAS output\n"); | |
127 #endif /* USE_NAS */ | |
107 } | 128 } |
108 | 129 |
109 void gaim_sound_quit() | 130 void gaim_sound_quit() |
110 { | 131 { |
111 #ifdef USE_AO | 132 #ifdef USE_AO |
112 | 133 if(ao_initialized) |
113 ao_shutdown(); | 134 ao_shutdown(); |
114 | 135 #endif |
115 #endif | 136 } |
116 } | 137 |
138 | |
139 #ifdef USE_NAS_AUDIO | |
140 static gboolean play_file_nas(const char *filename) | |
141 { | |
142 AuServer *nas_serv; | |
143 gboolean ret = FALSE; | |
144 | |
145 if((nas_serv = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL))) { | |
146 ret = AuSoundPlaySynchronousFromFile(nas_serv, filename, 100); | |
147 AuCloseServer(nas_serv); | |
148 } | |
149 | |
150 return ret; | |
151 } | |
152 | |
153 #endif /* USE_NAS_AUDIO */ | |
117 | 154 |
118 void gaim_sound_play_file(char *filename) | 155 void gaim_sound_play_file(char *filename) |
119 { | 156 { |
120 #ifdef USE_AO | 157 #if defined(USE_NAS_AUDIO) || defined(USE_AO) |
121 pid_t pid; | 158 pid_t pid; |
122 #endif /* USE_AO */ | 159 #ifdef USE_AO |
160 AFfilehandle file; | |
161 #endif | |
162 #endif | |
123 | 163 |
124 if (mute_sounds) | 164 if (mute_sounds) |
125 return; | 165 return; |
126 | 166 |
127 if (awaymessage && !(sound_options & OPT_SOUND_WHEN_AWAY)) | 167 if (awaymessage && !(sound_options & OPT_SOUND_WHEN_AWAY)) |
159 } | 199 } |
160 | 200 |
161 g_free(command); | 201 g_free(command); |
162 return; | 202 return; |
163 } | 203 } |
164 #ifdef USE_AO | 204 #if defined(USE_NAS_AUDIO) || defined(USE_AO) |
165 | |
166 if(ao_driver == -1) { | |
167 /* do _something_ audible ;-) */ | |
168 gdk_beep(); | |
169 return; | |
170 } | |
171 | |
172 | |
173 pid = fork(); | 205 pid = fork(); |
174 | |
175 if (pid < 0) | 206 if (pid < 0) |
176 return; | 207 return; |
177 else if (pid == 0) { | 208 else if (pid == 0) { |
178 AFfilehandle file = afOpenFile(filename, "rb", NULL); | 209 #ifdef USE_NAS_AUDIO |
210 if ((sound_options & OPT_SOUND_NAS)) { | |
211 if (play_file_nas(filename)) | |
212 _exit(0); | |
213 } | |
214 #endif /* USE_NAS_AUDIO */ | |
215 | |
216 #ifdef USE_AO | |
217 file = afOpenFile(filename, "rb", NULL); | |
179 if(file) { | 218 if(file) { |
180 ao_device *device; | 219 ao_device *device; |
181 ao_sample_format format; | 220 ao_sample_format format; |
182 int in_fmt; | 221 int in_fmt; |
183 int bytes_per_frame; | 222 int bytes_per_frame; |
208 buf, buf_frames))) { | 247 buf, buf_frames))) { |
209 if(!ao_play(device, buf, frames_read * bytes_per_frame)) | 248 if(!ao_play(device, buf, frames_read * bytes_per_frame)) |
210 break; | 249 break; |
211 } | 250 } |
212 ao_close(device); | 251 ao_close(device); |
213 } else { | |
214 debug_printf("error opening audio device!\n"); | |
215 } | 252 } |
216 afCloseFile(file); | 253 afCloseFile(file); |
217 } | 254 } |
255 ao_shutdown(); | |
256 #endif /* USE_AO */ | |
218 _exit(0); | 257 _exit(0); |
219 } | 258 } |
220 #else /* USE_AO */ | 259 #else /* USE_NAS_AUDIO || USE_AO */ |
221 gdk_beep(); | 260 gdk_beep(); |
222 return; | 261 return; |
223 #endif /* USE_AO */ | 262 #endif /* USE_NAS_AUDIO || USE_AO */ |
224 #else /* _WIN32 */ | 263 #else /* _WIN32 */ |
225 debug_printf("Playing %s\n", filename); | 264 debug_printf("Playing %s\n", filename); |
226 if (!PlaySound(filename, 0, SND_ASYNC | SND_FILENAME)) | 265 if (!PlaySound(filename, 0, SND_ASYNC | SND_FILENAME)) |
227 debug_printf("Error playing sound."); | 266 debug_printf("Error playing sound."); |
228 #endif /* _WIN32 */ | 267 #endif /* _WIN32 */ |