vrj::SoundManagerSonix Class Reference

Enables VR Juggler to reconfigure the sonix sound interface. More...

#include <vrj/Sound/SoundManagerSonix.h>

Inheritance diagram for vrj::SoundManagerSonix:

Inheritance graph
[legend]
Collaboration diagram for vrj::SoundManagerSonix:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SoundManagerSonix ()
virtual bool configAdd (jccl::ConfigElementPtr element)
 Adds the element to the configuration.
virtual bool configRemove (jccl::ConfigElementPtr element)
 Removes the element from the current configuration.
virtual bool configCanHandle (jccl::ConfigElementPtr element)
 Can the handler handle the given element?
virtual void update ()
 Enables a frame to be drawn.
virtual void sync ()
 Blocks until the end of the frame.

Detailed Description

Enables VR Juggler to reconfigure the sonix sound interface.

Definition at line 46 of file SoundManagerSonix.h.


Constructor & Destructor Documentation

vrj::SoundManagerSonix::SoundManagerSonix (  ) 

Definition at line 44 of file SoundManagerSonix.cpp.

00045       : vrj::SoundManager()
00046       , mLastFrameTime(0, vpr::Interval::Sec)
00047    {
00048       /* Do nothing. */ ;
00049    }


Member Function Documentation

bool vrj::SoundManagerSonix::configAdd ( jccl::ConfigElementPtr  element  )  [virtual]

Adds the element to the configuration.

Precondition:
configCanHandle(element) == true

Reimplemented from vrj::SoundManager.

Definition at line 55 of file SoundManagerSonix.cpp.

References configCanHandle().

00056    {
00057       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00058          << "======================================\n" << vprDEBUG_FLUSH;
00059       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00060          << "SoundManagerSonix is being configured...\n" << vprDEBUG_FLUSH;
00061 
00062       if (!configCanHandle( element ))
00063       {
00064          std::cerr << "ERROR: Wrong element type in SoundManagerSonix\n"
00065                    << std::flush;
00066          return false;
00067       }
00068 
00069       std::string manager_name = element->getName();
00070       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL) << "My Name: " << manager_name
00071                                               << "\n" << vprDEBUG_FLUSH;
00072       std::string api_to_use = element->getProperty<std::string>( "api" );
00073       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL) << "Use API: " << api_to_use
00074                                               << "\n" << vprDEBUG_FLUSH;
00075 
00076       float listener_position[3];
00077       listener_position[0] = element->getProperty<float>("listener_position", 0);
00078       listener_position[1] = element->getProperty<float>("listener_position", 1);
00079       listener_position[2] = element->getProperty<float>("listener_position", 2);
00080       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00081          << "Listener Position: " << listener_position[0] << ","
00082          << listener_position[1] << "," << listener_position[2] << std::endl
00083          << vprDEBUG_FLUSH;
00084 
00085       std::vector<std::string> file_search_path(element->getNum("file_search_path"));
00086 
00087       for ( unsigned int i = 0; i < file_search_path.size(); ++i )
00088       {
00089          file_search_path[i] =
00090             vpr::replaceEnvVars(element->getProperty<std::string>("file_search_path", i));
00091       }
00092 
00093 //      vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00094 //         << "Search path: " << file_search_path << "\n" << vprDEBUG_FLUSH;
00095 
00096       // configure sonix
00097       snx::sonix::instance()->changeAPI(api_to_use);
00098       gmtl::Matrix44f mat;
00099       gmtl::setTrans( mat, gmtl::Vec3f( listener_position[0], listener_position[1], listener_position[2] ) );
00100       snx::sonix::instance()->setListenerPosition(mat);
00101 
00102       // read the list of sounds
00103       int size = element->getNum( "sound" );
00104       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL) << "Configuring " << size
00105                                               << " sounds.\n" << vprDEBUG_FLUSH;
00106       for (int x = 0; x < size; ++x)
00107       {
00108          jccl::ConfigElementPtr sound_element =
00109             element->getProperty<jccl::ConfigElementPtr>("sound", x);
00110          std::string alias = sound_element->getName();
00111          std::string filename = sound_element->getProperty<std::string>("filename");
00112          filename = vpr::replaceEnvVars( filename );
00113          bool ambient = sound_element->getProperty<bool>("ambient");
00114          bool retriggerable = sound_element->getProperty<bool>("retriggerable");
00115          bool streaming = sound_element->getProperty<bool>("streaming");
00116          int loop = sound_element->getProperty<int>("loop");
00117          float cutoff = sound_element->getProperty<float>("cutoff");
00118          float volume = sound_element->getProperty<float>("volume");
00119          float pitchbend = sound_element->getProperty<float>("pitch_bend");
00120          float position[3];
00121          position[0] = sound_element->getProperty<float>("position", 0);
00122          position[1] = sound_element->getProperty<float>("position", 1);
00123          position[2] = sound_element->getProperty<float>("position", 2);
00124 
00125          // configure the sound...
00126          snx::SoundInfo si;
00127          si.datasource = snx::SoundInfo::FILESYSTEM;
00128          si.filename = filename;
00129          si.cutoff = cutoff;
00130          si.volume = volume;
00131          si.pitchbend = pitchbend;
00132          si.repeat = loop;
00133          si.ambient = ambient;
00134          si.retriggerable = retriggerable;
00135          si.streaming = streaming;
00136          si.position[0] = position[0];
00137          si.position[1] = position[1];
00138          si.position[2] = position[2];
00139          vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00140             << "- Configuring " << alias << " (" << filename << ")\n"
00141             << vprDEBUG_FLUSH;
00142          vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL)
00143             << "  + pos(" << position[0] << "," << position[1] << ","
00144             << position[2] << ")," << "loop(" << loop << "),\n"
00145             << vprDEBUG_FLUSH;
00146          vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL)
00147             << "  + amb(" << ambient << ")," << "ct(" << cutoff << "),"
00148             << "vl(" << volume << "),\n" << vprDEBUG_FLUSH;
00149          vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL)
00150             << "  + freq(" << pitchbend << ")," << "retrig(" << retriggerable
00151             << ")\n" << vprDEBUG_FLUSH;
00152 
00153          snx::sonix::instance()->configure(alias, si);
00154       }
00155       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00156          << "======================================\n" << vprDEBUG_FLUSH;
00157 
00158       return true;
00159    }

bool vrj::SoundManagerSonix::configRemove ( jccl::ConfigElementPtr  element  )  [virtual]

Removes the element from the current configuration.

Precondition:
configCanHandle(element) == true

Reimplemented from vrj::SoundManager.

Definition at line 165 of file SoundManagerSonix.cpp.

00166    {
00167       // remove any specified sounds...
00168       int size = element->getNum("sound");
00169       for (int x = 0; x < size; ++x)
00170       {
00171          jccl::ConfigElementPtr sound_element =
00172             element->getProperty<jccl::ConfigElementPtr>("sound", x);
00173          std::string alias(sound_element->getName());
00174          snx::sonix::instance()->remove(alias);
00175       }
00176 
00177       return true;
00178    }

bool vrj::SoundManagerSonix::configCanHandle ( jccl::ConfigElementPtr  element  )  [virtual]

Can the handler handle the given element?

Returns:
true if we can handle it; false if not

Reimplemented from vrj::SoundManager.

Definition at line 184 of file SoundManagerSonix.cpp.

Referenced by configAdd().

00185    {
00186       return std::string("sound_manager_sonix") == element->getID();
00187    }

void vrj::SoundManagerSonix::update (  )  [virtual]

Enables a frame to be drawn.

Reimplemented from vrj::SoundManager.

Definition at line 190 of file SoundManagerSonix.cpp.

00191    {
00192       const vpr::Interval cur_time(vpr::Interval::now());
00193       const vpr::Interval delta(cur_time - mLastFrameTime);
00194       float delta_sec(0.0f);
00195 
00196       if ( cur_time > mLastFrameTime )
00197       {
00198          delta_sec = delta.secf();
00199 
00200          if ( delta_sec > 1.0f )
00201          {
00202             delta_sec = 1.0f;
00203          }
00204       }
00205 
00206       mLastFrameTime = cur_time;
00207 
00208       snx::sonix::instance()->step(delta_sec);
00209    }

void vrj::SoundManagerSonix::sync (  )  [virtual]

Blocks until the end of the frame.

Postcondition:
The frame has been rendered.

Reimplemented from vrj::SoundManager.

Definition at line 215 of file SoundManagerSonix.cpp.

00216    {
00217       // whatever...
00218    }


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:58:32 2007 for VR Juggler by  doxygen 1.5.1