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:
ehofman
2009-10-24 12:57:11 +00:00
committed by Tim Moore
parent 7c5de29b61
commit a06a15e769
4 changed files with 10 additions and 8 deletions

View File

@@ -202,7 +202,7 @@ void SGSampleGroup::update( double dt ) {
}
// 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 );
if ( sample_it != _samples.end() ) {

View File

@@ -56,8 +56,7 @@
using std::map;
using std::string;
typedef SGSharedPtr<SGSoundSample> SGSoundSample_ptr;
typedef map < string, SGSoundSample_ptr > sample_map;
typedef map < string, SGSharedPtr<SGSoundSample> > sample_map;
typedef sample_map::iterator 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
* @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.
@@ -225,7 +224,7 @@ private:
SGGeod _position;
sample_map _samples;
std::vector<SGSoundSample_ptr> _removed_samples;
std::vector< SGSharedPtr<SGSoundSample> > _removed_samples;
bool testForALError(string s);
bool testForError(void *p, string s);

View File

@@ -150,7 +150,7 @@ SGSoundSample::SGSoundSample( const unsigned char** data,
_is_file(false)
{
SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" );
_data = (unsigned char*)data; *data = NULL;
_data = (unsigned char*)*data; *data = NULL;
}
// constructor
@@ -185,7 +185,7 @@ SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) :
_is_file(false)
{
SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" );
_data = (unsigned char*)data; *data = NULL;
_data = (unsigned char*)*data; *data = NULL;
}

View File

@@ -377,6 +377,8 @@ unsigned int SGSoundMgr::request_source()
_free_sources.pop_back();
_sources_in_use.push_back(source);
}
else
SG_LOG( SG_GENERAL, SG_INFO, "No more free sources available\n");
return source;
}
@@ -453,8 +455,9 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample)
}
}
}
else
else {
buffer = sample->get_buffer();
}
return buffer;
}