|
SAMPLE_INSTANCE vs a beginner (me) |
mir0slaw
Member #15,677
July 2014
|
Hello! So, what is my problem? I'm following this tutorial: http://fixbyproximity.com/oop-game-development/ So, what the hell is wrong with my instance? I don't know. Here are parts of my code that include anything connected with the instance. This is global: ALLEGRO_SAMPLE_INSTANCE *songInstance; This is in main: 1ALLEGRO_SAMPLE *mainLoop = NULL;
2//...
3al_install_keyboard();
4al_init_image_addon();
5al_init_font_addon();
6al_init_ttf_addon();
7al_init_primitives_addon();
8al_install_audio();
9al_init_acodec_addon();
10//...
11//...
12al_reserve_samples(25);
13mainLoop = al_load_sample("MainLoop.wav");
14songInstance = al_create_sample_instance(mainLoop);
15al_set_sample_instance_playmode(songInstance, ALLEGRO_PLAYMODE_LOOP);
16al_attach_sample_instance_to_mixer(songInstance, al_get_default_mixer());
17
18ChangeState(state, TITLE);
19srand(time(NULL));
20
21//...
22al_destroy_sample_instance(songInstance);
And this is the changeState function, called right now only once, just before while(!done) loop. 1void ChangeState(int &state, int newState)
2{
3 if (state == TITLE)
4 {
5
6 }
7 else if (state == PLAYING)
8 {
9 for (iter = objects.begin(); iter != objects.end(); ++iter)
10 {
11 if ((*iter)->GetID() != PLAYER && (*iter)->GetID() != MISC)
12 (*iter)->SetAlive(false);
13 }
14 al_stop_sample_instance(songInstance);
15 }
16 else if (state == LOST)
17 {
18
19 }
20
21 if (newState == TITLE)
22 {
23 al_play_sample_instance(songInstance);
24 }
25 else if (newState == PLAYING)
26 {
27
28 }
29 else if (newState == LOST)
30 {
31
32 }
33
34 state = newState;
35}
Cheers --- checked if another .wav sound would play I'm dumbfounded. But also glad it worked. |
Elias
Member #358
May 2000
|
Does ex_mixer_chain work for you? -- |
mir0slaw
Member #15,677
July 2014
|
I'm sorry, but I don't think I understand what I should do. Do you mean trying to run this file: http://sourceforge.net/p/alleg/allegro/ci/5.1/tree/examples/ex_mixer_chain.c#l20 ? Also, I've already made programs in Allegro which had working sample instances, but I don't see any differences in code between them and this one. This is strange. Please, remember that I'm new to programming, so try to explain things more carefully. |
Thomas Fjellstrom
Member #476
June 2000
|
If you have the allegro source you can compile the examples from there. -- |
Arthur Kalliokoski
Second in Command
February 2005
|
Give him the link too. They all watch too much MSNBC... they get ideas. |
mir0slaw
Member #15,677
July 2014
|
Well, I have Allegro 5.0.10 so I used an example from 5.0.10 zip file. I tried to build and run the file "ex_mixer_chain.c" but it gave me a few errors. Here's a screen shot: |
Arthur Kalliokoski
Second in Command
February 2005
|
The file "common.c" defines open_log() and the others, so somehow you're not including it. Is it in the same directory/folder as ex_mixer_chain.c? For the error "char followed by bool is illegal", I'd just delete the word 'char' and see if that works. They all watch too much MSNBC... they get ideas. |
Thomas Fjellstrom
Member #476
June 2000
|
That makes me think that you're using msvc? That bool char error comes from bool being new to C99, which allegro will partially emulate. But the example you're compiling may be picking up the in configured allegro source instead of a properly installed copy. Try just grabbing the pre compiled examples that were linked. -- |
mir0slaw
Member #15,677
July 2014
|
But if I open that .exe file that this kind man linked, I get an error "Couldn't find allegro-5.0.8-monolith-md.dll on your computer". And on allegro web page I can only see download links for 5.0.10 version. What should I do? And by the way, what is this .exe supposed to do? Cheers |
Thomas Fjellstrom
Member #476
June 2000
|
The dll should be in another download on that page. If the example doesn't work, then its a system or allegro problem, rather than your code. -- |
mir0slaw
Member #15,677
July 2014
|
Ok guys, so I have a very surprising solution to my problem. I honestly have no idea why it worked, but here's what I did: checked if another .wav sound would play I'm dumbfounded. But also glad it worked. |
Arthur Kalliokoski
Second in Command
February 2005
|
mir0slaw said: checked if I misspelled the file name or something but not. It was also .wav I think there are some special compression formats that weren't programmed into Allegro. They all watch too much MSNBC... they get ideas. |
Slartibartfast
Member #8,789
June 2007
|
Sounds like the real issue is that you aren't checking the return values of the functions you are using. I'd wager al_load_sample returned NULL for your "bad" .wav and you didn't even notice. ---- |
mir0slaw
Member #15,677
July 2014
|
I forgot I could do that, that's valuable advice. Thanks |
|