]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/sample_openal.cxx
use auto_ptr instead
[simgear.git] / simgear / sound / sample_openal.cxx
index d82c42a2f5080f9f104e93c9b1bff3ad3de34919..a4efd08a16c9761d60c3ee80f94b3476cda85eb0 100644 (file)
@@ -26,6 +26,8 @@
 #  include <simgear_config.h>
 #endif
 
+#include <stdlib.h>    // rand()
+
 #include <simgear/debug/logstream.hxx>
 #include <simgear/structure/exception.hxx>
 #include <simgear/misc/sg_path.hxx>
@@ -48,7 +50,7 @@ SGSoundSample::SGSoundSample() :
     _orientation(SGQuatd::zeros()),
     _orivec(SGVec3f::zeros()),
     _base_pos(SGGeod()),
-    _refname(""),
+    _refname(random_string()),
     _data(NULL),
     _format(AL_FORMAT_MONO8),
     _size(0),
@@ -114,7 +116,8 @@ SGSoundSample::SGSoundSample( const char *path, const char *file ) :
 }
 
 // constructor
-SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format ) :
+SGSoundSample::SGSoundSample( std::auto_ptr<unsigned char>& data,
+                              int len, int freq, int format ) :
     _absolute_pos(SGVec3d::zeros()),
     _relative_pos(SGVec3d::zeros()),
     _direction(SGVec3d::zeros()),
@@ -122,7 +125,8 @@ SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format
     _orientation(SGQuatd::zeros()),
     _orivec(SGVec3f::zeros()),
     _base_pos(SGGeod()),
-    _data(data),
+    _refname(random_string()),
+    _data(data.release()),
     _format(format),
     _size(len),
     _freq(freq),
@@ -144,7 +148,6 @@ SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format
     _static_changed(true),
     _is_file(false)
 {
-    _refname = "unknown, data supplied by caller";
     SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" );
 }
 
@@ -182,8 +185,16 @@ void SGSoundSample::update_absolute_position() {
     _orivec = -toVec3f(orient.rotate(_direction));
 
      orient = SGQuatd::fromRealImag(0, _relative_pos) * _orientation;
-    _absolute_pos = -SGVec3d::fromGeod(_base_pos) -orient.rotate(SGVec3d::e1());
+    _absolute_pos = -SGVec3d::fromGeod(_base_pos); // -orient.rotate(SGVec3d::e1());
+}
+
+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)] );
+      }
 
-    float vel = length(_velocity);
-    _velocity = toVec3d(_orivec * vel);
+      return rstr;
 }