X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fsound%2Fsample_openal.cxx;h=92acd8ad25b4eaab4e3276cfebef93dc52a5775d;hb=ea513d392e050578fcc017e0c888a3374f0dcead;hp=655a7e27c14301bee9225828430f1dd24a7385df;hpb=24c7941f65aa7d3fab3ee54fe982111c1f52656d;p=simgear.git diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 655a7e27..92acd8ad 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -1,8 +1,10 @@ -// sample.cxx -- Sound sample encapsulation class +// sample_openal.cxx -- Audio sample encapsulation class // // Written by Curtis Olson, started April 2004. +// Modified to match the new SoundSystem by Erik Hofman, October 2009 // // Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt +// Copyright (C) 2009 Erik Hofman // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -24,6 +26,8 @@ # include #endif +#include // rand() + #include #include #include @@ -43,9 +47,10 @@ SGSoundSample::SGSoundSample() : _relative_pos(SGVec3d::zeros()), _direction(SGVec3d::zeros()), _velocity(SGVec3d::zeros()), - _base_pos(SGGeod()), _orientation(SGQuatd::zeros()), - _sample_name(""), + _orivec(SGVec3f::zeros()), + _base_pos(SGGeod()), + _refname(random_string()), _data(NULL), _format(AL_FORMAT_MONO8), _size(0), @@ -66,8 +71,7 @@ SGSoundSample::SGSoundSample() : _playing(false), _changed(true), _static_changed(true), - _is_file(false), - _orivec(SGVec3f::zeros()) + _is_file(false) { } @@ -77,8 +81,9 @@ SGSoundSample::SGSoundSample( const char *path, const char *file ) : _relative_pos(SGVec3d::zeros()), _direction(SGVec3d::zeros()), _velocity(SGVec3d::zeros()), - _base_pos(SGGeod()), _orientation(SGQuatd::zeros()), + _orivec(SGVec3f::zeros()), + _base_pos(SGGeod()), _format(AL_FORMAT_MONO8), _size(0), _freq(0), @@ -98,28 +103,30 @@ SGSoundSample::SGSoundSample( const char *path, const char *file ) : _playing(false), _changed(true), _static_changed(true), - _is_file(true), - _orivec(SGVec3f::zeros()) + _is_file(true) { SGPath samplepath( path ); if ( strlen(file) ) { samplepath.append( file ); } - _sample_name = samplepath.str(); + _refname = samplepath.str(); SG_LOG( SG_GENERAL, SG_DEBUG, "From file sounds sample = " << samplepath.str() ); } // constructor -SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format ) : +SGSoundSample::SGSoundSample( std::auto_ptr& data, + int len, int freq, int format ) : _absolute_pos(SGVec3d::zeros()), _relative_pos(SGVec3d::zeros()), _direction(SGVec3d::zeros()), _velocity(SGVec3d::zeros()), - _base_pos(SGGeod()), _orientation(SGQuatd::zeros()), - _data(data), + _orivec(SGVec3f::zeros()), + _base_pos(SGGeod()), + _refname(random_string()), + _data(data.release()), _format(format), _size(len), _freq(freq), @@ -139,10 +146,8 @@ SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format _playing(false), _changed(true), _static_changed(true), - _is_file(false), - _orivec(SGVec3f::zeros()) + _is_file(false) { - _sample_name = "unknown, data supplied by caller"; SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" ); } @@ -151,25 +156,25 @@ SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format SGSoundSample::~SGSoundSample() { } -void SGSoundSample::set_orientation( SGQuatd ori ) { +void SGSoundSample::set_orientation( const SGQuatd& ori ) { _orientation = ori; update_absolute_position(); _changed = true; } -void SGSoundSample::set_direction( SGVec3d dir ) { +void SGSoundSample::set_direction( const SGVec3d& dir ) { _direction = dir; update_absolute_position(); _changed = true; } -void SGSoundSample::set_relative_position( SGVec3f pos ) { +void SGSoundSample::set_relative_position( const SGVec3f& pos ) { _relative_pos = toVec3d(pos); update_absolute_position(); _changed = true; } -void SGSoundSample::set_position( SGGeod pos ) { +void SGSoundSample::set_position( const SGGeod& pos ) { _base_pos = pos; update_absolute_position(); _changed = true; @@ -178,7 +183,20 @@ void SGSoundSample::set_position( SGGeod pos ) { void SGSoundSample::update_absolute_position() { SGQuatd orient = SGQuatd::fromLonLat(_base_pos) * _orientation; _orivec = -toVec3f(orient.rotate(_direction)); +printf("ori: %f %f %f\n", _orivec[0], _orivec[1], _orivec[2]); + + orient = SGQuatd::fromRealImag(0, _relative_pos) * _orientation; + _absolute_pos = -SGVec3d::fromGeod(_base_pos); // -orient.rotate(SGVec3d::e1()); +printf("pos: %f %f %f\n", _absolute_pos[0], _absolute_pos[1], _absolute_pos[2]); +} + +string SGSoundSample::random_string() { + static const char *r = "0123456789abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + string rstr; + for (int i=0; i<10; i++) { + rstr.push_back( r[rand() % strlen(r)] ); + } - orient = SGQuatd::fromRealImag(0, _relative_pos) * _orientation; - _absolute_pos = -SGVec3d::fromGeod(_base_pos) -orient.rotate(SGVec3d::e1()); + return rstr; }