Few days ago, I tried to include music files for my program. I wrote right function which read my file with headers of files music and same files.
I have not used music file yet. And now when I want load this 19 files (33 MB), I'm loading this samples and I get over 700 MB data in memory too.
I'm reading these files from my file:
I thought that I do something wrong, and get memory leak. So I tried load these files "manually":
For simplification I loading one file 19 times.
Two this ways doesn't load sample file correctly. After loading I should get about 33 MB data, but I get over than 700 MB.
Did you heard about problem like this? I use Allegro 5.0.10. I tried load this way in two projects to be sure.
If you understand, I send link for my topic about this on a Polish forum PC Format: http://forum.pcformat.pl/C-Allegro-5-Dealokacja-pliku-ALLEGRO-FILE-t
Ogg is compressed. al_load_sample loads the audio and decompresses it into raw PCM data.
If you want to use music, you're best off using streaming[1]
Ok, thanks!
Now I know why I get so many megabytes of data.
But I'd ask if I understand everything correctly and I'm doing everything what I should.
There is cool example which I base: ex_stream_file, but I'm not sure that I'm understanding everything right.
So, now I would like to summary what I centrainly do. This is test project, but there I include every step, which I want implement in my game. Only difference that I read music files from one file by al_load_audio_stream_f.
1. When I'm initializing Allegro, I turn on audio streaming. I'm saving a frequency, mixerDepth, voiceDepth and channel conf. I'm creating mixer and voice.
2. In my player I will have pointer on ALLEGRO_AUDIO_STREAM - *musicStream. On begin set on NULL.
3. Now when I want to handle stream:
a) If I want play stream, I call my function playStream:
b) If I want change volume, call this function: al_set_audio_stream_gain(musicStream, 'float value');
c) If I want stop stream, call this function: al_detach_audio_stream(musicStream);
Two asks:
1. How is difference between function above and al_drain_audio_stream? What should I use?
2. I'm not sure what means second and third argument of al_load_audio_stream.
- Second is probably size (on kilobytes?) of stream, which will be loading to play like one piece of stream.
- Third is for information how many streams can play at the same time, through my pointer musicStream? Can I change to 1? At the same time I will playing only one sample. Maybe is nonsense give 2048?
So, this is everything what I should do for correctly handling audio stream in Allegro? Of course, in the end, I'm destroing audio stream, mixer and voice.