Problems with ALLEGRO_SAMPLE_ID*
Desmond Taylor

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

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

Desmond Taylor

Thank you so much. It works fine now :)

Edit: How do I thank you at the top?

J-Gamer

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

Desmond Taylor

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

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

Arthur Kalliokoski

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

Desmond Taylor

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

Thread #607054. Printed from Allegro.cc