diff options
| author | Gerd Moellmann | 2000-01-04 14:45:08 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-01-04 14:45:08 +0000 |
| commit | d1299cdeca76c0caa51fda0c9c30b804c3c7e998 (patch) | |
| tree | b0db743bbc3bf8147065f20e00db417e69417b36 /src | |
| parent | fc91dc2d13870ab95bf81ec7b228227249e02a19 (diff) | |
| download | emacs-d1299cdeca76c0caa51fda0c9c30b804c3c7e998.tar.gz emacs-d1299cdeca76c0caa51fda0c9c30b804c3c7e998.zip | |
(struct sound): Renamed from struct sound_file.
(struct sound): Add members `data' and `header_size'.
(enum sound_attr): Add SOUND_DATA.
(current_sound, current_sound_device): Variables renamed from
sound_file and sound_device.
(parse_sound): Parse :data.
(parse_sound): Handle sound data in strings.
(find_sound_type): Function renamed from find_sound_file_type.
(wav_init, au_init): Fail if sound's header_size is smaller than
needed header size.
(wav_play, au_play): Play sounds from string data.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 12 | ||||
| -rw-r--r-- | src/sound.c | 274 |
2 files changed, 174 insertions, 112 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index b52e46ef022..5465c6eda89 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,17 @@ | |||
| 1 | 2000-01-04 Gerd Moellmann <gerd@gnu.org> | 1 | 2000-01-04 Gerd Moellmann <gerd@gnu.org> |
| 2 | 2 | ||
| 3 | * sound.c (struct sound): Renamed from struct sound_file. | ||
| 4 | (struct sound): Add members `data' and `header_size'. | ||
| 5 | (enum sound_attr): Add SOUND_DATA. | ||
| 6 | (current_sound, current_sound_device): Variables renamed from | ||
| 7 | sound_file and sound_device. | ||
| 8 | (parse_sound): Parse :data. | ||
| 9 | (parse_sound): Handle sound data in strings. | ||
| 10 | (find_sound_type): Function renamed from find_sound_file_type. | ||
| 11 | (wav_init, au_init): Fail if sound's header_size is smaller than | ||
| 12 | needed header size. | ||
| 13 | (wav_play, au_play): Play sounds from string data. | ||
| 14 | |||
| 3 | * puresize.h (BASE_PURE_SIZE): Increase to 600000. | 15 | * puresize.h (BASE_PURE_SIZE): Increase to 600000. |
| 4 | 16 | ||
| 5 | * lisp.h: Add prototype for allocate_string_data. | 17 | * lisp.h: Add prototype for allocate_string_data. |
diff --git a/src/sound.c b/src/sound.c index 2909e8f0f3f..6f0e6fb997e 100644 --- a/src/sound.c +++ b/src/sound.c | |||
| @@ -48,7 +48,7 @@ Boston, MA 02111-1307, USA. */ | |||
| 48 | 48 | ||
| 49 | /* Structure forward declarations. */ | 49 | /* Structure forward declarations. */ |
| 50 | 50 | ||
| 51 | struct sound_file; | 51 | struct sound; |
| 52 | struct sound_device; | 52 | struct sound_device; |
| 53 | 53 | ||
| 54 | /* The file header of RIFF-WAVE files (*.wav). Files are always in | 54 | /* The file header of RIFF-WAVE files (*.wav). Files are always in |
| @@ -146,9 +146,9 @@ struct sound_device | |||
| 146 | /* Configure SD accoring to device-dependent parameters. */ | 146 | /* Configure SD accoring to device-dependent parameters. */ |
| 147 | void (* configure) P_ ((struct sound_device *device)); | 147 | void (* configure) P_ ((struct sound_device *device)); |
| 148 | 148 | ||
| 149 | /* Choose a device-dependent format for outputting sound file SF. */ | 149 | /* Choose a device-dependent format for outputting sound S. */ |
| 150 | void (* choose_format) P_ ((struct sound_device *sd, | 150 | void (* choose_format) P_ ((struct sound_device *sd, |
| 151 | struct sound_file *sf)); | 151 | struct sound *s)); |
| 152 | 152 | ||
| 153 | /* Write NYBTES bytes from BUFFER to device SD. */ | 153 | /* Write NYBTES bytes from BUFFER to device SD. */ |
| 154 | void (* write) P_ ((struct sound_device *sd, char *buffer, int nbytes)); | 154 | void (* write) P_ ((struct sound_device *sd, char *buffer, int nbytes)); |
| @@ -167,20 +167,27 @@ enum sound_type | |||
| 167 | 167 | ||
| 168 | /* Interface structure for sound files. */ | 168 | /* Interface structure for sound files. */ |
| 169 | 169 | ||
| 170 | struct sound_file | 170 | struct sound |
| 171 | { | 171 | { |
| 172 | /* The type of the file. */ | 172 | /* The type of the file. */ |
| 173 | enum sound_type type; | 173 | enum sound_type type; |
| 174 | 174 | ||
| 175 | /* File descriptor of the file. */ | 175 | /* File descriptor of a sound file. */ |
| 176 | int fd; | 176 | int fd; |
| 177 | 177 | ||
| 178 | /* Pointer to sound file header. This contains the first | 178 | /* Pointer to sound file header. This contains header_size bytes |
| 179 | MAX_SOUND_HEADER_BYTES read from the file. */ | 179 | read from the start of a sound file. */ |
| 180 | char *header; | 180 | char *header; |
| 181 | 181 | ||
| 182 | /* Play sound file SF on device SD. */ | 182 | /* Number of bytes raed from sound file. This is always <= |
| 183 | void (* play) P_ ((struct sound_file *sf, struct sound_device *sd)); | 183 | MAX_SOUND_HEADER_BYTES. */ |
| 184 | int header_size; | ||
| 185 | |||
| 186 | /* Sound data, if a string. */ | ||
| 187 | Lisp_Object data; | ||
| 188 | |||
| 189 | /* Play sound file S on device SD. */ | ||
| 190 | void (* play) P_ ((struct sound *s, struct sound_device *sd)); | ||
| 184 | }; | 191 | }; |
| 185 | 192 | ||
| 186 | /* Indices of attributes in a sound attributes vector. */ | 193 | /* Indices of attributes in a sound attributes vector. */ |
| @@ -188,6 +195,7 @@ struct sound_file | |||
| 188 | enum sound_attr | 195 | enum sound_attr |
| 189 | { | 196 | { |
| 190 | SOUND_FILE, | 197 | SOUND_FILE, |
| 198 | SOUND_DATA, | ||
| 191 | SOUND_DEVICE, | 199 | SOUND_DEVICE, |
| 192 | SOUND_VOLUME, | 200 | SOUND_VOLUME, |
| 193 | SOUND_ATTR_SENTINEL | 201 | SOUND_ATTR_SENTINEL |
| @@ -195,7 +203,7 @@ enum sound_attr | |||
| 195 | 203 | ||
| 196 | /* Symbols. */ | 204 | /* Symbols. */ |
| 197 | 205 | ||
| 198 | extern Lisp_Object QCfile; | 206 | extern Lisp_Object QCfile, QCdata; |
| 199 | Lisp_Object QCvolume, QCdevice; | 207 | Lisp_Object QCvolume, QCdevice; |
| 200 | Lisp_Object Qsound; | 208 | Lisp_Object Qsound; |
| 201 | Lisp_Object Qplay_sound_functions; | 209 | Lisp_Object Qplay_sound_functions; |
| @@ -203,27 +211,27 @@ Lisp_Object Qplay_sound_functions; | |||
| 203 | /* These are set during `play-sound' so that sound_cleanup has | 211 | /* These are set during `play-sound' so that sound_cleanup has |
| 204 | access to them. */ | 212 | access to them. */ |
| 205 | 213 | ||
| 206 | struct sound_device *sound_device; | 214 | struct sound_device *current_sound_device; |
| 207 | struct sound_file *sound_file; | 215 | struct sound *current_sound; |
| 208 | 216 | ||
| 209 | /* Function prototypes. */ | 217 | /* Function prototypes. */ |
| 210 | 218 | ||
| 211 | static void vox_open P_ ((struct sound_device *)); | 219 | static void vox_open P_ ((struct sound_device *)); |
| 212 | static void vox_configure P_ ((struct sound_device *)); | 220 | static void vox_configure P_ ((struct sound_device *)); |
| 213 | static void vox_close P_ ((struct sound_device *sd)); | 221 | static void vox_close P_ ((struct sound_device *sd)); |
| 214 | static void vox_choose_format P_ ((struct sound_device *, struct sound_file *)); | 222 | static void vox_choose_format P_ ((struct sound_device *, struct sound *)); |
| 215 | static void vox_init P_ ((struct sound_device *)); | 223 | static void vox_init P_ ((struct sound_device *)); |
| 216 | static void vox_write P_ ((struct sound_device *, char *, int)); | 224 | static void vox_write P_ ((struct sound_device *, char *, int)); |
| 217 | static void sound_perror P_ ((char *)); | 225 | static void sound_perror P_ ((char *)); |
| 218 | static int parse_sound P_ ((Lisp_Object, Lisp_Object *)); | 226 | static int parse_sound P_ ((Lisp_Object, Lisp_Object *)); |
| 219 | static void find_sound_file_type P_ ((struct sound_file *)); | 227 | static void find_sound_type P_ ((struct sound *)); |
| 220 | static u_int32_t le2hl P_ ((u_int32_t)); | 228 | static u_int32_t le2hl P_ ((u_int32_t)); |
| 221 | static u_int16_t le2hs P_ ((u_int16_t)); | 229 | static u_int16_t le2hs P_ ((u_int16_t)); |
| 222 | static u_int32_t be2hl P_ ((u_int32_t)); | 230 | static u_int32_t be2hl P_ ((u_int32_t)); |
| 223 | static int wav_init P_ ((struct sound_file *)); | 231 | static int wav_init P_ ((struct sound *)); |
| 224 | static void wav_play P_ ((struct sound_file *, struct sound_device *)); | 232 | static void wav_play P_ ((struct sound *, struct sound_device *)); |
| 225 | static int au_init P_ ((struct sound_file *)); | 233 | static int au_init P_ ((struct sound *)); |
| 226 | static void au_play P_ ((struct sound_file *, struct sound_device *)); | 234 | static void au_play P_ ((struct sound *, struct sound_device *)); |
| 227 | 235 | ||
| 228 | #if 0 /* Currently not used. */ | 236 | #if 0 /* Currently not used. */ |
| 229 | static u_int16_t be2hs P_ ((u_int16_t)); | 237 | static u_int16_t be2hs P_ ((u_int16_t)); |
| @@ -256,6 +264,11 @@ sound_perror (msg) | |||
| 256 | FILE is the sound file to play. If it isn't an absolute name, | 264 | FILE is the sound file to play. If it isn't an absolute name, |
| 257 | it's searched under `data-directory'. | 265 | it's searched under `data-directory'. |
| 258 | 266 | ||
| 267 | - `:data DATA' | ||
| 268 | |||
| 269 | DATA is a string containing sound data. Either :file or :data | ||
| 270 | may be present, but not both. | ||
| 271 | |||
| 259 | - `:device DEVICE' | 272 | - `:device DEVICE' |
| 260 | 273 | ||
| 261 | DEVICE is the name of the device to play on, e.g. "/dev/dsp2". | 274 | DEVICE is the name of the device to play on, e.g. "/dev/dsp2". |
| @@ -277,11 +290,13 @@ parse_sound (sound, attrs) | |||
| 277 | 290 | ||
| 278 | sound = XCDR (sound); | 291 | sound = XCDR (sound); |
| 279 | attrs[SOUND_FILE] = Fplist_get (sound, QCfile); | 292 | attrs[SOUND_FILE] = Fplist_get (sound, QCfile); |
| 293 | attrs[SOUND_DATA] = Fplist_get (sound, QCdata); | ||
| 280 | attrs[SOUND_DEVICE] = Fplist_get (sound, QCdevice); | 294 | attrs[SOUND_DEVICE] = Fplist_get (sound, QCdevice); |
| 281 | attrs[SOUND_VOLUME] = Fplist_get (sound, QCvolume); | 295 | attrs[SOUND_VOLUME] = Fplist_get (sound, QCvolume); |
| 282 | 296 | ||
| 283 | /* File name must be specified. */ | 297 | /* File name or data must be specified. */ |
| 284 | if (!STRINGP (attrs[SOUND_FILE])) | 298 | if (!STRINGP (attrs[SOUND_FILE]) |
| 299 | && !STRINGP (attrs[SOUND_DATA])) | ||
| 285 | return 0; | 300 | return 0; |
| 286 | 301 | ||
| 287 | /* Volume must be in the range 0..100 or unspecified. */ | 302 | /* Volume must be in the range 0..100 or unspecified. */ |
| @@ -313,15 +328,14 @@ parse_sound (sound, attrs) | |||
| 313 | 328 | ||
| 314 | 329 | ||
| 315 | /* Find out the type of the sound file whose file descriptor is FD. | 330 | /* Find out the type of the sound file whose file descriptor is FD. |
| 316 | SF is the sound file structure to fill in. */ | 331 | S is the sound file structure to fill in. */ |
| 317 | 332 | ||
| 318 | static void | 333 | static void |
| 319 | find_sound_file_type (sf) | 334 | find_sound_type (s) |
| 320 | struct sound_file *sf; | 335 | struct sound *s; |
| 321 | { | 336 | { |
| 322 | if (!wav_init (sf) | 337 | if (!wav_init (s) && !au_init (s)) |
| 323 | && !au_init (sf)) | 338 | error ("Unknown sound format"); |
| 324 | error ("Unknown sound file format"); | ||
| 325 | } | 339 | } |
| 326 | 340 | ||
| 327 | 341 | ||
| @@ -331,11 +345,11 @@ static Lisp_Object | |||
| 331 | sound_cleanup (arg) | 345 | sound_cleanup (arg) |
| 332 | Lisp_Object arg; | 346 | Lisp_Object arg; |
| 333 | { | 347 | { |
| 334 | if (sound_device) | 348 | if (current_sound_device) |
| 335 | { | 349 | { |
| 336 | sound_device->close (sound_device); | 350 | current_sound_device->close (current_sound_device); |
| 337 | if (sound_file->fd > 0) | 351 | if (current_sound->fd > 0) |
| 338 | emacs_close (sound_file->fd); | 352 | emacs_close (current_sound->fd); |
| 339 | } | 353 | } |
| 340 | } | 354 | } |
| 341 | 355 | ||
| @@ -348,42 +362,46 @@ DEFUN ("play-sound", Fplay_sound, Splay_sound, 1, 1, 0, | |||
| 348 | Lisp_Object attrs[SOUND_ATTR_SENTINEL]; | 362 | Lisp_Object attrs[SOUND_ATTR_SENTINEL]; |
| 349 | Lisp_Object file; | 363 | Lisp_Object file; |
| 350 | struct gcpro gcpro1, gcpro2; | 364 | struct gcpro gcpro1, gcpro2; |
| 351 | int nbytes; | ||
| 352 | struct sound_device sd; | 365 | struct sound_device sd; |
| 353 | struct sound_file sf; | 366 | struct sound s; |
| 354 | Lisp_Object args[2]; | 367 | Lisp_Object args[2]; |
| 355 | int count = specpdl_ptr - specpdl; | 368 | int count = specpdl_ptr - specpdl; |
| 356 | 369 | ||
| 357 | file = Qnil; | 370 | file = Qnil; |
| 358 | GCPRO2 (sound, file); | 371 | GCPRO2 (sound, file); |
| 359 | bzero (&sd, sizeof sd); | 372 | bzero (&sd, sizeof sd); |
| 360 | bzero (&sf, sizeof sf); | 373 | bzero (&s, sizeof s); |
| 361 | sf.header = (char *) alloca (MAX_SOUND_HEADER_BYTES); | 374 | current_sound_device = &sd; |
| 362 | 375 | current_sound = &s; | |
| 363 | sound_device = &sd; | ||
| 364 | sound_file = &sf; | ||
| 365 | record_unwind_protect (sound_cleanup, Qnil); | 376 | record_unwind_protect (sound_cleanup, Qnil); |
| 377 | s.header = (char *) alloca (MAX_SOUND_HEADER_BYTES); | ||
| 366 | 378 | ||
| 367 | /* Parse the sound specification. Give up if it is invalid. */ | 379 | /* Parse the sound specification. Give up if it is invalid. */ |
| 368 | if (!parse_sound (sound, attrs)) | 380 | if (!parse_sound (sound, attrs)) |
| 381 | error ("Invalid sound specification"); | ||
| 382 | |||
| 383 | if (STRINGP (attrs[SOUND_FILE])) | ||
| 369 | { | 384 | { |
| 370 | UNGCPRO; | 385 | /* Open the sound file. */ |
| 371 | error ("Invalid sound specification"); | 386 | s.fd = openp (Fcons (Vdata_directory, Qnil), |
| 387 | attrs[SOUND_FILE], "", &file, 0); | ||
| 388 | if (s.fd < 0) | ||
| 389 | sound_perror ("Open sound file"); | ||
| 390 | |||
| 391 | /* Read the first bytes from the file. */ | ||
| 392 | s.header_size = emacs_read (s.fd, s.header, MAX_SOUND_HEADER_BYTES); | ||
| 393 | if (s.header_size < 0) | ||
| 394 | sound_perror ("Reading sound file header"); | ||
| 395 | } | ||
| 396 | else | ||
| 397 | { | ||
| 398 | s.data = attrs[SOUND_DATA]; | ||
| 399 | bcopy (XSTRING (s.data)->data, s.header, | ||
| 400 | min (MAX_SOUND_HEADER_BYTES, STRING_BYTES (XSTRING (s.data)))); | ||
| 372 | } | 401 | } |
| 373 | 402 | ||
| 374 | /* Open the sound file. */ | 403 | /* Find out the type of sound. Give up if we can't tell. */ |
| 375 | sf.fd = openp (Fcons (Vdata_directory, Qnil), | 404 | find_sound_type (&s); |
| 376 | attrs[SOUND_FILE], "", &file, 0); | ||
| 377 | if (sf.fd < 0) | ||
| 378 | sound_perror ("Open sound file"); | ||
| 379 | |||
| 380 | /* Read the first bytes from the file. */ | ||
| 381 | nbytes = emacs_read (sf.fd, sf.header, MAX_SOUND_HEADER_BYTES); | ||
| 382 | if (nbytes < 0) | ||
| 383 | sound_perror ("Reading sound file header"); | ||
| 384 | |||
| 385 | /* Find out the type of sound file. Give up if we can't tell. */ | ||
| 386 | find_sound_file_type (&sf); | ||
| 387 | 405 | ||
| 388 | /* Set up a device. */ | 406 | /* Set up a device. */ |
| 389 | if (STRINGP (attrs[SOUND_DEVICE])) | 407 | if (STRINGP (attrs[SOUND_DEVICE])) |
| @@ -392,6 +410,7 @@ DEFUN ("play-sound", Fplay_sound, Splay_sound, 1, 1, 0, | |||
| 392 | sd.file = (char *) alloca (len + 1); | 410 | sd.file = (char *) alloca (len + 1); |
| 393 | strcpy (sd.file, XSTRING (attrs[SOUND_DEVICE])->data); | 411 | strcpy (sd.file, XSTRING (attrs[SOUND_DEVICE])->data); |
| 394 | } | 412 | } |
| 413 | |||
| 395 | if (INTEGERP (attrs[SOUND_VOLUME])) | 414 | if (INTEGERP (attrs[SOUND_VOLUME])) |
| 396 | sd.volume = XFASTINT (attrs[SOUND_VOLUME]); | 415 | sd.volume = XFASTINT (attrs[SOUND_VOLUME]); |
| 397 | else if (FLOATP (attrs[SOUND_VOLUME])) | 416 | else if (FLOATP (attrs[SOUND_VOLUME])) |
| @@ -401,15 +420,30 @@ DEFUN ("play-sound", Fplay_sound, Splay_sound, 1, 1, 0, | |||
| 401 | args[1] = sound; | 420 | args[1] = sound; |
| 402 | Frun_hook_with_args (make_number (2), args); | 421 | Frun_hook_with_args (make_number (2), args); |
| 403 | 422 | ||
| 423 | /* There is only one type of device we currently support, the VOX | ||
| 424 | sound driver. Set up the device interface functions for that | ||
| 425 | device. */ | ||
| 404 | vox_init (&sd); | 426 | vox_init (&sd); |
| 427 | |||
| 428 | /* Open the device. */ | ||
| 405 | sd.open (&sd); | 429 | sd.open (&sd); |
| 406 | 430 | ||
| 407 | sf.play (&sf, &sd); | 431 | /* Play the sound. */ |
| 408 | emacs_close (sf.fd); | 432 | s.play (&s, &sd); |
| 409 | sf.fd = -1; | 433 | |
| 434 | /* Close the input file, if any. */ | ||
| 435 | if (!STRINGP (s.data)) | ||
| 436 | { | ||
| 437 | emacs_close (s.fd); | ||
| 438 | s.fd = -1; | ||
| 439 | } | ||
| 440 | |||
| 441 | /* Close the device. */ | ||
| 410 | sd.close (&sd); | 442 | sd.close (&sd); |
| 411 | sound_device = NULL; | 443 | |
| 412 | sound_file = NULL; | 444 | /* Clean up. */ |
| 445 | current_sound_device = NULL; | ||
| 446 | current_sound = NULL; | ||
| 413 | UNGCPRO; | 447 | UNGCPRO; |
| 414 | unbind_to (count, Qnil); | 448 | unbind_to (count, Qnil); |
| 415 | return Qnil; | 449 | return Qnil; |
| @@ -488,19 +522,20 @@ be2hs (value) | |||
| 488 | RIFF-WAVE (*.wav) | 522 | RIFF-WAVE (*.wav) |
| 489 | ***********************************************************************/ | 523 | ***********************************************************************/ |
| 490 | 524 | ||
| 491 | /* Try to initialize sound file SF from SF->header. SF->header | 525 | /* Try to initialize sound file S from S->header. S->header |
| 492 | contains the first MAX_SOUND_HEADER_BYTES number of bytes from the | 526 | contains the first MAX_SOUND_HEADER_BYTES number of bytes from the |
| 493 | sound file. If the file is a WAV-format file, set up interface | 527 | sound file. If the file is a WAV-format file, set up interface |
| 494 | functions in SF and convert header fields to host byte-order. | 528 | functions in S and convert header fields to host byte-order. |
| 495 | Value is non-zero if the file is a WAV file. */ | 529 | Value is non-zero if the file is a WAV file. */ |
| 496 | 530 | ||
| 497 | static int | 531 | static int |
| 498 | wav_init (sf) | 532 | wav_init (s) |
| 499 | struct sound_file *sf; | 533 | struct sound *s; |
| 500 | { | 534 | { |
| 501 | struct wav_header *header = (struct wav_header *) sf->header; | 535 | struct wav_header *header = (struct wav_header *) s->header; |
| 502 | 536 | ||
| 503 | if (bcmp (sf->header, "RIFF", 4) != 0) | 537 | if (s->header_size < sizeof *header |
| 538 | || bcmp (s->header, "RIFF", 4) != 0) | ||
| 504 | return 0; | 539 | return 0; |
| 505 | 540 | ||
| 506 | /* WAV files are in little-endian order. Convert the header | 541 | /* WAV files are in little-endian order. Convert the header |
| @@ -520,28 +555,25 @@ wav_init (sf) | |||
| 520 | header->data_length = le2hl (header->data_length); | 555 | header->data_length = le2hl (header->data_length); |
| 521 | 556 | ||
| 522 | /* Set up the interface functions for WAV. */ | 557 | /* Set up the interface functions for WAV. */ |
| 523 | sf->type = RIFF; | 558 | s->type = RIFF; |
| 524 | sf->play = wav_play; | 559 | s->play = wav_play; |
| 525 | 560 | ||
| 526 | return 1; | 561 | return 1; |
| 527 | } | 562 | } |
| 528 | 563 | ||
| 529 | 564 | ||
| 530 | /* Play RIFF-WAVE audio file SF on sound device SD. */ | 565 | /* Play RIFF-WAVE audio file S on sound device SD. */ |
| 531 | 566 | ||
| 532 | static void | 567 | static void |
| 533 | wav_play (sf, sd) | 568 | wav_play (s, sd) |
| 534 | struct sound_file *sf; | 569 | struct sound *s; |
| 535 | struct sound_device *sd; | 570 | struct sound_device *sd; |
| 536 | { | 571 | { |
| 537 | struct wav_header *header = (struct wav_header *) sf->header; | 572 | struct wav_header *header = (struct wav_header *) s->header; |
| 538 | char *buffer; | ||
| 539 | int nbytes; | ||
| 540 | int blksize = 2048; | ||
| 541 | 573 | ||
| 542 | /* Let the device choose a suitable device-dependent format | 574 | /* Let the device choose a suitable device-dependent format |
| 543 | for the file. */ | 575 | for the file. */ |
| 544 | sd->choose_format (sd, sf); | 576 | sd->choose_format (sd, s); |
| 545 | 577 | ||
| 546 | /* Configure the device. */ | 578 | /* Configure the device. */ |
| 547 | sd->sample_size = header->sample_size; | 579 | sd->sample_size = header->sample_size; |
| @@ -554,14 +586,24 @@ wav_play (sf, sd) | |||
| 554 | actually more complex. This simple scheme worked with all WAV | 586 | actually more complex. This simple scheme worked with all WAV |
| 555 | files I found so far. If someone feels inclined to implement the | 587 | files I found so far. If someone feels inclined to implement the |
| 556 | whole RIFF-WAVE spec, please do. */ | 588 | whole RIFF-WAVE spec, please do. */ |
| 557 | buffer = (char *) alloca (blksize); | 589 | if (STRINGP (s->data)) |
| 558 | lseek (sf->fd, sizeof *header, SEEK_SET); | 590 | sd->write (sd, XSTRING (s->data)->data + sizeof *header, |
| 591 | STRING_BYTES (XSTRING (s->data)) - sizeof *header); | ||
| 592 | else | ||
| 593 | { | ||
| 594 | char *buffer; | ||
| 595 | int nbytes; | ||
| 596 | int blksize = 2048; | ||
| 597 | |||
| 598 | buffer = (char *) alloca (blksize); | ||
| 599 | lseek (s->fd, sizeof *header, SEEK_SET); | ||
| 559 | 600 | ||
| 560 | while ((nbytes = emacs_read (sf->fd, buffer, blksize)) > 0) | 601 | while ((nbytes = emacs_read (s->fd, buffer, blksize)) > 0) |
| 561 | sd->write (sd, buffer, nbytes); | 602 | sd->write (sd, buffer, nbytes); |
| 562 | 603 | ||
| 563 | if (nbytes < 0) | 604 | if (nbytes < 0) |
| 564 | sound_perror ("Reading sound file"); | 605 | sound_perror ("Reading sound file"); |
| 606 | } | ||
| 565 | } | 607 | } |
| 566 | 608 | ||
| 567 | 609 | ||
| @@ -585,19 +627,20 @@ enum au_encoding | |||
| 585 | }; | 627 | }; |
| 586 | 628 | ||
| 587 | 629 | ||
| 588 | /* Try to initialize sound file SF from SF->header. SF->header | 630 | /* Try to initialize sound file S from S->header. S->header |
| 589 | contains the first MAX_SOUND_HEADER_BYTES number of bytes from the | 631 | contains the first MAX_SOUND_HEADER_BYTES number of bytes from the |
| 590 | sound file. If the file is a AU-format file, set up interface | 632 | sound file. If the file is a AU-format file, set up interface |
| 591 | functions in SF and convert header fields to host byte-order. | 633 | functions in S and convert header fields to host byte-order. |
| 592 | Value is non-zero if the file is an AU file. */ | 634 | Value is non-zero if the file is an AU file. */ |
| 593 | 635 | ||
| 594 | static int | 636 | static int |
| 595 | au_init (sf) | 637 | au_init (s) |
| 596 | struct sound_file *sf; | 638 | struct sound *s; |
| 597 | { | 639 | { |
| 598 | struct au_header *header = (struct au_header *) sf->header; | 640 | struct au_header *header = (struct au_header *) s->header; |
| 599 | 641 | ||
| 600 | if (bcmp (sf->header, ".snd", 4) != 0) | 642 | if (s->header_size < sizeof *header |
| 643 | || bcmp (s->header, ".snd", 4) != 0) | ||
| 601 | return 0; | 644 | return 0; |
| 602 | 645 | ||
| 603 | header->magic_number = be2hl (header->magic_number); | 646 | header->magic_number = be2hl (header->magic_number); |
| @@ -608,42 +651,49 @@ au_init (sf) | |||
| 608 | header->channels = be2hl (header->channels); | 651 | header->channels = be2hl (header->channels); |
| 609 | 652 | ||
| 610 | /* Set up the interface functions for AU. */ | 653 | /* Set up the interface functions for AU. */ |
| 611 | sf->type = SUN_AUDIO; | 654 | s->type = SUN_AUDIO; |
| 612 | sf->play = au_play; | 655 | s->play = au_play; |
| 613 | 656 | ||
| 614 | return 1; | 657 | return 1; |
| 615 | } | 658 | } |
| 616 | 659 | ||
| 617 | 660 | ||
| 618 | /* Play Sun audio file SF on sound device SD. */ | 661 | /* Play Sun audio file S on sound device SD. */ |
| 619 | 662 | ||
| 620 | static void | 663 | static void |
| 621 | au_play (sf, sd) | 664 | au_play (s, sd) |
| 622 | struct sound_file *sf; | 665 | struct sound *s; |
| 623 | struct sound_device *sd; | 666 | struct sound_device *sd; |
| 624 | { | 667 | { |
| 625 | struct au_header *header = (struct au_header *) sf->header; | 668 | struct au_header *header = (struct au_header *) s->header; |
| 626 | int blksize = 2048; | ||
| 627 | char *buffer; | ||
| 628 | int nbytes; | ||
| 629 | 669 | ||
| 630 | sd->sample_size = 0; | 670 | sd->sample_size = 0; |
| 631 | sd->sample_rate = header->sample_rate; | 671 | sd->sample_rate = header->sample_rate; |
| 632 | sd->bps = 0; | 672 | sd->bps = 0; |
| 633 | sd->channels = header->channels; | 673 | sd->channels = header->channels; |
| 634 | sd->choose_format (sd, sf); | 674 | sd->choose_format (sd, s); |
| 635 | sd->configure (sd); | 675 | sd->configure (sd); |
| 676 | |||
| 677 | if (STRINGP (s->data)) | ||
| 678 | sd->write (sd, XSTRING (s->data)->data + header->data_offset, | ||
| 679 | STRING_BYTES (XSTRING (s->data)) - header->data_offset); | ||
| 680 | else | ||
| 681 | { | ||
| 682 | int blksize = 2048; | ||
| 683 | char *buffer; | ||
| 684 | int nbytes; | ||
| 636 | 685 | ||
| 637 | /* Seek */ | 686 | /* Seek */ |
| 638 | lseek (sf->fd, header->data_offset, SEEK_SET); | 687 | lseek (s->fd, header->data_offset, SEEK_SET); |
| 639 | 688 | ||
| 640 | /* Copy sound data to the device. */ | 689 | /* Copy sound data to the device. */ |
| 641 | buffer = (char *) alloca (blksize); | 690 | buffer = (char *) alloca (blksize); |
| 642 | while ((nbytes = emacs_read (sf->fd, buffer, blksize)) > 0) | 691 | while ((nbytes = emacs_read (s->fd, buffer, blksize)) > 0) |
| 643 | sd->write (sd, buffer, nbytes); | 692 | sd->write (sd, buffer, nbytes); |
| 644 | 693 | ||
| 645 | if (nbytes < 0) | 694 | if (nbytes < 0) |
| 646 | sound_perror ("Reading sound file"); | 695 | sound_perror ("Reading sound file"); |
| 696 | } | ||
| 647 | } | 697 | } |
| 648 | 698 | ||
| 649 | 699 | ||
| @@ -737,16 +787,16 @@ vox_close (sd) | |||
| 737 | } | 787 | } |
| 738 | 788 | ||
| 739 | 789 | ||
| 740 | /* Choose device-dependent format for device SD from sound file SF. */ | 790 | /* Choose device-dependent format for device SD from sound file S. */ |
| 741 | 791 | ||
| 742 | static void | 792 | static void |
| 743 | vox_choose_format (sd, sf) | 793 | vox_choose_format (sd, s) |
| 744 | struct sound_device *sd; | 794 | struct sound_device *sd; |
| 745 | struct sound_file *sf; | 795 | struct sound *s; |
| 746 | { | 796 | { |
| 747 | if (sf->type == RIFF) | 797 | if (s->type == RIFF) |
| 748 | { | 798 | { |
| 749 | struct wav_header *h = (struct wav_header *) sf->header; | 799 | struct wav_header *h = (struct wav_header *) s->header; |
| 750 | if (h->precision == 8) | 800 | if (h->precision == 8) |
| 751 | sd->format = AFMT_U8; | 801 | sd->format = AFMT_U8; |
| 752 | else if (h->precision == 16) | 802 | else if (h->precision == 16) |
| @@ -754,9 +804,9 @@ vox_choose_format (sd, sf) | |||
| 754 | else | 804 | else |
| 755 | error ("Unsupported WAV file format"); | 805 | error ("Unsupported WAV file format"); |
| 756 | } | 806 | } |
| 757 | else if (sf->type == SUN_AUDIO) | 807 | else if (s->type == SUN_AUDIO) |
| 758 | { | 808 | { |
| 759 | struct au_header *header = (struct au_header *) sf->header; | 809 | struct au_header *header = (struct au_header *) s->header; |
| 760 | switch (header->encoding) | 810 | switch (header->encoding) |
| 761 | { | 811 | { |
| 762 | case AU_ENCODING_ULAW_8: | 812 | case AU_ENCODING_ULAW_8: |