I had overlooked a few memory allocation/deallocation issues for audio buffers.

Hopefully this helps clean those up.
This commit is contained in:
curt
2004-05-10 21:22:50 +00:00
parent a9faf8ceff
commit 331a4e4406
3 changed files with 24 additions and 6 deletions

View File

@@ -24,6 +24,7 @@ openal_test2_SOURCES = openal_test2.cxx
openal_test1_LDADD = \
$(top_builddir)/simgear/debug/libsgdebug.a \
$(openal_LIBS)
openal_test2_LDADD = \
$(top_builddir)/simgear/sound/libsgsound.a \
$(top_builddir)/simgear/debug/libsgdebug.a \

View File

@@ -80,7 +80,7 @@ SGSoundSample::SGSoundSample( const char *path, const char *file,
SG_LOG( SG_GENERAL, SG_DEBUG, "From file sounds sample = "
<< samplepath.str() );
source_pos[0] = 0.0; source_pos[1] = 0.0; source_pos[2] = 0.0;
source_pos[0] = 0.0; source_pos[1] = 0.0; source_pos[2] = 0.0;
offset_pos[0] = 0.0; offset_pos[1] = 0.0; offset_pos[2] = 0.0;
source_vel[0] = 0.0; source_vel[1] = 0.0; source_vel[2] = 0.0;
@@ -138,7 +138,8 @@ SGSoundSample::SGSoundSample( const char *path, const char *file,
// constructor
SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq ) :
SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq,
bool cleanup) :
data(NULL),
pitch(1.0),
volume(1.0),
@@ -172,6 +173,14 @@ SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq ) :
freq = _freq;
alBufferData( buffer, format, data, size, freq );
if (alGetError() != AL_NO_ERROR) {
throw sg_exception("Failed to buffer data.");
}
if ( cleanup ) {
alutUnloadWAV( format, data, size, freq );
data = NULL;
}
// Bind buffer with a source.
alGenSources(1, &source);
@@ -195,9 +204,6 @@ SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq ) :
// destructor
SGSoundSample::~SGSoundSample() {
SG_LOG( SG_GENERAL, SG_INFO, "Deleting a sample" );
if ( data != NULL ) {
free(data);
}
alDeleteSources(1, &source);
alDeleteBuffers(1, &buffer);
}

View File

@@ -101,7 +101,18 @@ public:
later.)
*/
SGSoundSample( const char *path, const char *file, bool cleanup );
SGSoundSample( unsigned char *_data, int len, int _freq );
/**
* Constructor.
* @param _data Pointer to a memory buffer containing the sample data
* @param len Byte length of array
* @param _freq Frequency of the provided data (bytes per second)
* @param cleanup Request clean up the intermediate data (this
should usually be true unless you want to manipulate the data
later.)
*/
SGSoundSample( unsigned char *_data, int len, int _freq, bool cleanup );
~SGSoundSample();
/**