00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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>
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
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
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
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
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;
00182 sonix::instance()->step( time_delta );
00183 }
00184
00189 void SoundManagerSonix::sync()
00190 {
00191
00192 }
00193
00194 }