![]() |
|
music in allegro5 |
adamk kromm
Member #5,432
January 2005
|
So i've never done anything with music before... samples/voices/mixers... mean nothing to me I'm dumb!... so by alot of reading the api and other things i came up with this al_install_audio(ALLEGRO_AUDIO_DRIVER_AUTODETECT); ALLEGRO_SAMPLE *test = al_load_sample_wav("music/simple.wav"); if(!test) cout<<"couldnt load music"<<endl; else al_play_sample(test,255, 128, 1000, 0,NULL);
but it doesnt work... i looked for other files to link to and include in the project but didnt find anything that looked like it would help. ---------- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
You'll want to link to kcm_audio as well. acodec just provides audio decoders for popular formats. At some point I'll probably be renamed to better fit the current naming scheme. -- |
adamk kromm
Member #5,432
January 2005
|
perfect, now it compiles and i dont get any errors, but i dont hear anything EDIT: after more reading i've changed it to this; al_install_audio(ALLEGRO_AUDIO_DRIVER_AUTODETECT); if(!al_reserve_samples(5)) cout<<"couldnt reserve samples"<<endl; ALLEGRO_SAMPLE *test = al_load_sample("music/simple.wav"); ALLEGRO_SAMPLE_ID testid; if(!test) cout<<"couldnt load music"<<endl; al_play_sample(test,1, ALLEGRO_AUDIO_PAN_NONE, 1, 1, &testid); but still no sound... ---------- |
weapon_S
Member #7,859
October 2006
![]() |
if(!al_install_audio(ALLEGRO_AUDIO_DRIVER_AUTODETECT)) cout<<"Apparently can't find a driver"<<endl; Maybe? I don't know about a5 error messages... |
Trent Gamblin
Member #261
April 2000
![]() |
Post a test case. What you have should work unless there's something else wrong in your code. Secondly, you're better of streaming your music than loading it all into memory. A 1 minute sample is going to take huge amounts of memory.
|
Matthew Leverton
Supreme Loser
January 1999
![]() |
Use ALLEGRO_PLAYMODE_ONCE or ALLEGRO_PLAYMODE_LOOP for the fifth argument. I don't think either of them are defined to 1. The last parameter can be NULL if you never need to explicitly stop it. Also, some wav files won't load in 4.9.12 if they have extended information embedded in them. But most should work. |
adamk kromm
Member #5,432
January 2005
|
ok here is what i got now. if(!al_install_audio(ALLEGRO_AUDIO_DRIVER_AUTODETECT)) cout<<"couldnt install audio"<<endl; if(!al_reserve_samples(2048)) cout<<"couldnt reserve samples"<<endl; ALLEGRO_SAMPLE *test = al_load_sample("music/simple.wav"); ALLEGRO_SAMPLE_ID testid; if(!test) cout<<"couldnt load music"<<endl; al_play_sample(test,1.0, ALLEGRO_AUDIO_PAN_NONE, 1.0, ALLEGRO_PLAYMODE_ONCE , &testid); and it works now!... kinda. after adding ALLEGRO_PLAYMODE_ONCE... but it sounds really jacked up... then crashes haha. how do i stream it instead of loading it all? ---------- |
Matthew Leverton
Supreme Loser
January 1999
![]() |
al_stream_from_file |
adamk kromm
Member #5,432
January 2005
|
did that and now i dont get any noise, or any errors... bad .wav? it works in itunes... btw: what do i put in al_reserve_samples() (or do i even need that anymore?) ---------- |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Did you attach the stream to a mixer? Check out ex_stream_file.c. al_reserve_samples() sets up a default voice and mixer and is required for al_play_sample(). If you set up your own voice and mixer and don't use al_play_sample(), then you don't need it. |
adamk kromm
Member #5,432
January 2005
|
nope didnt attach the stream to a mixer... (stream, mixer, sample, voice, they all still mean very little to me, but they're starting to come together.) EDIT: I now have this 1if(!al_install_audio(ALLEGRO_AUDIO_DRIVER_AUTODETECT))
2 cout<<"couldnt install audio"<<endl;
3 if(!al_reserve_samples(2048))
4 cout<<"couldnt reserve samples"<<endl;
5
6 ALLEGRO_VOICE* voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2);
7 if(!voice)
8 cout<<"couldnt create voice"<<endl;
9 ALLEGRO_MIXER* mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2);
10 if(!mixer)
11 cout<<"couldnt create mixer"<<endl;
12 if(!al_attach_mixer_to_voice(voice, mixer))
13 cout<<"couldnt attach mixer to voice"<<endl;
14 ALLEGRO_STREAM *stream = al_stream_from_file(4,2048,"music/simple.wav");
15 if(!stream)
16 cout<<"couldnt start the stream"<<endl;
17 if(!al_attach_stream_to_mixer(mixer, stream))
18 cout<<"Couldnt attach stream to mixer"<<endl;
but still no sound or errors... i copied ex_stream_file.c as best i could. EDIT: EDIT: is there someway to change the volume or something?? and for al_stream_from_file, how do i know what to put for the first two arguments? EDIT: EDIT: EDIT: Just found out the wav file was junk ---------- |
Matthew Leverton
Supreme Loser
January 1999
![]() |
|
adamk kromm
Member #5,432
January 2005
|
perfect thanks! Just what i needed to know! ---------- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Matthew Leverton said: 4.9.13 has better support for loading wav files. Technically its worse. While Elias added support for skipping unknown data in the wav, Peter decided it was ok to remove support for libsndfile, which is what supported encoded wav files (ADPCM etc). So now all we're going to get is plain old un encoded wav support (back to how it was in A4). -- |
Matthew Leverton
Supreme Loser
January 1999
![]() |
I won't be including libsndfile in any Allegro.cc binary distributions, so I don't care either way. |
Peter Wang
Member #23
April 2000
|
I don't think we need an official sndfile addon. ADPCM wave files would be the strongest reason, but in a game you can pick which file formats you want to use, and I can't see why you'd use ADPCM wave files over FLAC or Ogg Vorbis, if you are concerned about the size of uncompressed PCM. The sizes of the FLAC and sndfile libraries are nearly the same, and Ogg Vorbis is smaller than either: Quote:
-rwxr-xr-x 1 root root 328704 2008-09-11 09:28 libFLAC.so.8.2.0
Not to mention ADPCM sounds crap.
|
Thomas Fjellstrom
Member #476
June 2000
![]() |
Yeah, I can't say why someone would pick ADPCM or other encoded wav formats over plain old Ogg, flac, or mp3 for that matter. And heck, one of these days someone should add a Speex loader as well. -- |
|