get rid of aut_ptr, it only works with objects that can destroyed with delete (and not even delete[]) which is too limited. take drastic actions to find the sound-not-playing-bug: set all positions and orientations to default all the time.
This commit is contained in:
@@ -169,7 +169,6 @@ void SGSampleGroup::update( double dt ) {
|
||||
SG_LOG( SG_GENERAL, SG_ALERT, "No such buffer!\n");
|
||||
// sample->no_valid_source();
|
||||
// sadly, no free source available at this time
|
||||
printf("No free source found.");
|
||||
}
|
||||
|
||||
} else if ( sample->is_valid_source() && sample->has_changed() ) {
|
||||
@@ -393,6 +392,7 @@ void SGSampleGroup::update_sample_config( SGSoundSample *sample ) {
|
||||
if ( sample->is_valid_source() ) {
|
||||
unsigned int source = sample->get_source();
|
||||
|
||||
#if 0
|
||||
if ( _tied_to_listener && _smgr->has_changed() ) {
|
||||
alSourcefv( source, AL_POSITION, _smgr->get_position().data() );
|
||||
alSourcefv( source, AL_DIRECTION, _smgr->get_direction().data() );
|
||||
@@ -402,6 +402,11 @@ void SGSampleGroup::update_sample_config( SGSoundSample *sample ) {
|
||||
alSourcefv( source, AL_DIRECTION, sample->get_orientation() );
|
||||
alSourcefv( source, AL_VELOCITY, sample->get_velocity() );
|
||||
}
|
||||
#else
|
||||
alSourcefv( source, AL_POSITION, SGVec3f::zeros().data() );
|
||||
alSourcefv( source, AL_DIRECTION, SGVec3f::zeros().data() );
|
||||
alSourcefv( source, AL_VELOCITY, SGVec3f::zeros().data() );
|
||||
#endif
|
||||
testForALError("position and orientation");
|
||||
|
||||
alSourcef( source, AL_PITCH, sample->get_pitch() );
|
||||
@@ -409,9 +414,11 @@ void SGSampleGroup::update_sample_config( SGSoundSample *sample ) {
|
||||
testForALError("pitch and gain");
|
||||
|
||||
if ( sample->has_static_data_changed() ) {
|
||||
#if 0
|
||||
alSourcef( source, AL_CONE_INNER_ANGLE, sample->get_innerangle() );
|
||||
alSourcef( source, AL_CONE_OUTER_ANGLE, sample->get_outerangle() );
|
||||
alSourcef( source, AL_CONE_OUTER_GAIN, sample->get_outergain() );
|
||||
#endif
|
||||
testForALError("audio cone");
|
||||
|
||||
alSourcef( source, AL_MAX_DISTANCE, sample->get_max_dist() );
|
||||
|
||||
@@ -84,6 +84,8 @@ SGSoundSample::SGSoundSample( const char *path, const char *file ) :
|
||||
_orientation(SGQuatd::zeros()),
|
||||
_orivec(SGVec3f::zeros()),
|
||||
_base_pos(SGGeod()),
|
||||
_refname(file),
|
||||
_data(NULL),
|
||||
_format(AL_FORMAT_MONO8),
|
||||
_size(0),
|
||||
_freq(0),
|
||||
@@ -116,7 +118,7 @@ SGSoundSample::SGSoundSample( const char *path, const char *file ) :
|
||||
}
|
||||
|
||||
// constructor
|
||||
SGSoundSample::SGSoundSample( std::auto_ptr<unsigned char>& data,
|
||||
SGSoundSample::SGSoundSample( const unsigned char** data,
|
||||
int len, int freq, int format ) :
|
||||
_absolute_pos(SGVec3d::zeros()),
|
||||
_relative_pos(SGVec3d::zeros()),
|
||||
@@ -126,7 +128,6 @@ SGSoundSample::SGSoundSample( std::auto_ptr<unsigned char>& data,
|
||||
_orivec(SGVec3f::zeros()),
|
||||
_base_pos(SGGeod()),
|
||||
_refname(random_string()),
|
||||
_data(data.release()),
|
||||
_format(format),
|
||||
_size(len),
|
||||
_freq(freq),
|
||||
@@ -149,11 +150,49 @@ SGSoundSample::SGSoundSample( std::auto_ptr<unsigned char>& data,
|
||||
_is_file(false)
|
||||
{
|
||||
SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" );
|
||||
_data = (unsigned char*)data; *data = NULL;
|
||||
}
|
||||
|
||||
// constructor
|
||||
SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) :
|
||||
_absolute_pos(SGVec3d::zeros()),
|
||||
_relative_pos(SGVec3d::zeros()),
|
||||
_direction(SGVec3d::zeros()),
|
||||
_velocity(SGVec3d::zeros()),
|
||||
_orientation(SGQuatd::zeros()),
|
||||
_orivec(SGVec3f::zeros()),
|
||||
_base_pos(SGGeod()),
|
||||
_refname(random_string()),
|
||||
_format(format),
|
||||
_size(len),
|
||||
_freq(freq),
|
||||
_valid_buffer(false),
|
||||
_buffer(SGSoundMgr::NO_BUFFER),
|
||||
_valid_source(false),
|
||||
_source(SGSoundMgr::NO_SOURCE),
|
||||
_inner_angle(360.0),
|
||||
_outer_angle(360.0),
|
||||
_outer_gain(0.0),
|
||||
_pitch(1.0),
|
||||
_volume(1.0),
|
||||
_master_volume(1.0),
|
||||
_reference_dist(500.0),
|
||||
_max_dist(3000.0),
|
||||
_loop(AL_FALSE),
|
||||
_playing(false),
|
||||
_changed(true),
|
||||
_static_changed(true),
|
||||
_is_file(false)
|
||||
{
|
||||
SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" );
|
||||
_data = (unsigned char*)data; *data = NULL;
|
||||
}
|
||||
|
||||
|
||||
// destructor
|
||||
SGSoundSample::~SGSoundSample() {
|
||||
if (_data) free( _data );
|
||||
_data = NULL;
|
||||
}
|
||||
|
||||
void SGSoundSample::set_orientation( const SGQuatd& ori ) {
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
@@ -70,12 +69,14 @@ public:
|
||||
* Constructor.
|
||||
* @param data Pointer to a memory buffer containing this audio sample data
|
||||
The application may free the data by calling free_data(), otherwise it
|
||||
will be resident untill the class is destroyed.
|
||||
will be resident untill the class is destroyed. This pointer will be
|
||||
set to NULL after calling this function.
|
||||
* @param len Byte length of array
|
||||
* @param freq Frequency of the provided data (bytes per second)
|
||||
* @param format OpenAL format id of the data
|
||||
*/
|
||||
SGSoundSample( std::auto_ptr<unsigned char>& data, int len, int freq,
|
||||
SGSoundSample( void** data, int len, int freq, int format=AL_FORMAT_MONO8 );
|
||||
SGSoundSample( const unsigned char** data, int len, int freq,
|
||||
int format = AL_FORMAT_MONO8 );
|
||||
|
||||
/**
|
||||
@@ -150,24 +151,28 @@ public:
|
||||
inline bool is_playing() { return _playing; }
|
||||
|
||||
/**
|
||||
* sSt the data associated with this audio sample
|
||||
* Set the data associated with this audio sample
|
||||
* @param data Pointer to a memory block containg this audio sample data.
|
||||
This pointer will be set to NULL after calling this function.
|
||||
*/
|
||||
inline void set_data( std::auto_ptr<unsigned char>& data ) {
|
||||
_data = data;
|
||||
inline void set_data( const unsigned char **data ) {
|
||||
_data = (unsigned char*)*data; *data = NULL;
|
||||
}
|
||||
inline void set_data( void **data ) {
|
||||
_data = (unsigned char*)*data; *data = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data associated with this audio sample.
|
||||
* @return A pointer to this sound data of this audio sample.
|
||||
*/
|
||||
inline void* get_data() const { return _data.get(); }
|
||||
inline void* get_data() const { return _data; }
|
||||
|
||||
/**
|
||||
* Free the data associated with this audio sample
|
||||
*/
|
||||
void free_data() {
|
||||
free( _data.release() );
|
||||
if ( _data ) free( _data ); _data = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -435,7 +440,7 @@ private:
|
||||
SGGeod _base_pos; // base position
|
||||
|
||||
std::string _refname; // name or file path
|
||||
std::auto_ptr<unsigned char> _data;
|
||||
unsigned char* _data;
|
||||
|
||||
// configuration values
|
||||
int _format;
|
||||
|
||||
@@ -94,7 +94,6 @@ SGSoundMgr::~SGSoundMgr() {
|
||||
// initialize the sound manager
|
||||
void SGSoundMgr::init() {
|
||||
|
||||
printf("Initializing OpenAL sound manager\n");
|
||||
SG_LOG( SG_GENERAL, SG_INFO, "Initializing OpenAL sound manager" );
|
||||
|
||||
ALCdevice *device = alcOpenDevice(_devname);
|
||||
@@ -154,7 +153,6 @@ printf("Initializing OpenAL sound manager\n");
|
||||
else break;
|
||||
}
|
||||
|
||||
printf("%i free sources found\n", _free_sources.size() );
|
||||
if (_free_sources.size() == 0) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "Unable to grab any OpenAL sources!");
|
||||
}
|
||||
@@ -175,7 +173,6 @@ void SGSoundMgr::activate() {
|
||||
// stop the sound manager
|
||||
void SGSoundMgr::stop() {
|
||||
if (_working) {
|
||||
printf("Stopping Sound Manager\n");
|
||||
_working = false;
|
||||
_active = false;
|
||||
|
||||
@@ -198,7 +195,6 @@ printf("Stopping Sound Manager\n");
|
||||
|
||||
void SGSoundMgr::suspend() {
|
||||
if (_working) {
|
||||
printf("SoundManager suspend\n");
|
||||
sample_group_map_iterator sample_grp_current = _sample_groups.begin();
|
||||
sample_group_map_iterator sample_grp_end = _sample_groups.end();
|
||||
for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) {
|
||||
@@ -211,7 +207,6 @@ printf("SoundManager suspend\n");
|
||||
|
||||
void SGSoundMgr::resume() {
|
||||
if (_working) {
|
||||
printf("SoundManager resume\n");
|
||||
sample_group_map_iterator sample_grp_current = _sample_groups.begin();
|
||||
sample_group_map_iterator sample_grp_end = _sample_groups.end();
|
||||
for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) {
|
||||
@@ -224,7 +219,6 @@ printf("SoundManager resume\n");
|
||||
|
||||
void SGSoundMgr::bind ()
|
||||
{
|
||||
printf("SoundManager bind\n");
|
||||
_free_sources.clear();
|
||||
_free_sources.reserve( MAX_SOURCES );
|
||||
_sources_in_use.clear();
|
||||
@@ -234,7 +228,6 @@ printf("SoundManager bind\n");
|
||||
|
||||
void SGSoundMgr::unbind ()
|
||||
{
|
||||
printf("SoundManager unbind\n");
|
||||
_sample_groups.clear();
|
||||
|
||||
// delete free sources
|
||||
@@ -259,9 +252,11 @@ void SGSoundMgr::update_late( double dt ) {
|
||||
|
||||
if (_changed) {
|
||||
alListenerf( AL_GAIN, _volume );
|
||||
#if 0
|
||||
alListenerfv( AL_ORIENTATION, _at_up_vec );
|
||||
alListenerfv( AL_POSITION, toVec3f(_position).data() );
|
||||
alListenerfv( AL_VELOCITY, toVec3f(_velocity).data() );
|
||||
#endif
|
||||
// alDopplerVelocity(340.3); // TODO: altitude dependent
|
||||
testForALError("update");
|
||||
_changed = false;
|
||||
@@ -430,10 +425,7 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample)
|
||||
void *data;
|
||||
|
||||
load(sample_name, &data, &format, &size, &freq);
|
||||
std::auto_ptr<unsigned char> ptr;
|
||||
ptr.reset((unsigned char *)data);
|
||||
|
||||
sample->set_data( ptr );
|
||||
sample->set_data( &data );
|
||||
sample->set_frequency( freq );
|
||||
sample->set_format( format );
|
||||
sample->set_size( size );
|
||||
|
||||
Reference in New Issue
Block a user