comparison src/sound.c @ 25548:df6548ca33fd

(Qplay_sound_functions): Replaces Qplay_sound_hook. (Fplay_sound, syms_of_sound): Use it. (parse_sound): Allow float volume values in the range [0, 1]. (Fplay_sound): Ditto.
author Gerd Moellmann <gerd@gnu.org>
date Sun, 05 Sep 1999 21:22:45 +0000
parents bb68fe3c72f8
children 2be6ced279d3
comparison
equal deleted inserted replaced
25547:2992a7953ac4 25548:df6548ca33fd
196 /* Symbols. */ 196 /* Symbols. */
197 197
198 extern Lisp_Object QCfile; 198 extern Lisp_Object QCfile;
199 Lisp_Object QCvolume, QCdevice; 199 Lisp_Object QCvolume, QCdevice;
200 Lisp_Object Qsound; 200 Lisp_Object Qsound;
201 Lisp_Object Qplay_sound_hook; 201 Lisp_Object Qplay_sound_functions;
202 202
203 /* These are set during `play-sound' so that sound_cleanup has 203 /* These are set during `play-sound' so that sound_cleanup has
204 access to them. */ 204 access to them. */
205 205
206 struct sound_device *sound_device; 206 struct sound_device *sound_device;
258 DEVICE is the name of the device to play on, e.g. "/dev/dsp2". 258 DEVICE is the name of the device to play on, e.g. "/dev/dsp2".
259 If not specified, a default device is used. 259 If not specified, a default device is used.
260 260
261 - `:volume VOL' 261 - `:volume VOL'
262 262
263 VOL must be an integer in the range 0..100. */ 263 VOL must be an integer in the range [0, 100], or a float in the
264 range [0, 1]. */
264 265
265 static int 266 static int
266 parse_sound (sound, attrs) 267 parse_sound (sound, attrs)
267 Lisp_Object sound; 268 Lisp_Object sound;
268 Lisp_Object *attrs; 269 Lisp_Object *attrs;
281 return 0; 282 return 0;
282 283
283 /* Volume must be in the range 0..100 or unspecified. */ 284 /* Volume must be in the range 0..100 or unspecified. */
284 if (!NILP (attrs[SOUND_VOLUME])) 285 if (!NILP (attrs[SOUND_VOLUME]))
285 { 286 {
286 if (!INTEGERP (attrs[SOUND_VOLUME])) 287 if (INTEGERP (attrs[SOUND_VOLUME]))
287 return 0; 288 {
288 if (XINT (attrs[SOUND_VOLUME]) < 0 289 if (XINT (attrs[SOUND_VOLUME]) < 0
289 || XINT (attrs[SOUND_VOLUME]) > 100) 290 || XINT (attrs[SOUND_VOLUME]) > 100)
291 return 0;
292 }
293 else if (FLOATP (attrs[SOUND_VOLUME]))
294 {
295 if (XFLOAT_DATA (attrs[SOUND_VOLUME]) < 0
296 || XFLOAT_DATA (attrs[SOUND_VOLUME]) > 1)
297 return 0;
298 }
299 else
290 return 0; 300 return 0;
291 } 301 }
292 302
293 /* Device must be a string or unspecified. */ 303 /* Device must be a string or unspecified. */
294 if (!NILP (attrs[SOUND_DEVICE]) 304 if (!NILP (attrs[SOUND_DEVICE])
381 sd.file = (char *) alloca (len + 1); 391 sd.file = (char *) alloca (len + 1);
382 strcpy (sd.file, XSTRING (attrs[SOUND_DEVICE])->data); 392 strcpy (sd.file, XSTRING (attrs[SOUND_DEVICE])->data);
383 } 393 }
384 if (INTEGERP (attrs[SOUND_VOLUME])) 394 if (INTEGERP (attrs[SOUND_VOLUME]))
385 sd.volume = XFASTINT (attrs[SOUND_VOLUME]); 395 sd.volume = XFASTINT (attrs[SOUND_VOLUME]);
386 396 else if (FLOATP (attrs[SOUND_VOLUME]))
387 args[0] = Qplay_sound_hook; 397 sd.volume = XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100;
398
399 args[0] = Qplay_sound_functions;
388 args[1] = sound; 400 args[1] = sound;
389 Frun_hook_with_args (make_number (2), args); 401 Frun_hook_with_args (make_number (2), args);
390 402
391 vox_init (&sd); 403 vox_init (&sd);
392 sd.open (&sd); 404 sd.open (&sd);
807 staticpro (&QCdevice); 819 staticpro (&QCdevice);
808 QCvolume = intern (":volume"); 820 QCvolume = intern (":volume");
809 staticpro (&QCvolume); 821 staticpro (&QCvolume);
810 Qsound = intern ("sound"); 822 Qsound = intern ("sound");
811 staticpro (&Qsound); 823 staticpro (&Qsound);
812 Qplay_sound_hook = intern ("play-sound-hook"); 824 Qplay_sound_functions = intern ("play-sound-functions");
813 staticpro (&Qplay_sound_hook); 825 staticpro (&Qplay_sound_functions);
814 826
815 defsubr (&Splay_sound); 827 defsubr (&Splay_sound);
816 } 828 }
817 829
818 830