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 {
00044 SoundManagerSonix::SoundManagerSonix()
00045 : vrj::SoundManager()
00046 , mLastFrameTime(0, vpr::Interval::Sec)
00047 {
00048 ;
00049 }
00050
00055 bool SoundManagerSonix::configAdd(jccl::ConfigElementPtr element)
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
00094
00095
00096
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
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
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 }
00160
00165 bool SoundManagerSonix::configRemove(jccl::ConfigElementPtr element)
00166 {
00167
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 }
00179
00184 bool SoundManagerSonix::configCanHandle(jccl::ConfigElementPtr element)
00185 {
00186 return std::string("sound_manager_sonix") == element->getID();
00187 }
00188
00190 void SoundManagerSonix::update()
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 }
00210
00215 void SoundManagerSonix::sync()
00216 {
00217
00218 }
00219
00220 }