Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Problems with ALLEGRO_SAMPLE_ID*

This thread is locked; no one can reply to it. rss feed Print
Problems with ALLEGRO_SAMPLE_ID*
Desmond Taylor
Member #11,943
May 2010
avatar

I am having a slight problem with my audio class. It just stops responding when I use this->sample[id].sample_id in the al_play_sample() function.

Here is the struct used to hold the data.

#SelectExpand
1struct SAMPLE_DATA 2{ 3 ALLEGRO_SAMPLE* sample; 4 ALLEGRO_SAMPLE_ID* sample_id; 5};

This is the vector that holds the array.

#SelectExpand
1std::vector<SAMPLE_DATA> sample;

This is how I load, play and stop the sounds.

#SelectExpand
1int Audio::load_from_file( std::string filename ) 2{ 3 ALLEGRO_SAMPLE* temp_sample = al_load_sample( filename.c_str() ); 4 if ( temp_sample ) 5 { 6 SAMPLE_DATA sd; 7 sd.sample = temp_sample; 8 this->sample.push_back( sd ); 9 return this->sample.size() - 1; 10 } 11 12 return -1; 13} 14 15void Audio::play( int id, ALLEGRO_PLAYMODE loop, float gain, float pan, float speed ) 16{ 17 if ( this->is_valid_id( id ) ) 18 { 19 al_play_sample( this->sample[id].sample, gain, pan, speed, loop, this->sample[id].sample_id ); 20 } 21} 22 23void Audio::stop( int id ) 24{ 25 if ( this->is_valid_id( id ) ) 26 { 27 al_stop_sample( this->sample[id].sample_id ); 28 } 29}

If I use this it works fine but then I have no sample id to stop it.

#SelectExpand
1void Audio::play( int id, ALLEGRO_PLAYMODE loop, float gain, float pan, float speed ) 2{ 3 if ( this->is_valid_id( id ) ) 4 { 5 al_play_sample( this->sample[id].sample, gain, pan, speed, loop, NULL ); 6 } 7}

Any suggestions?

Matthew Leverton
Supreme Loser
January 1999
avatar

Use ALLEGRO_SAMPLE_ID foo; and pass &foo as the parameter. You are passing around a pointer to unallocated memory.

Desmond Taylor
Member #11,943
May 2010
avatar

Thank you so much. It works fine now :)

Edit: How do I thank you at the top?

J-Gamer
Member #12,491
January 2011
avatar

"... is answered to my satisfaction"(there's a checkbox for it when you reply)

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Desmond Taylor
Member #11,943
May 2010
avatar

There is no boxes :/

{"name":"603949","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/7\/b7e48d0e185cce31f384c0bd795b76ee.png","w":1024,"h":768,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/7\/b7e48d0e185cce31f384c0bd795b76ee"}603949

J-Gamer
Member #12,491
January 2011
avatar

Maybe this is because you didn't select "a question with a specific answer" or something like that...(when writing the OP)

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Arthur Kalliokoski
Second in Command
February 2005
avatar

When you create the thread, you have to select "A question or problem with a specific answer" under the Classification pulldown.

They all watch too much MSNBC... they get ideas.

Desmond Taylor
Member #11,943
May 2010
avatar

Ahh, I shall keep that in mind thanks guys :)

Go to: