Play sound from file in memory
nujuwhite

I'm using miniz to load files from a .zip archive into memory. I'm hoping to put my resources in this .zip and distribute it alongside my program. My question: Is it possible to use Allegro to play a sound file stored in memory, or will i have to resort to a separate audio library?

SiegeLord

Allegro already supports loading files directly from zip files using the PhysFS addon... if you stick with miniz, however, you can use the memfile addon and then use the loading functions with the _f suffix.

nujuwhite

PhysFS seems too big and complicated... I think i'll use memfile and al_load_sample_f(). Thanks :D So if i load the file into memory, will al_load_sample_f() duplicate it, or just read from what i've already stored?

SiegeLord
nujuwhite said:

So if i load the file into memory, will al_load_sample_f() duplicate it, or just read from what i've already stored?

It will duplicate it (because it needs to decode it into the format Allegro uses to play sounds). If you don't want to duplicate, then look into the streaming API, e.g. al_load_audio_stream_f.

Thomas Fjellstrom

You can stick with miniz and al_load_audio_stream if you set up your own fshook driver.

nujuwhite said:

PhysFS seems too big and complicated...

Um, its like two or three PhysFS calls, and one allegro_physfs call. It's pretty easy, and you can stick things in zip files.

Thread #610861. Printed from Allegro.cc