Revision: 7281
http://playerstage.svn.sourceforge.net/playerstage/?rev=7281&view=rev
Author: natepak
Date: 2009-01-20 05:39:31 +0000 (Tue, 20 Jan 2009)
Log Message:
-----------
Update to the openal implementation
Modified Paths:
--------------
code/gazebo/trunk/SConstruct
code/gazebo/trunk/server/World.cc
code/gazebo/trunk/server/audio_video/OpenAL.cc
code/gazebo/trunk/server/audio_video/OpenAL.hh
code/gazebo/trunk/server/audio_video/SConscript
Modified: code/gazebo/trunk/SConstruct
===================================================================
--- code/gazebo/trunk/SConstruct 2009-01-18 01:56:16 UTC (rev 7280)
+++ code/gazebo/trunk/SConstruct 2009-01-20 05:39:31 UTC (rev 7281)
@@ -58,12 +58,13 @@
'#server/controllers/position2d',
'#server/controllers/position2d/pioneer2dx',
'#server/controllers/irarray',
+ '#server/audio_video',
],
- LIBPATH=Split('#libgazebo'),
+ LIBPATH=Split('#libgazebo #server/audio_video'),
#LIBS=Split('gazebo boost_python')
- LIBS=Split('gazebo boost_signals'),
+ LIBS=Split('gazebo gazeboav boost_signals'),
LINKFLAGS=Split('-export-dynamic'),
TARFLAGS = '-c -z',
Modified: code/gazebo/trunk/server/World.cc
===================================================================
--- code/gazebo/trunk/server/World.cc 2009-01-18 01:56:16 UTC (rev 7280)
+++ code/gazebo/trunk/server/World.cc 2009-01-20 05:39:31 UTC (rev 7281)
@@ -38,6 +38,7 @@
#include "Simulator.hh"
#include "gazebo.h"
#include "World.hh"
+#include "OpenAL.hh"
#include "Geom.hh"
using namespace gazebo;
@@ -170,8 +171,12 @@
(*miter)->Init();
}
+ // Initialize the physics engine
this->physicsEngine->Init();
+ // Initialize openal
+ OpenAL::Instance()->Init();
+
this->toAddModels.clear();
this->toDeleteModels.clear();
@@ -219,6 +224,9 @@
this->toDeleteModels.clear();
+ // Update the audio
+ OpenAL::Instance()->Update();
+
return 0;
}
Modified: code/gazebo/trunk/server/audio_video/OpenAL.cc
===================================================================
--- code/gazebo/trunk/server/audio_video/OpenAL.cc 2009-01-18 01:56:16 UTC
(rev 7280)
+++ code/gazebo/trunk/server/audio_video/OpenAL.cc 2009-01-20 05:39:31 UTC
(rev 7281)
@@ -2,32 +2,37 @@
#include <unistd.h>
#include <iostream>
-#include <AL/alut.h>
+#ifdef ENABLE_OPENAL
#include <AL/alc.h>
+#endif
+#include "GazeboError.hh"
+#include "GazeboMessage.hh"
#include "AudioDecoder.hh"
#include "OpenAL.hh"
-#ifndef NULL
-#define NULL 0
-#endif
+using namespace gazebo;
-
////////////////////////////////////////////////////////////////////////////////
///// Constructor
OpenAL::OpenAL()
{
+#ifdef ENABLE_OPENAL
+ printf("CONSTRUCTOR!!!!|\n\n\n");
this->context = NULL;
this->audioDevice = NULL;
this->pos[0] = this->pos[1] = this->pos[2] = 0.0;
this->pos[0] = -10.0;
+#endif
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor
OpenAL::~OpenAL()
{
+
+#ifdef ENABLE_OPENAL
if (this->context && this->audioDevice)
{
this->context = alcGetCurrentContext();
@@ -36,6 +41,7 @@
alcDestroyContext(this->context);
alcCloseDevice(this->audioDevice);
}
+#endif
this->sources.clear();
this->buffers.clear();
@@ -45,8 +51,11 @@
/// Initialize
int OpenAL::Init()
{
+#ifdef ENABLE_OPENAL
+
// Open the default audio device
this->audioDevice = alcOpenDevice("ALSA Software on HDA Intel");
+
if (this->audioDevice == NULL)
{
printf("Unable to open audio device\n");
@@ -59,6 +68,7 @@
//Clear error code
alGetError();
+#endif
// TODO: put in function to set distance model
//alDistanceModel(AL_EXPONENT_DISTANCE);
@@ -69,6 +79,15 @@
/// Create a sound source
unsigned int OpenAL::CreateSource()
{
+#ifdef ENABLE_OPENAL
+
+ // Make sure we have an audio device
+ if (!this->audioDevice)
+ {
+ gzerr(0) << "Audio device not open\n";
+ return -1;
+ }
+
unsigned int source;
//Create 1 source
@@ -76,17 +95,30 @@
this->sources.push_back(source);
+#endif
+
return this->sources.size()-1;
+
}
////////////////////////////////////////////////////////////////////////////////
/// Create an audio data buffer
unsigned int OpenAL::CreateBuffer(const std::string &audioFile)
{
+
+#ifdef ENABLE_OPENAL
+
unsigned int buffer;
uint8_t *dataBuffer = NULL;
unsigned int dataBufferSize;
+ // Make sure we have an audio device
+ if (!this->audioDevice)
+ {
+ gzerr(0) << "Audio device not open\n";
+ return -1;
+ }
+
// Create an audio decoder
AudioDecoder audioDecoder;
@@ -106,6 +138,7 @@
if (dataBuffer)
delete [] dataBuffer;
+#endif
return this->buffers.size()-1;
}
@@ -115,9 +148,18 @@
/// Update all the sources and the listener
void OpenAL::Update()
{
+#ifdef ENABLE_OPENAL
+
//ALfloat pos[3];
ALfloat vel[3];
+ // Make sure we have an audio device
+ if (!this->audioDevice)
+ {
+ gzerr(10) << "Audio device not open\n";
+ return;
+ }
+
//for (int i=0; i< this->sourceCount; i++)
{
@@ -135,12 +177,22 @@
//printf("p[%f %f %f] v[%f %f %f]\n", pos[0], pos[1], pos[2], vel[0],
vel[1], vel[2]);
this->SetSourcePos(0, this->pos[0], this->pos[1], this->pos[2] );
}
+#endif
}
////////////////////////////////////////////////////////////////////////////////
/// Set the data
int OpenAL::SetData(unsigned int index, uint8_t *data, unsigned int dataSize,
unsigned int freq)
{
+#ifdef ENABLE_OPENAL
+
+ // Make sure we have an audio device
+ if (!this->audioDevice)
+ {
+ gzerr(0) << "Audio device not open\n";
+ return -1;
+ }
+
// Clear the error buffer;
alGetError();
@@ -158,8 +210,7 @@
alDeleteBuffers(1, &this->buffers[index]);
return -1;
}
-
-
+#endif
return 0;
}
@@ -167,6 +218,15 @@
/// \brief Attach a buffer to a source
int OpenAL::SetSourceBuffer(unsigned int sourceIndex, unsigned int bufferIndex)
{
+#ifdef ENABLE_OPENAL
+
+ // Make sure we have an audio device
+ if (!this->audioDevice)
+ {
+ gzerr(0) << "Audio device not open\n";
+ return -1;
+ }
+
if (sourceIndex >= this->sources.size())
{
std::cerr << "Invalid source index\n";
@@ -190,6 +250,7 @@
return -1;
}
+#endif
return 0;
}
@@ -198,6 +259,15 @@
// Play the source
void OpenAL::Play( unsigned int index )
{
+#ifdef ENABLE_OPENAL
+
+ // Make sure we have an audio device
+ if (!this->audioDevice)
+ {
+ gzerr(0) << "Audio device not open\n";
+ return;
+ }
+
// Play the source
alSourcePlay( this->sources[index] );
@@ -210,13 +280,22 @@
alGetSourcei(this->sources[index], AL_SOURCE_STATE, &state);
} while ( state == AL_PLAYING);
*/
-
+#endif
}
////////////////////////////////////////////////////////////////////////////////
/// Set the listener position
int OpenAL::SetListenerPos( float x, float y, float z )
{
+#ifdef ENABLE_OPENAL
+
+ // Make sure we have an audio device
+ if (!this->audioDevice)
+ {
+ gzerr(0) << "Audio device not open\n";
+ return -1;
+ }
+
// Clear error state
alGetError();
@@ -227,7 +306,7 @@
std::cerr << "OpenAL SetListenerPos Error: [%d]\n" << this->error << "\n";
return -1;
}
-
+#endif
return 0;
}
@@ -235,6 +314,15 @@
/// Set the listener velocity
int OpenAL::SetListenerVel( float x, float y, float z )
{
+#ifdef ENABLE_OPENAL
+
+ // Make sure we have an audio device
+ if (!this->audioDevice)
+ {
+ gzerr(0) << "Audio device not open\n";
+ return -1;
+ }
+
// Clear error state
alGetError();
@@ -244,7 +332,7 @@
std::cerr << "OpenAL SetListenerVel Error: [%d]" << this->error << "\n";
return -1;
}
-
+#endif
return 0;
}
@@ -253,8 +341,16 @@
int OpenAL::SetListenerOrient( float cx, float cy, float cz,
float ux, float uy, float uz )
{
+#ifdef ENABLE_OPENAL
ALfloat orient[]={cx, cy, cz, ux, uy, uz};
+ // Make sure we have an audio device
+ if (!this->audioDevice)
+ {
+ gzerr(0) << "Audio device not open\n";
+ return -1;
+ }
+
// Clear error state
alGetError();
@@ -265,7 +361,7 @@
std::cerr << "OpenAL SetListenerOrientation Error: [%d]" << this->error <<
"\n";
return -1;
}
-
+#endif
return 0;
}
@@ -273,8 +369,16 @@
// Set the position of the source
int OpenAL::SetSourcePos(unsigned int index, float x, float y, float z)
{
+#ifdef ENABLE_OPENAL
ALfloat p[3] = {x, y, z};
+ // Make sure we have an audio device
+ if (!this->audioDevice)
+ {
+ gzerr(0) << "Audio device not open\n";
+ return -1;
+ }
+
if (index >= this->sources.size())
{
std::cerr << "Invalid source index[" << index <<" ]\n";
@@ -291,7 +395,7 @@
std::cerr << "OpenAL::SetSourcePos Error: [%d]" << this->error << "\n";
return -1;
}
-
+#endif
return 0;
}
@@ -299,8 +403,17 @@
// Set the position of the source
int OpenAL::SetSourceVel(unsigned int index, float x, float y, float z)
{
+#ifdef ENABLE_OPENAL
ALfloat v[3] = {x, y, z};
+ // Make sure we have an audio device
+ if (!this->audioDevice)
+ {
+ gzerr(0) << "Audio device not open\n";
+ return -1;
+ }
+
+
if (index >= this->sources.size())
{
std::cerr << "Invalid source index[" << index <<" ]\n";
@@ -317,7 +430,7 @@
std::cerr << "OpenAL::SetSourceVel Error: [%d]" << this->error << "\n";
return -1;
}
-
+#endif
return 0;
}
@@ -325,6 +438,16 @@
// Set the pitch of the source
int OpenAL::SetSourcePitch(unsigned int index, float p)
{
+
+#ifdef ENABLE_OPENAL
+
+ // Make sure we have an audio device
+ if (!this->audioDevice)
+ {
+ gzerr(0) << "Audio device not open\n";
+ return -1;
+ }
+
if (index >= this->sources.size())
{
std::cerr << "Invalid source index[" << index <<" ]\n";
@@ -341,7 +464,7 @@
std::cerr << "OpenAL::SetSourcePitch Error: [%d]\n" << this->error;
return -1;
}
-
+#endif
return 0;
}
@@ -349,6 +472,16 @@
// Set the pitch of the source
int OpenAL::SetSourceGain(unsigned int index, float g)
{
+#ifdef ENABLE_OPENAL
+
+ // Make sure we have an audio device
+ if (!this->audioDevice)
+ {
+ gzerr(0) << "Audio device not open\n";
+ return -1;
+ }
+
+
if (index >= this->sources.size())
{
std::cerr << "Invalid source index[" << index <<" ]\n";
@@ -365,7 +498,7 @@
std::cerr << "OpenAL::SetSourceGain Error: [%d]\n" << this->error;
return -1;
}
-
+#endif
return 0;
}
@@ -373,6 +506,16 @@
// Set whether the source loops the audio
int OpenAL::SetSourceLoop(unsigned int index, bool state)
{
+#ifdef ENABLE_OPENAL
+
+ // Make sure we have an audio device
+ if (!this->audioDevice)
+ {
+ gzerr(0) << "Audio device not open\n";
+ return -1;
+ }
+
+
if (index >= this->sources.size())
{
std::cerr << "Invalid source index[" << index <<" ]\n";
@@ -390,7 +533,7 @@
std::cerr << "OpenAL::SetSourceLoop Error: [%d]\n" << this->error << "\n";
return -1;
}
+#endif
-
return 0;
}
Modified: code/gazebo/trunk/server/audio_video/OpenAL.hh
===================================================================
--- code/gazebo/trunk/server/audio_video/OpenAL.hh 2009-01-18 01:56:16 UTC
(rev 7280)
+++ code/gazebo/trunk/server/audio_video/OpenAL.hh 2009-01-20 05:39:31 UTC
(rev 7281)
@@ -1,81 +1,95 @@
#ifndef OPENAL_HH
#define OPENAL_HH
+#ifndef DISABLE_OPENAL
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/alext.h>
+#endif
+
#include <stdint.h>
#include <deque>
+#include "SingletonT.hh"
-class OpenAL
+namespace gazebo
{
- /// \brief Constructor
- public: OpenAL();
+
+ class OpenAL : public SingletonT<OpenAL>
+ {
+ /// \brief Constructor
+ private: OpenAL();
+
+ /// \brief Destructor
+ private: virtual ~OpenAL();
+
+ /// \brief Initialize
+ public: int Init();
+
+ /// \brief Update all the sources and the listener
+ public: void Update();
+
+ /// \brief Create a sound source
+ public: unsigned int CreateSource();
+
+ /// \brief Create an audio data buffer
+ public: unsigned int CreateBuffer(const std::string &audioFile);
+
+ /// \brief Set the data
+ public: int SetData(unsigned int index, uint8_t *data, unsigned int
dataSize, unsigned int freq);
+
+ /// \brief Attach a buffer to a source
+ public: int SetSourceBuffer(unsigned int sourceIndex, unsigned int
bufferIndex);
+
+ /// \brief Play a sound
+ public: void Play(unsigned int source);
+
+ /// \brief Set the listener position
+ public: int SetListenerPos( float x, float y, float z );
+
+ /// \brief Set the listener velocity
+ public: int SetListenerVel( float x, float y, float z );
+
+ /// \brief Set the listener orientation
+ public: int SetListenerOrient(float cx, float cy, float cz,
+ float ux, float uy, float uz);
+
+ /// \brief Set the position of the source
+ public: int SetSourcePos(unsigned int index, float x, float y, float z);
+
+ /// \brief Set the position of the source
+ public: int SetSourceVel(unsigned int index, float x, float y, float z);
+
+ /// \brief Set the pitch of the source
+ public: int SetSourcePitch(unsigned int index, float p);
+
+ /// \brief Set the pitch of the source
+ public: int SetSourceGain(unsigned int index, float g);
+
+ /// \brief Set whether the source loops the audio
+ public: int SetSourceLoop(unsigned int index, bool state);
- /// \brief Destructor
- public: virtual ~OpenAL();
+#ifndef DISABLE_OPENAL
+ private: ALCcontext *context;
+ private: ALCdevice *audioDevice;
+
+ private: ALfloat pos[3];
- /// \brief Initialize
- public: int Init();
+ // OpenAL error code
+ private: ALenum error;
+#endif
- /// \brief Update all the sources and the listener
- public: void Update();
+ // Audio sources.
+ private: std::deque<unsigned int> sources;
+
+ // Audio data buffers
+ private: std::deque<unsigned int> buffers;
+
+ private: friend class DestroyerT<OpenAL>;
+ private: friend class SingletonT<OpenAL>;
+ };
+
+}
- /// \brief Create a sound source
- public: unsigned int CreateSource();
-
- /// \brief Create an audio data buffer
- public: unsigned int CreateBuffer(const std::string &audioFile);
-
- /// \brief Set the data
- public: int SetData(unsigned int index, uint8_t *data, unsigned int
dataSize, unsigned int freq);
-
- /// \brief Attach a buffer to a source
- public: int SetSourceBuffer(unsigned int sourceIndex, unsigned int
bufferIndex);
-
- /// \brief Play a sound
- public: void Play(unsigned int source);
-
- /// \brief Set the listener position
- public: int SetListenerPos( float x, float y, float z );
-
- /// \brief Set the listener velocity
- public: int SetListenerVel( float x, float y, float z );
-
- /// \brief Set the listener orientation
- public: int SetListenerOrient(float cx, float cy, float cz,
- float ux, float uy, float uz);
-
- /// \brief Set the position of the source
- public: int SetSourcePos(unsigned int index, float x, float y, float z);
-
- /// \brief Set the position of the source
- public: int SetSourceVel(unsigned int index, float x, float y, float z);
-
- /// \brief Set the pitch of the source
- public: int SetSourcePitch(unsigned int index, float p);
-
- /// \brief Set the pitch of the source
- public: int SetSourceGain(unsigned int index, float g);
-
- /// \brief Set whether the source loops the audio
- public: int SetSourceLoop(unsigned int index, bool state);
-
- private: ALCcontext *context;
- private: ALCdevice *audioDevice;
-
- // OpenAL error code
- private: ALenum error;
-
- // Audio sources.
- private: std::deque<unsigned int> sources;
-
- // Audio data buffers
- private: std::deque<unsigned int> buffers;
-
- private: ALfloat pos[3];
-};
-
#endif
Modified: code/gazebo/trunk/server/audio_video/SConscript
===================================================================
--- code/gazebo/trunk/server/audio_video/SConscript 2009-01-18 01:56:16 UTC
(rev 7280)
+++ code/gazebo/trunk/server/audio_video/SConscript 2009-01-20 05:39:31 UTC
(rev 7281)
@@ -1,11 +1,10 @@
#Import variable
-Import('env sharedObjs headers')
+Import('env sharedObjs headers install_prefix')
parseConfigs = [
'pkg-config --cflags --libs libavformat',
'pkg-config --cflags --libs libavcodec',
- 'pkg-config --cflags --libs openal',
- 'pkg-config --cflags --libs freealut'
+ 'pkg-config --cflags --libs openal'
]
myEnv = env.Clone()
@@ -18,6 +17,10 @@
['server/audio_video/AudioDecoder.hh',
'server/audio_video/OpenAL.hh',
] )
+
+enable_openal = 1
+
+
#
# Parse all the pacakge configurations
#
@@ -32,10 +35,17 @@
if cfg.find("OpenAL") >= 0:
print "OpenAL not found. 3D audio is disabled."
print " http://connect.creativelabs.com/"
- Exit(1)
+ enable_openal = 0
if cfg.find("avcodec") >= 0 or cfg.find("avformat") >= 0:
print "FFMpeg not found. Audio decoding disabled."
print " http://ffmpeg.mplayerhq.hu/"
- Exit(1)
+ enable_openal = 0
-myEnv.SharedLibrary('gazeboav', sources)
+conf = Configure(myEnv)
+if conf.CheckLib('openal'):
+ conf.env.Append(CCFLAGS = " -DENABLE_OPENAL")
+myEnv = conf.Finish()
+
+sharedLib = myEnv.SharedLibrary('gazeboav', sources)
+myEnv.Install(install_prefix+'/lib', sharedLib)
+
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit