|
Problems with ALLEGRO_SAMPLE_ID* |
Desmond Taylor
Member #11,943
May 2010
|
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. This is the vector that holds the array. 1std::vector<SAMPLE_DATA> sample;
This is how I load, play and stop the sounds. 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. 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
|
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
|
Thank you so much. It works fine now Edit: How do I thank you at the top? |
J-Gamer
Member #12,491
January 2011
|
"... 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 |
Desmond Taylor
Member #11,943
May 2010
|
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"} |
J-Gamer
Member #12,491
January 2011
|
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 |
Arthur Kalliokoski
Second in Command
February 2005
|
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
|
Ahh, I shall keep that in mind thanks guys |
|