equal
deleted
inserted
replaced
411 SDL_AudioSpec * spec, Uint8 ** audio_buf, Uint32 * audio_len) |
411 SDL_AudioSpec * spec, Uint8 ** audio_buf, Uint32 * audio_len) |
412 { |
412 { |
413 int was_error; |
413 int was_error; |
414 Chunk chunk; |
414 Chunk chunk; |
415 int lenread; |
415 int lenread; |
416 int MS_ADPCM_encoded, IMA_ADPCM_encoded; |
416 int IEEE_float_encoded, MS_ADPCM_encoded, IMA_ADPCM_encoded; |
417 int samplesize; |
417 int samplesize; |
418 |
418 |
419 /* WAV magic header */ |
419 /* WAV magic header */ |
420 Uint32 RIFFchunk; |
420 Uint32 RIFFchunk; |
421 Uint32 wavelen = 0; |
421 Uint32 wavelen = 0; |
470 if (chunk.magic != FMT) { |
470 if (chunk.magic != FMT) { |
471 SDL_SetError("Complex WAVE files not supported"); |
471 SDL_SetError("Complex WAVE files not supported"); |
472 was_error = 1; |
472 was_error = 1; |
473 goto done; |
473 goto done; |
474 } |
474 } |
475 MS_ADPCM_encoded = IMA_ADPCM_encoded = 0; |
475 IEEE_float_encoded = MS_ADPCM_encoded = IMA_ADPCM_encoded = 0; |
476 switch (SDL_SwapLE16(format->encoding)) { |
476 switch (SDL_SwapLE16(format->encoding)) { |
477 case PCM_CODE: |
477 case PCM_CODE: |
|
478 /* We can understand this */ |
|
479 break; |
|
480 case IEEE_FLOAT_CODE: |
|
481 IEEE_float_encoded = 1; |
478 /* We can understand this */ |
482 /* We can understand this */ |
479 break; |
483 break; |
480 case MS_ADPCM_CODE: |
484 case MS_ADPCM_CODE: |
481 /* Try to understand this */ |
485 /* Try to understand this */ |
482 if (InitMS_ADPCM(format) < 0) { |
486 if (InitMS_ADPCM(format) < 0) { |
504 was_error = 1; |
508 was_error = 1; |
505 goto done; |
509 goto done; |
506 } |
510 } |
507 SDL_memset(spec, 0, (sizeof *spec)); |
511 SDL_memset(spec, 0, (sizeof *spec)); |
508 spec->freq = SDL_SwapLE32(format->frequency); |
512 spec->freq = SDL_SwapLE32(format->frequency); |
509 switch (SDL_SwapLE16(format->bitspersample)) { |
513 |
510 case 4: |
514 if (IEEE_float_encoded) { |
511 if (MS_ADPCM_encoded || IMA_ADPCM_encoded) { |
515 if ((SDL_SwapLE16(format->bitspersample)) != 32) { |
|
516 was_error = 1; |
|
517 } else { |
|
518 spec->format = AUDIO_F32; |
|
519 } |
|
520 } else { |
|
521 switch (SDL_SwapLE16(format->bitspersample)) { |
|
522 case 4: |
|
523 if (MS_ADPCM_encoded || IMA_ADPCM_encoded) { |
|
524 spec->format = AUDIO_S16; |
|
525 } else { |
|
526 was_error = 1; |
|
527 } |
|
528 break; |
|
529 case 8: |
|
530 spec->format = AUDIO_U8; |
|
531 break; |
|
532 case 16: |
512 spec->format = AUDIO_S16; |
533 spec->format = AUDIO_S16; |
513 } else { |
534 break; |
514 was_error = 1; |
535 case 32: |
515 } |
536 spec->format = AUDIO_S32; |
516 break; |
537 break; |
517 case 8: |
538 default: |
518 spec->format = AUDIO_U8; |
539 was_error = 1; |
519 break; |
540 break; |
520 case 16: |
541 } |
521 spec->format = AUDIO_S16; |
542 } |
522 break; |
543 |
523 default: |
|
524 was_error = 1; |
|
525 break; |
|
526 } |
|
527 if (was_error) { |
544 if (was_error) { |
528 SDL_SetError("Unknown %d-bit PCM data format", |
545 SDL_SetError("Unknown %d-bit PCM data format", |
529 SDL_SwapLE16(format->bitspersample)); |
546 SDL_SwapLE16(format->bitspersample)); |
530 goto done; |
547 goto done; |
531 } |
548 } |