Mercurial > sdl-ios-xcode
comparison src/audio/SDL_wave.c @ 1336:3692456e7b0f
Use SDL_ prefixed versions of C library functions.
FIXME:
Change #include <stdlib.h> to #include "SDL_stdlib.h"
Change #include <string.h> to #include "SDL_string.h"
Make sure nothing else broke because of this...
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 06:59:48 +0000 |
parents | 450721ad5436 |
children | 604d73db6802 |
comparison
equal
deleted
inserted
replaced
1335:c39265384763 | 1336:3692456e7b0f |
---|---|
133 encoded = *audio_buf; | 133 encoded = *audio_buf; |
134 freeable = *audio_buf; | 134 freeable = *audio_buf; |
135 *audio_len = (encoded_len/MS_ADPCM_state.wavefmt.blockalign) * | 135 *audio_len = (encoded_len/MS_ADPCM_state.wavefmt.blockalign) * |
136 MS_ADPCM_state.wSamplesPerBlock* | 136 MS_ADPCM_state.wSamplesPerBlock* |
137 MS_ADPCM_state.wavefmt.channels*sizeof(Sint16); | 137 MS_ADPCM_state.wavefmt.channels*sizeof(Sint16); |
138 *audio_buf = (Uint8 *)malloc(*audio_len); | 138 *audio_buf = (Uint8 *)SDL_malloc(*audio_len); |
139 if ( *audio_buf == NULL ) { | 139 if ( *audio_buf == NULL ) { |
140 SDL_Error(SDL_ENOMEM); | 140 SDL_Error(SDL_ENOMEM); |
141 return(-1); | 141 return(-1); |
142 } | 142 } |
143 decoded = *audio_buf; | 143 decoded = *audio_buf; |
212 ++encoded; | 212 ++encoded; |
213 samplesleft -= 2; | 213 samplesleft -= 2; |
214 } | 214 } |
215 encoded_len -= MS_ADPCM_state.wavefmt.blockalign; | 215 encoded_len -= MS_ADPCM_state.wavefmt.blockalign; |
216 } | 216 } |
217 free(freeable); | 217 SDL_free(freeable); |
218 return(0); | 218 return(0); |
219 } | 219 } |
220 | 220 |
221 struct IMA_ADPCM_decodestate { | 221 struct IMA_ADPCM_decodestate { |
222 Sint32 sample; | 222 Sint32 sample; |
350 encoded = *audio_buf; | 350 encoded = *audio_buf; |
351 freeable = *audio_buf; | 351 freeable = *audio_buf; |
352 *audio_len = (encoded_len/IMA_ADPCM_state.wavefmt.blockalign) * | 352 *audio_len = (encoded_len/IMA_ADPCM_state.wavefmt.blockalign) * |
353 IMA_ADPCM_state.wSamplesPerBlock* | 353 IMA_ADPCM_state.wSamplesPerBlock* |
354 IMA_ADPCM_state.wavefmt.channels*sizeof(Sint16); | 354 IMA_ADPCM_state.wavefmt.channels*sizeof(Sint16); |
355 *audio_buf = (Uint8 *)malloc(*audio_len); | 355 *audio_buf = (Uint8 *)SDL_malloc(*audio_len); |
356 if ( *audio_buf == NULL ) { | 356 if ( *audio_buf == NULL ) { |
357 SDL_Error(SDL_ENOMEM); | 357 SDL_Error(SDL_ENOMEM); |
358 return(-1); | 358 return(-1); |
359 } | 359 } |
360 decoded = *audio_buf; | 360 decoded = *audio_buf; |
392 } | 392 } |
393 decoded += (channels * 8 * 2); | 393 decoded += (channels * 8 * 2); |
394 } | 394 } |
395 encoded_len -= IMA_ADPCM_state.wavefmt.blockalign; | 395 encoded_len -= IMA_ADPCM_state.wavefmt.blockalign; |
396 } | 396 } |
397 free(freeable); | 397 SDL_free(freeable); |
398 return(0); | 398 return(0); |
399 } | 399 } |
400 | 400 |
401 SDL_AudioSpec * SDL_LoadWAV_RW (SDL_RWops *src, int freesrc, | 401 SDL_AudioSpec * SDL_LoadWAV_RW (SDL_RWops *src, int freesrc, |
402 SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len) | 402 SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len) |
442 | 442 |
443 /* Read the audio data format chunk */ | 443 /* Read the audio data format chunk */ |
444 chunk.data = NULL; | 444 chunk.data = NULL; |
445 do { | 445 do { |
446 if ( chunk.data != NULL ) { | 446 if ( chunk.data != NULL ) { |
447 free(chunk.data); | 447 SDL_free(chunk.data); |
448 } | 448 } |
449 lenread = ReadChunk(src, &chunk); | 449 lenread = ReadChunk(src, &chunk); |
450 if ( lenread < 0 ) { | 450 if ( lenread < 0 ) { |
451 was_error = 1; | 451 was_error = 1; |
452 goto done; | 452 goto done; |
487 SDL_SetError("Unknown WAVE data format: 0x%.4x", | 487 SDL_SetError("Unknown WAVE data format: 0x%.4x", |
488 SDL_SwapLE16(format->encoding)); | 488 SDL_SwapLE16(format->encoding)); |
489 was_error = 1; | 489 was_error = 1; |
490 goto done; | 490 goto done; |
491 } | 491 } |
492 memset(spec, 0, (sizeof *spec)); | 492 SDL_memset(spec, 0, (sizeof *spec)); |
493 spec->freq = SDL_SwapLE32(format->frequency); | 493 spec->freq = SDL_SwapLE32(format->frequency); |
494 switch (SDL_SwapLE16(format->bitspersample)) { | 494 switch (SDL_SwapLE16(format->bitspersample)) { |
495 case 4: | 495 case 4: |
496 if ( MS_ADPCM_encoded || IMA_ADPCM_encoded ) { | 496 if ( MS_ADPCM_encoded || IMA_ADPCM_encoded ) { |
497 spec->format = AUDIO_S16; | 497 spec->format = AUDIO_S16; |
519 | 519 |
520 /* Read the audio data chunk */ | 520 /* Read the audio data chunk */ |
521 *audio_buf = NULL; | 521 *audio_buf = NULL; |
522 do { | 522 do { |
523 if ( *audio_buf != NULL ) { | 523 if ( *audio_buf != NULL ) { |
524 free(*audio_buf); | 524 SDL_free(*audio_buf); |
525 } | 525 } |
526 lenread = ReadChunk(src, &chunk); | 526 lenread = ReadChunk(src, &chunk); |
527 if ( lenread < 0 ) { | 527 if ( lenread < 0 ) { |
528 was_error = 1; | 528 was_error = 1; |
529 goto done; | 529 goto done; |
551 samplesize = ((spec->format & 0xFF)/8)*spec->channels; | 551 samplesize = ((spec->format & 0xFF)/8)*spec->channels; |
552 *audio_len &= ~(samplesize-1); | 552 *audio_len &= ~(samplesize-1); |
553 | 553 |
554 done: | 554 done: |
555 if ( format != NULL ) { | 555 if ( format != NULL ) { |
556 free(format); | 556 SDL_free(format); |
557 } | 557 } |
558 if ( freesrc && src ) { | 558 if ( freesrc && src ) { |
559 SDL_RWclose(src); | 559 SDL_RWclose(src); |
560 } | 560 } |
561 else { | 561 else { |
572 be freed here. (Necessary under Win32, VC++) | 572 be freed here. (Necessary under Win32, VC++) |
573 */ | 573 */ |
574 void SDL_FreeWAV(Uint8 *audio_buf) | 574 void SDL_FreeWAV(Uint8 *audio_buf) |
575 { | 575 { |
576 if ( audio_buf != NULL ) { | 576 if ( audio_buf != NULL ) { |
577 free(audio_buf); | 577 SDL_free(audio_buf); |
578 } | 578 } |
579 } | 579 } |
580 | 580 |
581 static int ReadChunk(SDL_RWops *src, Chunk *chunk) | 581 static int ReadChunk(SDL_RWops *src, Chunk *chunk) |
582 { | 582 { |
583 chunk->magic = SDL_ReadLE32(src); | 583 chunk->magic = SDL_ReadLE32(src); |
584 chunk->length = SDL_ReadLE32(src); | 584 chunk->length = SDL_ReadLE32(src); |
585 chunk->data = (Uint8 *)malloc(chunk->length); | 585 chunk->data = (Uint8 *)SDL_malloc(chunk->length); |
586 if ( chunk->data == NULL ) { | 586 if ( chunk->data == NULL ) { |
587 SDL_Error(SDL_ENOMEM); | 587 SDL_Error(SDL_ENOMEM); |
588 return(-1); | 588 return(-1); |
589 } | 589 } |
590 if ( SDL_RWread(src, chunk->data, chunk->length, 1) != 1 ) { | 590 if ( SDL_RWread(src, chunk->data, chunk->length, 1) != 1 ) { |
591 SDL_Error(SDL_EFREAD); | 591 SDL_Error(SDL_EFREAD); |
592 free(chunk->data); | 592 SDL_free(chunk->data); |
593 return(-1); | 593 return(-1); |
594 } | 594 } |
595 return(chunk->length); | 595 return(chunk->length); |
596 } | 596 } |
597 | 597 |