I had overlooked a few memory allocation/deallocation issues for audio buffers.
Hopefully this helps clean those up.
This commit is contained in:
@@ -24,6 +24,7 @@ openal_test2_SOURCES = openal_test2.cxx
|
|||||||
openal_test1_LDADD = \
|
openal_test1_LDADD = \
|
||||||
$(top_builddir)/simgear/debug/libsgdebug.a \
|
$(top_builddir)/simgear/debug/libsgdebug.a \
|
||||||
$(openal_LIBS)
|
$(openal_LIBS)
|
||||||
|
|
||||||
openal_test2_LDADD = \
|
openal_test2_LDADD = \
|
||||||
$(top_builddir)/simgear/sound/libsgsound.a \
|
$(top_builddir)/simgear/sound/libsgsound.a \
|
||||||
$(top_builddir)/simgear/debug/libsgdebug.a \
|
$(top_builddir)/simgear/debug/libsgdebug.a \
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ SGSoundSample::SGSoundSample( const char *path, const char *file,
|
|||||||
SG_LOG( SG_GENERAL, SG_DEBUG, "From file sounds sample = "
|
SG_LOG( SG_GENERAL, SG_DEBUG, "From file sounds sample = "
|
||||||
<< samplepath.str() );
|
<< 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;
|
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;
|
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
|
// constructor
|
||||||
SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq ) :
|
SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq,
|
||||||
|
bool cleanup) :
|
||||||
data(NULL),
|
data(NULL),
|
||||||
pitch(1.0),
|
pitch(1.0),
|
||||||
volume(1.0),
|
volume(1.0),
|
||||||
@@ -172,6 +173,14 @@ SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq ) :
|
|||||||
freq = _freq;
|
freq = _freq;
|
||||||
|
|
||||||
alBufferData( buffer, format, data, size, 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.
|
// Bind buffer with a source.
|
||||||
alGenSources(1, &source);
|
alGenSources(1, &source);
|
||||||
@@ -195,9 +204,6 @@ SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq ) :
|
|||||||
// destructor
|
// destructor
|
||||||
SGSoundSample::~SGSoundSample() {
|
SGSoundSample::~SGSoundSample() {
|
||||||
SG_LOG( SG_GENERAL, SG_INFO, "Deleting a sample" );
|
SG_LOG( SG_GENERAL, SG_INFO, "Deleting a sample" );
|
||||||
if ( data != NULL ) {
|
|
||||||
free(data);
|
|
||||||
}
|
|
||||||
alDeleteSources(1, &source);
|
alDeleteSources(1, &source);
|
||||||
alDeleteBuffers(1, &buffer);
|
alDeleteBuffers(1, &buffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,18 @@ public:
|
|||||||
later.)
|
later.)
|
||||||
*/
|
*/
|
||||||
SGSoundSample( const char *path, const char *file, bool cleanup );
|
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();
|
~SGSoundSample();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user