Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » SAMPLE_INSTANCE vs a beginner (me)

This thread is locked; no one can reply to it. rss feed Print
SAMPLE_INSTANCE vs a beginner (me)
mir0slaw
Member #15,677
July 2014

Hello!
I'm new to this forum and quite new to programming as well. This far, I've written two very simple games using Allegro 5 but I still don't feel particurarly sure that I always know what's going on.
I've never had this problem before, maybe it's caused by using a wrong name somewhere, maybe it's an effect of me having not enough C++ knowledge. Whatever.
If you could help me, I'd be very greatful!

So, what is my problem? I'm following this tutorial: http://fixbyproximity.com/oop-game-development/
Here's my problem:
My SAMPLE_INSTANCE does not want to play at all. I tried al_set_sample_instance_playing(songInstance, true) as well as al_play_sample_instance(songInstance). At first, I put it in my changeState function, but I've also tried to put it in various places in main just to see, where the problem is.
I've told the program to write out if the sample_instance is playing and it always told me: 0, (not playing). The changeState function itself most certainly works, because I've told the game to write out the current state and it changed how I wanted it to.

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:

#SelectExpand
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.

#SelectExpand
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 :)

---
EDIT:
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
"oh, it works with this one. Strange"
checked if I misspelled the file name or something but not. It was also .wav
I opened it in Audacity and exported it again as a .wav (not having changed anything)
I replaced my old .wav file with the new one from Audacity
It started working.

I'm dumbfounded. But also glad it worked.
Thank you for all the advise you've given me.
Cheers!

Elias
Member #358
May 2000

Does ex_mixer_chain work for you?

--
"Either help out or stop whining" - Evert

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 ?
Well, I tried, but my compiler doesn't know what common.c is and I also found this on the net: http://opensource.apple.com/source/pam_modules/pam_modules-126.1/common/Common.c and copied it into the project, but compiler doesn't know what all those included files are:
<code start="1'>#include <CoreFoundation/CoreFoundation.h>
#include <DirectoryService/DirectoryService.h>
#include <OpenDirectory/OpenDirectory.h>
#include <OpenDirectory/OpenDirectoryPriv.h>
#include <ServerInformation/ServerInformation.h></code>

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.
Thank you!
Cheers

Thomas Fjellstrom
Member #476
June 2000
avatar

If you have the allegro source you can compile the examples from there.

--
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

Arthur Kalliokoski
Second in Command
February 2005
avatar

Give him the link too.

Sources and windows binaries

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:
http://postimg.org/image/xu3xpofr1/full/
Did I do something wrong?
Cheers

Arthur Kalliokoski
Second in Command
February 2005
avatar

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
avatar

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.

--
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

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
avatar

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.

--
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

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
"oh, it works with this one. Strange"
checked if I misspelled the file name or something but not. It was also .wav
I opened it in Audacity and exported it again as a .wav (not having changed anything)
I replaced my old .wav file with the new one from Audacity
It started working.

I'm dumbfounded. But also glad it worked.
Thank you for all the advise you've given me.
Cheers!

Arthur Kalliokoski
Second in Command
February 2005
avatar

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
avatar

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

Go to: