#173342 - protomank - Fri Apr 02, 2010 12:04 pm
Is there anyone with free time and will to help me to fix the SDL_Mixer?
Currently, the problem is in wave reading, in this part of the code:
It is always returning SDL_EFREAD. Here is the big function that call ReadChunk:
The struct that contains the wave (I believe the problem is here):
It does not seem too complex to fix, but I lack any knowledge about wave format :-(
_________________
Iuri Fiedoruk
http://rockbot.upperland.net
Currently, the problem is in wave reading, in this part of the code:
Code: |
#define SDL_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n) static int ReadChunk(SDL_RWops *src, Chunk *chunk) { chunk->magic = SDL_ReadLE32(src); chunk->length = SDL_ReadLE32(src); chunk->data = (Uint8 *)malloc(chunk->length); if ( chunk->data == NULL ) { SDL_Error(SDL_ENOMEM); return(-1); } if ( SDL_RWread(src, chunk->data, chunk->length, 1) != 1 ) { SDL_Error(SDL_EFREAD); free(chunk->data); return(-1); } return(chunk->length); } |
It is always returning SDL_EFREAD. Here is the big function that call ReadChunk:
Code: |
SDL_AudioSpec * SDL_LoadWAV_RW (SDL_RWops *src, int freesrc,
SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len) { int was_error; Chunk chunk; int lenread; int MS_ADPCM_encoded, IMA_ADPCM_encoded; int samplesize; /* WAV magic header */ Uint32 RIFFchunk; Uint32 wavelen; Uint32 WAVEmagic; /* FMT chunk */ WaveFMT *format = NULL; /* Make sure we are passed a valid data source */ was_error = 0; if ( src == NULL ) { was_error = 1; goto done; } /* Check the magic header */ RIFFchunk = SDL_ReadLE32(src); wavelen = SDL_ReadLE32(src); if ( wavelen == WAVE ) { /* The RIFFchunk has already been read */ WAVEmagic = wavelen; wavelen = RIFFchunk; RIFFchunk = RIFF; } else { WAVEmagic = SDL_ReadLE32(src); } if ( (RIFFchunk != RIFF) || (WAVEmagic != WAVE) ) { SDL_SetError("Unrecognized file type (not WAVE)"); was_error = 1; goto done; } /* Read the audio data format chunk */ chunk.data = NULL; do { if ( chunk.data != NULL ) { free(chunk.data); } lenread = ReadChunk(src, &chunk); if ( lenread < 0 ) { was_error = 1; goto done; } } while ( (chunk.magic == FACT) || (chunk.magic == LIST) ); /* Decode the audio data format */ format = (WaveFMT *)chunk.data; if ( chunk.magic != FMT ) { SDL_SetError("Complex WAVE files not supported"); was_error = 1; goto done; } MS_ADPCM_encoded = IMA_ADPCM_encoded = 0; switch (SDL_SwapLE16(format->encoding)) { case PCM_CODE: /* We can understand this */ break; case MS_ADPCM_CODE: /* Try to understand this */ if ( InitMS_ADPCM(format) < 0 ) { was_error = 1; goto done; } MS_ADPCM_encoded = 1; break; case IMA_ADPCM_CODE: /* Try to understand this */ if ( InitIMA_ADPCM(format) < 0 ) { was_error = 1; goto done; } IMA_ADPCM_encoded = 1; break; default: SDL_SetError("Unknown WAVE data format: 0x%.4x", SDL_SwapLE16(format->encoding)); was_error = 1; goto done; } memset(spec, 0, (sizeof *spec)); spec->freq = SDL_SwapLE32(format->frequency); switch (SDL_SwapLE16(format->bitspersample)) { case 4: if ( MS_ADPCM_encoded || IMA_ADPCM_encoded ) { spec->format = AUDIO_S16; } else { was_error = 1; } break; case 8: spec->format = AUDIO_U8; break; case 16: spec->format = AUDIO_S16; break; default: was_error = 1; break; } if ( was_error ) { SDL_SetError("Unknown %d-bit PCM data format", SDL_SwapLE16(format->bitspersample)); goto done; } spec->channels = (Uint8)SDL_SwapLE16(format->channels); spec->samples = 4096; /* Good default buffer size */ /* Read the audio data chunk */ *audio_buf = NULL; do { if ( *audio_buf != NULL ) { free(*audio_buf); } lenread = ReadChunk(src, &chunk); if ( lenread < 0 ) { was_error = 1; goto done; } *audio_len = lenread; *audio_buf = chunk.data; } while ( chunk.magic != DATA ); if ( MS_ADPCM_encoded ) { if ( MS_ADPCM_decode(audio_buf, audio_len) < 0 ) { was_error = 1; goto done; } } if ( IMA_ADPCM_encoded ) { if ( IMA_ADPCM_decode(audio_buf, audio_len) < 0 ) { was_error = 1; goto done; } } /* Don't return a buffer that isn't a multiple of samplesize */ samplesize = ((spec->format & 0xFF)/8)*spec->channels; *audio_len &= ~(samplesize-1); done: if ( format != NULL ) { free(format); } if ( freesrc && src ) { SDL_RWclose(src); } if ( was_error ) { spec = NULL; } return(spec); } |
The struct that contains the wave (I believe the problem is here):
Code: |
typedef struct SDL_RWops { /* Seek to 'offset' relative to whence, one of stdio's whence values: SEEK_SET, SEEK_CUR, SEEK_END Returns the final offset in the data source. */ int (SDLCALL *seek)(struct SDL_RWops *context, int offset, int whence); /* Read up to 'num' objects each of size 'objsize' from the data source to the area pointed at by 'ptr'. Returns the number of objects read, or -1 if the read failed. */ int (SDLCALL *read)(struct SDL_RWops *context, void *ptr, int size, int maxnum); /* Write exactly 'num' objects each of size 'objsize' from the area pointed at by 'ptr' to data source. Returns 'num', or -1 if the write failed. */ int (SDLCALL *write)(struct SDL_RWops *context, const void *ptr, int size, int num); /* Close and free an allocated SDL_FSops structure */ int (SDLCALL *close)(struct SDL_RWops *context); Uint32 type; union { struct { int autoclose; FILE *fp; } stdio; struct { Uint8 *base; Uint8 *here; Uint8 *stop; } mem; struct { void *data1; } unknown; } hidden; } SDL_RWops; |
It does not seem too complex to fix, but I lack any knowledge about wave format :-(
_________________
Iuri Fiedoruk
http://rockbot.upperland.net