SDL Mixer load sound from memory (zip file)


#1

Hi. I have a problem with SDL Mixer. I do not know how to read a sound file from a zip file. I know the functions Mix_QuickLoad_WAV and Mix_QuickLoad_RAW. But I do not know how to use them.

When I read the file from the zip, I get data of type char *. But if I use any of the above functions, with this data, this happens:

char * data = new char [dat.size];
zip_fread (ZIPFILE, data, dat.size);
audio = Mix_QuickLoad_WAV(data);  
//audio = Mix_QuickLoad_WAV(data,dat.size);  

Invalid conversion from ‘char *’ to 'Uint8 *.

I tried to do this but it does not work.

Uint8 * datos = reinterpret_cast <Uint8 *> (data);
audio = Mix_QuickLoad_WAV(datos);  
//audio = Mix_QuickLoad_WAV(datos,dat.size); 

If you can help me, please.

Thank you very much.


#2

Did this not work?

audio = Mix_QuickLoad_WAV((Uint8*)data);

The QuickLoad function isn’t safe to use and does no checking and returns no errors. You could try creating a SDL_RWops for memory so you can use Mix_LoadWAV_RW:

char * data = new char [dat.size];
zip_fread (ZIPFILE, data, dat.size);
SDL_RWops *rw = SDL_RWFromMem((void*)data, dat.size);
audio = Mix_LoadWAV_RW(rw, 0);

#3

Now works well with SDL_RWops.

Thank you very much for your help, friend.

Regards.