Use shared pointers for any reference to SGSoundSample, fix the constructor of SGSoundSample where data is supplied by the calling program.
This commit is contained in:
@@ -202,7 +202,7 @@ void SGSampleGroup::update( double dt ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add a sound effect, return true if successful
|
// add a sound effect, return true if successful
|
||||||
bool SGSampleGroup::add( SGSoundSample *sound, const string& refname ) {
|
bool SGSampleGroup::add( SGSharedPtr<SGSoundSample> sound, const string& refname ) {
|
||||||
|
|
||||||
sample_map_iterator sample_it = _samples.find( refname );
|
sample_map_iterator sample_it = _samples.find( refname );
|
||||||
if ( sample_it != _samples.end() ) {
|
if ( sample_it != _samples.end() ) {
|
||||||
|
|||||||
@@ -56,8 +56,7 @@
|
|||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
typedef SGSharedPtr<SGSoundSample> SGSoundSample_ptr;
|
typedef map < string, SGSharedPtr<SGSoundSample> > sample_map;
|
||||||
typedef map < string, SGSoundSample_ptr > sample_map;
|
|
||||||
typedef sample_map::iterator sample_map_iterator;
|
typedef sample_map::iterator sample_map_iterator;
|
||||||
typedef sample_map::const_iterator const_sample_map_iterator;
|
typedef sample_map::const_iterator const_sample_map_iterator;
|
||||||
|
|
||||||
@@ -106,7 +105,7 @@ public:
|
|||||||
* @param refname Name of this audio sample for reference purposes
|
* @param refname Name of this audio sample for reference purposes
|
||||||
* @return return true if successful
|
* @return return true if successful
|
||||||
*/
|
*/
|
||||||
bool add( SGSoundSample *sound, const string& refname );
|
bool add( SGSharedPtr<SGSoundSample> sound, const string& refname );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an audio sample from this group.
|
* Remove an audio sample from this group.
|
||||||
@@ -225,7 +224,7 @@ private:
|
|||||||
SGGeod _position;
|
SGGeod _position;
|
||||||
|
|
||||||
sample_map _samples;
|
sample_map _samples;
|
||||||
std::vector<SGSoundSample_ptr> _removed_samples;
|
std::vector< SGSharedPtr<SGSoundSample> > _removed_samples;
|
||||||
|
|
||||||
bool testForALError(string s);
|
bool testForALError(string s);
|
||||||
bool testForError(void *p, string s);
|
bool testForError(void *p, string s);
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ SGSoundSample::SGSoundSample( const unsigned char** data,
|
|||||||
_is_file(false)
|
_is_file(false)
|
||||||
{
|
{
|
||||||
SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" );
|
SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" );
|
||||||
_data = (unsigned char*)data; *data = NULL;
|
_data = (unsigned char*)*data; *data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
@@ -185,7 +185,7 @@ SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) :
|
|||||||
_is_file(false)
|
_is_file(false)
|
||||||
{
|
{
|
||||||
SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" );
|
SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" );
|
||||||
_data = (unsigned char*)data; *data = NULL;
|
_data = (unsigned char*)*data; *data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -377,6 +377,8 @@ unsigned int SGSoundMgr::request_source()
|
|||||||
_free_sources.pop_back();
|
_free_sources.pop_back();
|
||||||
_sources_in_use.push_back(source);
|
_sources_in_use.push_back(source);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
SG_LOG( SG_GENERAL, SG_INFO, "No more free sources available\n");
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
@@ -453,8 +455,9 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
buffer = sample->get_buffer();
|
buffer = sample->get_buffer();
|
||||||
|
}
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user