Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Play sound from file in memory

This thread is locked; no one can reply to it. rss feed Print
Play sound from file in memory
nujuwhite
Member #14,390
June 2012

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
Member #7,827
October 2006
avatar

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.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

nujuwhite
Member #14,390
June 2012

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
Member #7,827
October 2006
avatar

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.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Thomas Fjellstrom
Member #476
June 2000
avatar

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.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Go to: