|
al_load_sample's loading many data |
JurekGP
Member #15,891
February 2015
|
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'm reading these files from my file: 1for(unsigned i = 0; i < songCount; i++)
2{
3 buffer = new char[songs[i]->fileLength];
4 file.read(buffer, songs[i]->fileLength);
5 alFile = al_open_memfile((void*)buffer, songs[i]->fileLength, "rb");
6 ALLEGRO_SAMPLE *sample = al_load_sample_f(alFile, songs[i]->fileType.c_str());
7 songs[i]->addSongFile(sample);
8 std::cout << &buffer << " " << alFile << " " << sample << std::endl;
9 al_fclose(alFile);
10 alFile = NULL;
11 delete[] buffer;
12 buffer = NULL;
13}
I thought that I do something wrong, and get memory leak. So I tried load these files "manually": 2ALLEGRO_SAMPLE *sample = NULL;
3sample = al_load_sample("music.ogg");
4songs[0]->addSongFile(sample);
5sample = al_load_sample("music.ogg");
6songs[1]->addSongFile(sample);
7sample = al_load_sample("music.ogg");
8songs[2]->addSongFile(sample);
9sample = al_load_sample("music.ogg");
10songs[3]->addSongFile(sample);
11sample = al_load_sample("music.ogg");
12songs[4]->addSongFile(sample);
13sample = al_load_sample("music.ogg");
14songs[5]->addSongFile(sample);
15sample = al_load_sample("music.ogg");
16songs[6]->addSongFile(sample);
17sample = al_load_sample("music.ogg");
18songs[7]->addSongFile(sample);
19sample = al_load_sample("music.ogg");
20songs[8]->addSongFile(sample);
21sample = al_load_sample("music.ogg");
22songs[9]->addSongFile(sample);
23sample = al_load_sample("music.ogg");
24songs[10]->addSongFile(sample);
25sample = al_load_sample("music.ogg");
26songs[11]->addSongFile(sample);
27sample = al_load_sample("music.ogg");
28songs[12]->addSongFile(sample);
29sample = al_load_sample("music.ogg");
30songs[13]->addSongFile(sample);
31sample = al_load_sample("music.ogg");
32songs[14]->addSongFile(sample);
33sample = al_load_sample("music.ogg");
34songs[15]->addSongFile(sample);
35sample = al_load_sample("music.ogg");
36songs[16]->addSongFile(sample);
37sample = al_load_sample("music.ogg");
38songs[17]->addSongFile(sample);
39sample = al_load_sample("music.ogg");
40songs[18]->addSongFile(sample);
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 Hi! I'm Pole and my english is not very well. So, please understanding to me. :) |
Thomas Fjellstrom
Member #476
June 2000
|
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] -- |
JurekGP
Member #15,891
February 2015
|
Ok, thanks! 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. 1void TestGame::playStream(std::string filePath)
2{
3 if(musicStream)
4 al_destroy_audio_stream(musicStream);
5 musicStream = al_load_audio_stream(filePath.c_str(), 4, 2048);
6 al_register_event_source(gameCore->alManager->getAllegroEventQueue(), al_get_audio_stream_event_source(musicStream));
7 al_attach_audio_stream_to_mixer(musicStream, gameCore->alManager->getAllegroMixer());
8}
b) If I want change volume, call this function: al_set_audio_stream_gain(musicStream, 'float value'); Two asks: 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. Hi! I'm Pole and my english is not very well. So, please understanding to me. :) |
|