| | 192 | void |
| | 193 | SoundTests::testSoundSourceMotion() |
| | 194 | { |
| | 195 | Zen::Engine::Sound::I_SoundManager::config_type soundConfig; |
| | 196 | Zen::Engine::Resource::I_ResourceManager::config_type resourceConfig; |
| | 197 | |
| | 198 | Zen::Engine::Sound::I_SoundManager::pService_type pSoundService = |
| | 199 | Zen::Engine::Sound::I_SoundManager::getSingleton() |
| | 200 | .create("ZOpenAL", soundConfig); |
| | 201 | |
| | 202 | CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE( |
| | 203 | "Sound service was not loaded.", |
| | 204 | CPPUNIT_ASSERT(pSoundService.isValid()) |
| | 205 | ); |
| | 206 | |
| | 207 | Zen::Engine::Resource::I_ResourceManager::pResourceService_type pResourceService = |
| | 208 | Zen::Engine::Resource::I_ResourceManager::getSingleton() |
| | 209 | .create("ZOpenAL", resourceConfig); |
| | 210 | |
| | 211 | CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE( |
| | 212 | "Sound resource service was not loaded.", |
| | 213 | CPPUNIT_ASSERT(pResourceService.isValid()) |
| | 214 | ); |
| | 215 | |
| | 216 | pResourceService->addResourceLocation("Engine/resources/sound", "", "", true); |
| | 217 | |
| | 218 | resourceConfig["fileName"] = "thunder.wav"; |
| | 219 | |
| | 220 | typedef Zen::Memory::managed_ptr<Zen::Engine::Sound::I_SoundResource> pSoundResource_type; |
| | 221 | pSoundResource_type pSoundResource = |
| | 222 | pResourceService |
| | 223 | ->loadResource(resourceConfig) |
| | 224 | .as<pSoundResource_type>(); |
| | 225 | |
| | 226 | CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE( |
| | 227 | "Sound resource was not loaded.", |
| | 228 | CPPUNIT_ASSERT(pSoundResource.isValid()) |
| | 229 | ); |
| | 230 | |
| | 231 | Zen::Engine::Sound::I_SoundSource::pSoundSource_type pSound = |
| | 232 | pSoundService->createSource(pSoundResource,Zen::Math::Point3(100.0f,0.0f,0.0f)); |
| | 233 | |
| | 234 | char input(' '); |
| | 235 | while(input != 'Y' && input != 'N' && input != 'y' && input != 'n') |
| | 236 | { |
| | 237 | std::cout << "\n Unit Test - SoundTests::testSoundSourceMotion() : Is thunder playing to your right? (Y/N) : "; |
| | 238 | std::cin.get(input); |
| | 239 | } |
| | 240 | pSound->setPosition(Zen::Math::Point3(-100.0f,0.0f,0.0f)); |
| | 241 | pSound->stop(); |
| | 242 | pSound->play(); |
| | 243 | |
| | 244 | input = ' '; |
| | 245 | while(input != 'Y' && input != 'N' && input != 'y' && input != 'n') |
| | 246 | { |
| | 247 | std::cout << "\n Unit Test - SoundTests::testSoundSourceMotion() : Is thunder playing to your left? (Y/N) : "; |
| | 248 | std::cin.get(input); |
| | 249 | } |
| | 250 | pSound->stop(); |
| | 251 | CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE( |
| | 252 | "Sound source is not playing through the sound card.", |
| | 253 | CPPUNIT_ASSERT(input == 'Y' || input == 'y') |
| | 254 | ); |
| | 255 | } |
| | 256 | |
| | 257 | //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ |
| | 258 | void |
| | 259 | SoundTests::testListenerMotion() |
| | 260 | { |
| | 261 | Zen::Engine::Sound::I_SoundManager::config_type soundConfig; |
| | 262 | Zen::Engine::Resource::I_ResourceManager::config_type resourceConfig; |
| | 263 | |
| | 264 | Zen::Engine::Sound::I_SoundManager::pService_type pSoundService = |
| | 265 | Zen::Engine::Sound::I_SoundManager::getSingleton() |
| | 266 | .create("ZOpenAL", soundConfig); |
| | 267 | |
| | 268 | CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE( |
| | 269 | "Sound service was not loaded.", |
| | 270 | CPPUNIT_ASSERT(pSoundService.isValid()) |
| | 271 | ); |
| | 272 | |
| | 273 | Zen::Engine::Resource::I_ResourceManager::pResourceService_type pResourceService = |
| | 274 | Zen::Engine::Resource::I_ResourceManager::getSingleton() |
| | 275 | .create("ZOpenAL", resourceConfig); |
| | 276 | |
| | 277 | CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE( |
| | 278 | "Sound resource service was not loaded.", |
| | 279 | CPPUNIT_ASSERT(pResourceService.isValid()) |
| | 280 | ); |
| | 281 | |
| | 282 | pResourceService->addResourceLocation("Engine/resources/sound", "", "", true); |
| | 283 | |
| | 284 | resourceConfig["fileName"] = "thunder.wav"; |
| | 285 | |
| | 286 | typedef Zen::Memory::managed_ptr<Zen::Engine::Sound::I_SoundResource> pSoundResource_type; |
| | 287 | pSoundResource_type pSoundResource = |
| | 288 | pResourceService |
| | 289 | ->loadResource(resourceConfig) |
| | 290 | .as<pSoundResource_type>(); |
| | 291 | |
| | 292 | CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE( |
| | 293 | "Sound resource was not loaded.", |
| | 294 | CPPUNIT_ASSERT(pSoundResource.isValid()) |
| | 295 | ); |
| | 296 | |
| | 297 | Zen::Engine::Sound::I_SoundSource::pSoundSource_type pSound = |
| | 298 | pSoundService->createSource(pSoundResource,Zen::Math::Point3(0.0f,0.0f,0.0f)); |
| | 299 | |
| | 300 | Math::Matrix4 yourLocation; |
| | 301 | yourLocation = pSoundService->getListenMatrix(); |
| | 302 | Math::Point3 pos; |
| | 303 | yourLocation.getPosition(pos); |
| | 304 | std::cout << "\n Position was:" << boost::int32_t(pos.m_x) << "," << boost::int32_t(pos.m_y) << "," << boost::int32_t(pos.m_z); |
| | 305 | pos = Math::Point3(100.0f,0.0f,0.0f); |
| | 306 | yourLocation.setPosition(pos); |
| | 307 | pSoundService->setListenMatrix(yourLocation); |
| | 308 | yourLocation.getPosition(pos); |
| | 309 | std::cout << "and is now" << boost::int32_t(pos.m_x) << "," << boost::int32_t(pos.m_y) << "," << boost::int32_t(pos.m_z); |
| | 310 | pSound->play(); |
| | 311 | pSound->setLooping(true); |
| | 312 | |
| | 313 | char input(' '); |
| | 314 | while(input != 'Y' && input != 'N' && input != 'y' && input != 'n') |
| | 315 | { |
| | 316 | std::cout << "\n Unit Test - SoundTests::testSoundSourceMotion() : Is thunder playing to your right? (Y/N) : "; |
| | 317 | std::cin.get(input); |
| | 318 | } |
| | 319 | |
| | 320 | pos = Math::Point3(-100.0f,0.0f,0.0f); |
| | 321 | yourLocation.setPosition(pos); |
| | 322 | pSoundService->setListenMatrix(yourLocation); |
| | 323 | pSoundService->processEvents(); |
| | 324 | |
| | 325 | input = ' '; |
| | 326 | while(input != 'Y' && input != 'N' && input != 'y' && input != 'n') |
| | 327 | { |
| | 328 | std::cout << "/n Unit Test - SoundTests::testSoundSourceMotion() : Is thunder playing to your left? (Y/N) : "; |
| | 329 | std::cin.get(input); |
| | 330 | } |
| | 331 | |
| | 332 | CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE( |
| | 333 | "Sound source is not playing through the sound card.", |
| | 334 | CPPUNIT_ASSERT(input == 'Y' || input == 'y') |
| | 335 | ); |
| | 336 | } |
| | 337 | //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ |