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() ) {
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() );
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() );
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() );
_orientation(SGQuatd::zeros()),
_orivec(SGVec3f::zeros()),
_base_pos(SGGeod()),
+ _refname(file),
+ _data(NULL),
_format(AL_FORMAT_MONO8),
_size(0),
_freq(0),
}
// 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()),
_orivec(SGVec3f::zeros()),
_base_pos(SGGeod()),
_refname(random_string()),
- _data(data.release()),
_format(format),
_size(len),
_freq(freq),
_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 ) {
#endif
#include <string>
-#include <memory>
#include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx>
* 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 );
/**
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;
}
/**
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;
// 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);
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!");
}
// stop the sound manager
void SGSoundMgr::stop() {
if (_working) {
-printf("Stopping Sound Manager\n");
_working = false;
_active = false;
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 ) {
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 ) {
void SGSoundMgr::bind ()
{
-printf("SoundManager bind\n");
_free_sources.clear();
_free_sources.reserve( MAX_SOURCES );
_sources_in_use.clear();
void SGSoundMgr::unbind ()
{
-printf("SoundManager unbind\n");
_sample_groups.clear();
// delete free sources
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;
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 );