Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

SoundManagerSonix.cpp

Go to the documentation of this file.
00001 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00002  *
00003  * VR Juggler is (C) Copyright 1998-2003 by Iowa State University
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Christopher Just,
00007  *   Patrick Hartling, Kevin Meinert,
00008  *   Carolina Cruz-Neira, Albert Baker
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Library General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Library General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Library General Public
00021  * License along with this library; if not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023  * Boston, MA 02111-1307, USA.
00024  *
00025  * -----------------------------------------------------------------
00026  * File:          $RCSfile: SoundManagerSonix.cpp,v $
00027  * Date modified: $Date: 2004/04/05 03:05:59 $
00028  * Version:       $Revision: 1.16 $
00029  * -----------------------------------------------------------------
00030  *
00031  *************** <auto-copyright.pl END do not edit this line> ***************/
00032 
00033 #include <vrj/vrjConfig.h>
00034 #include <gmtl/Matrix.h>
00035 #include <gmtl/Generate.h>
00036 #include <snx/sonix.h>
00037 #include <vpr/Util/Debug.h>
00038 #include <vpr/Util/FileUtils.h> // for replaceEnvVars...
00039 #include <jccl/Config/ConfigElement.h>
00040 #include <vrj/Sound/SoundManagerSonix.h>
00041 
00042 namespace vrj
00043 {
00048    bool SoundManagerSonix::configAdd(jccl::ConfigElementPtr element)
00049    {
00050       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00051          << "======================================\n" << vprDEBUG_FLUSH;
00052       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00053          << "SoundManagerSonix is being configured...\n" << vprDEBUG_FLUSH;
00054 
00055       if (!configCanHandle( element ))
00056       {
00057          std::cerr << "ERROR: Wrong element type in SoundManagerSonix\n"
00058                    << std::flush;
00059          return false;
00060       }
00061 
00062       std::string manager_name = element->getName();
00063       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL) << "My Name: " << manager_name
00064                                               << "\n" << vprDEBUG_FLUSH;
00065       std::string api_to_use = element->getProperty<std::string>( "api" );
00066       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL) << "Use API: " << api_to_use
00067                                               << "\n" << vprDEBUG_FLUSH;
00068       float listener_position[3];
00069       listener_position[0] = (float)element->getProperty<float>( "listener_position", 0 );
00070       listener_position[1] = (float)element->getProperty<float>( "listener_position", 1 );
00071       listener_position[2] = (float)element->getProperty<float>( "listener_position", 2 );
00072       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00073          << "Listener Position: " << listener_position[0] << ","
00074          << listener_position[1] << "," << listener_position[2] << "\n" << vprDEBUG_FLUSH;
00075       std::string file_search_path = element->getProperty<std::string>( "file_search_path" );
00076       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00077          << "Search path: " << file_search_path << "\n" << vprDEBUG_FLUSH;
00078 
00079       // configure sonix
00080       sonix::instance()->changeAPI( api_to_use );
00081       gmtl::Matrix44f mat;
00082       gmtl::setTrans( mat, gmtl::Vec3f( listener_position[0], listener_position[1], listener_position[2] ) );
00083       sonix::instance()->setListenerPosition( mat );
00084 
00085       // read the list of sounds
00086       int size = element->getNum( "sound" );
00087       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL) << "Configuring " << size
00088                                               << " sounds.\n" << vprDEBUG_FLUSH;
00089       for (int x = 0; x < size; ++x)
00090       {
00091          jccl::ConfigElementPtr sound_element =
00092             element->getProperty<jccl::ConfigElementPtr>("sound", x);
00093          std::string alias = sound_element->getName();
00094          std::string filename = sound_element->getProperty<std::string>("filename");
00095          filename = vpr::replaceEnvVars( filename );
00096          bool ambient = sound_element->getProperty<bool>("ambient");
00097          bool retriggerable = sound_element->getProperty<bool>("retriggerable");
00098          int loop = sound_element->getProperty<int>("loop");
00099          float cutoff = sound_element->getProperty<float>("cutoff");
00100          float volume = sound_element->getProperty<float>("volume");
00101          float pitchbend = sound_element->getProperty<float>("pitch_bend");
00102          float position[3];
00103          position[0] = sound_element->getProperty<float>("position", 0);
00104          position[1] = sound_element->getProperty<float>("position", 1);
00105          position[2] = sound_element->getProperty<float>("position", 2);
00106 
00107          // configure the sound...
00108          snx::SoundInfo si;
00109          si.datasource = snx::SoundInfo::FILESYSTEM;
00110          si.filename = filename;
00111          si.cutoff = cutoff;
00112          si.volume = volume;
00113          si.pitchbend = pitchbend;
00114          si.repeat = loop;
00115          si.ambient = ambient;
00116          si.retriggerable = retriggerable;
00117          si.position[0] = position[0];
00118          si.position[1] = position[1];
00119          si.position[2] = position[2];
00120          vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00121             << "- Configuring " << alias << " (" << filename << ")\n"
00122             << vprDEBUG_FLUSH;
00123          vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL)
00124             << "  + pos(" << position[0] << "," << position[1] << ","
00125             << position[2] << ")," << "loop(" << loop << "),\n"
00126             << vprDEBUG_FLUSH;
00127          vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL)
00128             << "  + amb(" << ambient << ")," << "ct(" << cutoff << "),"
00129             << "vl(" << volume << "),\n" << vprDEBUG_FLUSH;
00130          vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL)
00131             << "  + freq(" << pitchbend << ")," << "retrig(" << retriggerable
00132             << ")\n" << vprDEBUG_FLUSH;
00133 
00134          sonix::instance()->configure( alias, si );
00135       }
00136       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00137          << "======================================\n" << vprDEBUG_FLUSH;
00138 
00139       return true;
00140    }
00141 
00146    bool SoundManagerSonix::configRemove(jccl::ConfigElementPtr element)
00147    {
00148       // remove any specified sounds...
00149       int size = element->getNum("sound");
00150       for (int x = 0; x < size; ++x)
00151       {
00152          jccl::ConfigElementPtr sound_element =
00153             element->getProperty<jccl::ConfigElementPtr>("sound", x);
00154          std::string alias(sound_element->getName());
00155          sonix::instance()->remove(alias);
00156       }
00157 
00158       return true;
00159    }
00160 
00165    bool SoundManagerSonix::configCanHandle(jccl::ConfigElementPtr element)
00166    {
00167       const std::string element_type(element->getID());
00168       if(std::string("sound_manager") == element_type)
00169       {
00170          return true;
00171       }
00172       else
00173       {
00174          return false;
00175       }
00176    }
00177 
00179    void SoundManagerSonix::update()
00180    {
00181       float time_delta = 0.1f; // TODO: get real time since last frame...
00182       sonix::instance()->step( time_delta );
00183    }
00184 
00189    void SoundManagerSonix::sync()
00190    {
00191       // whatever...
00192    }
00193 
00194 } // end namespace

Generated on Sun May 2 15:10:17 2004 for VR Juggler by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002