Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Audio::Test Namespace Reference

Classes

class  EngParticleListener
 

Functions

void initSceneManager ()
 
void clearScene ()
 
void smTick ()
 
void smQuickTick ()
 
void testRendererless ()
 
void testSimpleScene ()
 
void testSimpleSceneWTemplates (const std::string &abtplName, const std::string &beamtplName)
 
void testSimpleSceneWDynTemplates ()
 
void testSimpleSceneWFileTemplates ()
 
void testComplexScene (bool doppler)
 
void testStreaming ()
 
void testMultiStreaming ()
 
void testMultiStreaming2 ()
 
void initALRenderer ()
 
void closeRenderer ()
 
int main (int argc, char **argv)
 

Function Documentation

void Audio::Test::clearScene ( )

Definition at line 44 of file test.cpp.

References Audio::SceneManager::destroyScene(), and Audio::SceneManager::getSceneIterator().

Referenced by testComplexScene(), testMultiStreaming(), testMultiStreaming2(), testRendererless(), testSimpleScene(), testSimpleSceneWTemplates(), and testStreaming().

45  {
46  cerr << " Clearing Scene" << endl;
47 
48  SceneManager *sm = SceneManager::getSingleton();
49  for (SharedPtr<SceneManager::SceneIterator> it = sm->getSceneIterator(); !it->eos();) {
50  string sceneName = it->get()->getName();
51  cerr << " destroying \"" << sceneName.c_str() << "\"" << flush;
52  it->next();
53  cerr << "..." << flush;
54  sm->destroyScene(sceneName);
55  cerr << "done" << endl;
56  }
57 
58  if (!sm->getSceneIterator()->eos())
59  throw Exception("WTF: SceneManager has scenes after clearing them all?");
60 
61  }
void Audio::Test::closeRenderer ( )

Definition at line 732 of file test.cpp.

733  {
734  cerr << "Shutting down renderer..." << endl;
735  SceneManager::getSingleton()->setRenderer( SharedPtr<Renderer>() );
736  }
void Audio::Test::initALRenderer ( )

Definition at line 721 of file test.cpp.

References Audio::SceneManager::setRenderer().

722  {
723  cerr << " Initializing renderer..." << endl;
724  SceneManager *sm = SceneManager::getSingleton();
725 
726  SharedPtr<Renderer> renderer(new OpenALRenderer);
727  renderer->setOutputFormat( Format(44100,16,2) );
728 
729  sm->setRenderer( renderer );
730  }
void Audio::Test::initSceneManager ( )

Definition at line 30 of file test.cpp.

31  {
32  cerr << "Creating scene manager..." << flush;
33  new SceneManager();
34 
35  cerr << "Creating template manager..." << flush;
36  new TemplateManager();
37 
38  if (SceneManager::getSingleton() == 0)
39  throw Exception("Singleton null after SceneManager instantiation");
40 
41  cerr << "OK" << endl;
42  }
int Audio::Test::main ( int  argc,
char **  argv 
)

Definition at line 738 of file test.cpp.

References closeRenderer(), e, initALRenderer(), initSceneManager(), testComplexScene(), testMultiStreaming(), testMultiStreaming2(), testRendererless(), testSimpleScene(), testSimpleSceneWDynTemplates(), testSimpleSceneWFileTemplates(), testStreaming(), and Audio::Exception::what().

Referenced by readCommandLineOptions().

739  {
740  int rv = 0;
741  try {
743 
744  // Rendererless tests
745  cerr << "Running rendererless tests..." << endl;
747 
748  // Rendererful tests
749  cerr << "Running rendererful tests..." << endl;
750  initALRenderer();
751  testRendererless(); // <-- whatever worked without renderer must work again with it
752  testSimpleScene();
753  testSimpleScene(); // Test replay ability
756 
757  // Now more complex scenes...
758  testComplexScene(false);
759  testComplexScene(false); // Test replay ability
760  testComplexScene(true);
761 
762  // Streaming tests
763  testStreaming();
766 
767  // Tidy close
768  closeRenderer();
769 
770  } catch(Exception e) {
771  cerr << "Uncaught exception: "
772  << e.what()
773  << endl;
774  rv = 1;
775  };
776  if (rv)
777  cout << "FAILED" << endl;
778  return rv;
779  }
void Audio::Test::smQuickTick ( )

Definition at line 70 of file test.cpp.

References Audio::sleep().

Referenced by testComplexScene().

71  {
72  SceneManager::getSingleton()->commit();
73  sleep(10);
74  }
void Audio::Test::smTick ( )

Definition at line 63 of file test.cpp.

References Audio::sleep().

Referenced by testComplexScene(), testMultiStreaming(), testMultiStreaming2(), testSimpleScene(), testSimpleSceneWTemplates(), and testStreaming().

64  {
65  cerr << "t" << flush;
66  SceneManager::getSingleton()->commit();
67  sleep(100);
68  }
void Audio::Test::testComplexScene ( bool  doppler)

Definition at line 318 of file test.cpp.

References clearScene(), UniverseUtil::cos(), Audio::SceneManager::createScene(), Audio::SceneManager::createSource(), Audio::getRealTime(), Audio::SceneManager::getRenderer(), Audio::SceneManager::getScene(), i, M_PI, StarSystemGent::radii, Audio::SceneManager::setMaxDistance(), Audio::SceneManager::setMaxSources(), Audio::SceneManager::setSceneActive(), UniverseUtil::sin(), smQuickTick(), smTick(), and speed.

Referenced by main().

319  {
320  cerr << " Complex scene" << endl;
321 
322  clearScene();
323 
324  int i;
325  double t;
326 
327  SceneManager *sm = SceneManager::getSingleton();
328 
329  // Create (and verify that) the test scene set
330  SharedPtr<Scene> cpscene = sm->createScene("testSceneCP");
331  sm->getScene("testSceneCP");
332  sm->setSceneActive("testSceneCP",true);
333 
334  SharedPtr<Scene> spcscene = sm->createScene("testSceneSPC");
335  sm->getScene("testSceneSPC");
336  sm->setSceneActive("testSceneSPC",true);
337 
338  // Complex test scene:
339  // 1. A looping, afterburner source at the back,
340  // in the cockpit.
341  // 2. A set of random fire-and-forget cockpit sounds
342  // (beeps of various sorts)
343  // 3. Numerous random fire-and-forget, low-volume
344  // explosions (in space)
345  // 4. A fleet of listener-driven engine sounds
346  // with parametric flight paths.
347  // 5. The cockpit listener is fixed
348  // 6. The space listener moves around the scene,
349  // which is bigger than the maximum activation
350  // distance (forcing sources on/off)
351 
352  const size_t nengs = 100;
353  const double worldsize = 500.0;
354 
355  // Set scene manager settings for test
356  sm->setMaxSources(10);
357  sm->setMaxDistance(worldsize/4);
358  sm->getRenderer()->setDopplerFactor(doppler ? 0.25 : 0.0);
359  sm->getRenderer()->setMeterDistance(1.0);
360 
361 
362  cerr << " Creating resources" << endl;
363  cerr << " looking up templates..." << flush;
364  SharedPtr<SourceTemplate> abtpl = TemplateManager::getSingleton()->getSourceTemplate(
365  "test.sources:afterburner");
366  SharedPtr<SourceTemplate> engtpl = TemplateManager::getSingleton()->getSourceTemplate(
367  "test.sources:engine");
368  SharedPtr<SourceTemplate> engexpl = TemplateManager::getSingleton()->getSourceTemplate(
369  "test.sources:explosion");
370  cerr << " ok" << endl;
371 
372  cerr << " setting up CP listener..." << flush;
373  cpscene->getListener().setOrientation( Vector3(0,0,1), Vector3(0,1,0) );
374  cpscene->getListener().setPosition( LVector3(0,0,0) );
375  cerr << " ok" << endl;
376 
377  cerr << " setting up SPC listener..." << flush;
378  spcscene->getListener().setOrientation( Vector3(0,0,1), Vector3(0,1,0) );
379  spcscene->getListener().setPosition( LVector3(0,0,0) );
380  cerr << " ok" << endl;
381 
382  cerr << " creating looping sources..." << flush;
383 
384  SharedPtr<Source> absource = sm->createSource(abtpl);
385  absource->setPosition(Vector3(0,0,-1));
386  cpscene->add(absource);
387 
388  vector<SharedPtr<Source> > engsources;
389  vector<LVector3> engpaths; // x=phase, y=speed, z=wobble
390 
391  // Fill in engpaths
392  SharedPtr<SourceListener> englistener(
393  new EngParticleListener(engpaths,worldsize) );
394 
395 
396  {
397  const double phase_step = 2.0 * M_PI / nengs;
398  for (size_t i = 0; i < nengs; ++i) {
399  double phase = i * phase_step;
400  double speed = 2.0 * phase_step * ( double(rand() + RAND_MAX/2) / RAND_MAX );
401  double radii = worldsize * ( 1.0 + 0.25 * double(rand() - RAND_MAX/2) / RAND_MAX );
402 
403  engpaths.push_back(LVector3(phase, speed, radii));
404 
405  SharedPtr<Source> src = sm->createSource(engtpl);
406  src->setUserDataLong(i);
407  src->setSourceListener(englistener);
408  engsources.push_back(src);
409 
410  spcscene->add(src);
411  }
412  }
413 
414 
415  cerr << " ok" << endl;
416 
417  cerr << " playing out scene..." << flush;
418 
419  absource->setGain(0.01);
420  absource->startPlaying();
421 
422  {
423  for (vector<SharedPtr<Source> >::iterator i = engsources.begin(); i != engsources.end(); ++i)
424  (*i)->startPlaying();
425  }
426 
427  for (t=getRealTime(); (getRealTime()-t) < 20.0; ) { // 20s = 200 ticks
428  const double phase_step = 2.0 * M_PI / 20;
429  double phase = (getRealTime()-t) * phase_step;
430  double speed = phase_step;
431 
432  LVector3 pos = LVector3(
433  cos(phase) * worldsize,
434  -sin(phase) * worldsize,
435  0
436  );
437 
438  LVector3 dpos = LVector3(
439  -sin(phase) * worldsize * speed,
440  -cos(phase) * worldsize * speed,
441  0
442  );
443 
444  spcscene->getListener().setOrientation( dpos, Vector3(0,1,0) );
445  spcscene->getListener().setPosition( pos );
446 
447  dynamic_cast<EngParticleListener*>(englistener.get())->time = (getRealTime()-t) / 20.0;
448 
449  smQuickTick();
450  }
451 
452  absource->stopPlaying();
453  { for (vector<SharedPtr<Source> >::iterator i = engsources.begin(); i != engsources.end(); ++i)
454  (*i)->stopPlaying(); }
455 
456  for (i=0; i<10; ++i) // 1s = 10 ticks
457  smTick();
458 
459  cerr << " ok" << endl;
460  }
void Audio::Test::testMultiStreaming ( )

Definition at line 536 of file test.cpp.

References clearScene(), Audio::SceneManager::createScene(), Audio::SceneManager::createSource(), f, Audio::getRealTime(), Audio::SceneManager::getRenderer(), Audio::SceneManager::getScene(), i, int, VSFileSystem::MusicFile, realTime(), Audio::SceneManager::setSceneActive(), and smTick().

Referenced by main().

537  {
538  cerr << " Multiple streaming (stream two music tracks)" << endl;
539 
540  clearScene();
541 
542  int i;
543  double timeDelta = 0.0;
544 
545  SceneManager *sm = SceneManager::getSingleton();
546 
547  // Create (and verify that) a test scene
548  SharedPtr<Scene> scene = sm->createScene("testScene");
549  sm->getScene("testScene");
550  sm->setSceneActive("testScene",true);
551 
552  // Multi streaming test scene:
553  // 1. Two streaming music tracks playing simultaneously
554  cerr << " Creating resources" << endl;
555  cerr << " creating sounds..." << flush;
556  SharedPtr<Sound> music = sm->getRenderer()->getSound(
557  "AyMambo.ogg", VSFileSystem::MusicFile, true);
558  SharedPtr<Sound> music2 = sm->getRenderer()->getSound(
559  "Bliss.ogg", VSFileSystem::MusicFile, true);
560  cerr << " ok" << endl;
561  cerr << " loading sounds..." << flush;
562  music->load();
563  music2->load();
564  cerr << " ok" << endl;
565 
566  cerr << " setting up listener..." << flush;
567  scene->getListener().setOrientation( Vector3(0,0,1), Vector3(0,1,0) );
568  scene->getListener().setPosition( LVector3(0,0,0) );
569  cerr << " ok" << endl;
570 
571  cerr << " creating sources..." << flush;
572 
573  SharedPtr<Source> musicsource = sm->createSource(music);
574  musicsource->setPosition(Vector3(0,0,0));
575  musicsource->setGain(1.0f);
576  musicsource->setAttenuated(false);
577  musicsource->setRelative(true);
578 
579  SharedPtr<Source> musicsource2 = sm->createSource(music2);
580  musicsource2->setPosition(Vector3(0,0,0));
581  musicsource2->setGain(1.0f);
582  musicsource2->setAttenuated(false);
583  musicsource2->setRelative(true);
584 
585  scene->add(musicsource);
586  scene->add(musicsource2);
587 
588  cerr << " ok" << endl;
589 
590  cerr << " playing out scene..." << flush;
591 
592  double startPlayingTime = getRealTime();
593  musicsource->startPlaying();
594  musicsource2->startPlaying();
595  for (i=0; i<200; ++i) { // 20s = 200 ticks
596  smTick();
597 
598  // Track drift
599  double realTime = getRealTime();
600  double curPlayingTime = musicsource->getPlayingTime();
601  double shouldPlayingTime = realTime - startPlayingTime;
602  double delta = fabs(curPlayingTime - shouldPlayingTime);
603  if (delta > timeDelta)
604  timeDelta = delta;
605 
606  // Resync supposed start time to account for systematic
607  // drift (which isn't that bad, and quite normal in fact)
608  startPlayingTime = realTime - curPlayingTime;
609 
610  cerr << "Time delta: " << int(delta * 1000) << "ms (max " << int(timeDelta * 1000) << "ms)\t\r" << flush;
611  }
612 
613  musicsource->stopPlaying();
614  for (i=0; i<50; ++i) // 5s = 50 ticks
615  smTick();
616 
617  musicsource2->stopPlaying();
618  for (i=0; i<10; ++i) // 1s = 10 ticks
619  smTick();
620 
621  if (timeDelta > (1.0 / 30.0))
622  cerr << "\nWARNING: Poor time tracking resolution\n";
623  cerr << " Time drift at " << int(timeDelta*1000) << "ms" << endl;
624 
625  cerr << " ok" << endl;
626  }
void Audio::Test::testMultiStreaming2 ( )

Definition at line 628 of file test.cpp.

References clearScene(), Audio::SceneManager::createScene(), Audio::SceneManager::createSource(), f, Audio::getRealTime(), Audio::SceneManager::getRenderer(), Audio::SceneManager::getScene(), i, int, VSFileSystem::MusicFile, realTime(), Audio::SceneManager::setSceneActive(), and smTick().

Referenced by main().

629  {
630  cerr << " Multiple streaming (stream one music track - twice - from different positions)" << endl;
631 
632  clearScene();
633 
634  int i;
635  double timeDelta = 0.0;
636 
637  SceneManager *sm = SceneManager::getSingleton();
638 
639  // Create (and verify that) a test scene
640  SharedPtr<Scene> scene = sm->createScene("testScene");
641  sm->getScene("testScene");
642  sm->setSceneActive("testScene",true);
643 
644  // Multi streaming test scene:
645  // 1. Two streaming music tracks playing simultaneously
646  cerr << " Creating resources" << endl;
647  cerr << " creating sounds..." << flush;
648  SharedPtr<Sound> music = sm->getRenderer()->getSound(
649  "SonOfSandFleaRemix.ogg", VSFileSystem::MusicFile, true);
650  SharedPtr<Sound> music2 = sm->getRenderer()->getSound(
651  "SonOfSandFleaRemix.ogg", VSFileSystem::MusicFile, true);
652  cerr << " ok" << endl;
653  cerr << " loading sounds..." << flush;
654  music->load();
655  music2->load();
656  cerr << " ok" << endl;
657 
658  cerr << " setting up listener..." << flush;
659  scene->getListener().setOrientation( Vector3(0,0,1), Vector3(0,1,0) );
660  scene->getListener().setPosition( LVector3(0,0,0) );
661  cerr << " ok" << endl;
662 
663  cerr << " creating sources..." << flush;
664 
665  SharedPtr<Source> musicsource = sm->createSource(music);
666  musicsource->setPosition(Vector3(0,0,0));
667  musicsource->setGain(1.0f);
668  musicsource->setAttenuated(false);
669  musicsource->setRelative(true);
670 
671  SharedPtr<Source> musicsource2 = sm->createSource(music2);
672  musicsource2->setPosition(Vector3(0,0,0));
673  musicsource2->setGain(1.0f);
674  musicsource2->setAttenuated(false);
675  musicsource2->setRelative(true);
676 
677  scene->add(musicsource);
678  scene->add(musicsource2);
679 
680  cerr << " ok" << endl;
681 
682  cerr << " playing out scene..." << flush;
683 
684  double startPlayingTime = getRealTime();
685  musicsource->startPlaying();
686  musicsource2->startPlaying(60.0);
687  for (i=0; i<200; ++i) { // 20s = 200 ticks
688  smTick();
689 
690  // Track drift
691  double realTime = getRealTime();
692  double curPlayingTime = musicsource->getPlayingTime();
693  double shouldPlayingTime = realTime - startPlayingTime;
694  double delta = fabs(curPlayingTime - shouldPlayingTime);
695  if (delta > timeDelta)
696  timeDelta = delta;
697 
698  // Resync supposed start time to account for systematic
699  // drift (which isn't that bad, and quite normal in fact)
700  startPlayingTime = realTime - curPlayingTime;
701 
702  cerr << "Time delta: " << int(delta * 1000) << "ms (max " << int(timeDelta * 1000) << "ms)\t\r" << flush;
703  }
704 
705  musicsource->stopPlaying();
706  for (i=0; i<50; ++i) // 5s = 50 ticks
707  smTick();
708 
709  musicsource2->stopPlaying();
710  for (i=0; i<10; ++i) // 1s = 10 ticks
711  smTick();
712 
713  if (timeDelta > (1.0 / 30.0))
714  cerr << "\nWARNING: Poor time tracking resolution\n";
715  cerr << " Time drift at " << int(timeDelta*1000) << "ms" << endl;
716 
717  cerr << " ok" << endl;
718  }
void Audio::Test::testRendererless ( )

Definition at line 76 of file test.cpp.

References clearScene(), Audio::SceneManager::createScene(), Audio::SceneManager::getScene(), and Audio::SceneManager::setSceneActive().

Referenced by main().

77  {
78  // Test clearing and creating scenes repeatedly
79  // (tests management structures)
80  clearScene();
81 
82  SceneManager *sm = SceneManager::getSingleton();
83 
84  cerr << " Creating empty inactive scene" << endl;
85  sm->createScene("testScene");
86  sm->getScene("testScene");
87 
88  clearScene();
89 
90  cerr << " Creating empty active scene" << endl;
91  sm->createScene("testScene");
92  sm->getScene("testScene");
93  sm->setSceneActive("testScene",true);
94 
95  clearScene();
96  }
void Audio::Test::testSimpleScene ( )

Definition at line 98 of file test.cpp.

References clearScene(), Audio::SceneManager::createScene(), Audio::SceneManager::createSource(), f, Audio::SceneManager::getRenderer(), Audio::SceneManager::getScene(), i, Audio::SceneManager::setSceneActive(), smTick(), and VSFileSystem::SoundFile.

Referenced by main().

99  {
100  cerr << " Simple scene (low level services only)" << endl;
101 
102  clearScene();
103 
104  int i;
105 
106  SceneManager *sm = SceneManager::getSingleton();
107 
108  // Create (and verify that) a test scene
109  SharedPtr<Scene> scene = sm->createScene("testScene");
110  sm->getScene("testScene");
111  sm->setSceneActive("testScene",true);
112 
113  // Simple test scene:
114  // 1. A looping, afterburner source at the back.
115  // 2. A fire-and-forget beam sound to the left (4s)
116  // 3. A fire-and-forget beam sound to the right (8s)
117  // 4. Finish (16s)
118  cerr << " Creating resources" << endl;
119  cerr << " creating sounds..." << flush;
120  SharedPtr<Sound> absound = sm->getRenderer()->getSound("afterburner.wav", VSFileSystem::SoundFile);
121  SharedPtr<Sound> beamsound = sm->getRenderer()->getSound("beam.wav", VSFileSystem::SoundFile);
122  cerr << " ok" << endl;
123  cerr << " loading sounds..." << flush;
124  absound->load();
125  beamsound->load();
126  cerr << " ok" << endl;
127 
128  cerr << " setting up listener..." << flush;
129  scene->getListener().setOrientation( Vector3(0,0,1), Vector3(0,1,0) );
130  scene->getListener().setPosition( LVector3(0,0,0) );
131  cerr << " ok" << endl;
132 
133  cerr << " creating sources..." << flush;
134  SharedPtr<Source> absource = sm->createSource(absound, true);
135  SharedPtr<Source> beamsource1 = sm->createSource(beamsound);
136  SharedPtr<Source> beamsource2 = sm->createSource(beamsound);
137  absource->setPosition(Vector3(0,0,-1));
138  beamsource1->setPosition(Vector3(-1,0,0));
139  beamsource2->setPosition(Vector3(+1,0,0));
140  beamsource1->setGain(0.5f);
141  beamsource2->setGain(0.5f);
142  scene->add(absource);
143  scene->add(beamsource1);
144  scene->add(beamsource2);
145  cerr << " ok" << endl;
146 
147  cerr << " playing out scene..." << flush;
148 
149  absource->startPlaying();
150  for (i=0; i<40; ++i) // 4s = 40 ticks
151  smTick();
152 
153  beamsource1->startPlaying();
154  for (i=0; i<40; ++i) // 4s = 40 ticks
155  smTick();
156 
157  beamsource2->startPlaying();
158  for (i=0; i<80; ++i) // 8s = 80 ticks
159  smTick();
160 
161  absource->stopPlaying();
162  for (i=0; i<10; ++i) // 1s = 10 ticks
163  smTick();
164 
165  cerr << " ok" << endl;
166  }
void Audio::Test::testSimpleSceneWDynTemplates ( )

Definition at line 230 of file test.cpp.

References f, VSFileSystem::SoundFile, and testSimpleSceneWTemplates().

Referenced by main().

231  {
232  cerr << " Simple scene (dynamic templates)" << endl;
233 
234  SharedPtr<SourceTemplate> abtpl(
235  new SourceTemplate("afterburner.wav", VSFileSystem::SoundFile, true) );
236  SharedPtr<SourceTemplate> beamtpl(
237  new SourceTemplate("beam.wav", VSFileSystem::SoundFile, false) );
238  beamtpl->setGain(0.5f);
239 
240  TemplateManager::getSingleton()->addSourceTemplate("afterburner",abtpl,false);
241  TemplateManager::getSingleton()->addSourceTemplate("beam",beamtpl,false);
242 
243  testSimpleSceneWTemplates(":afterburner", ":beam");
244  }
void Audio::Test::testSimpleSceneWFileTemplates ( )

Definition at line 246 of file test.cpp.

References testSimpleSceneWTemplates().

Referenced by main().

247  {
248  cerr << " Simple scene (persistent templates)" << endl;
249  testSimpleSceneWTemplates("test.sources:afterburner", "test.sources:beam");
250  }
void Audio::Test::testSimpleSceneWTemplates ( const std::string &  abtplName,
const std::string &  beamtplName 
)

Definition at line 168 of file test.cpp.

References clearScene(), Audio::SceneManager::createScene(), Audio::SceneManager::createSource(), Audio::SceneManager::getScene(), i, Audio::SceneManager::playSource(), Audio::SceneManager::setSceneActive(), and smTick().

Referenced by testSimpleSceneWDynTemplates(), and testSimpleSceneWFileTemplates().

169  {
170  clearScene();
171 
172  int i;
173 
174  SceneManager *sm = SceneManager::getSingleton();
175 
176  // Create (and verify that) a test scene
177  SharedPtr<Scene> scene = sm->createScene("testScene");
178  sm->getScene("testScene");
179  sm->setSceneActive("testScene",true);
180 
181  // Simple test scene:
182  // 1. A looping, afterburner source at the back.
183  // 2. A fire-and-forget beam sound to the left (4s)
184  // 3. A fire-and-forget beam sound to the right (8s)
185  // 4. Finish (16s)
186  cerr << " Creating resources" << endl;
187  cerr << " looking up templates..." << flush;
188  SharedPtr<SourceTemplate> abtpl = TemplateManager::getSingleton()->getSourceTemplate(abtplName);
189  SharedPtr<SourceTemplate> beamtpl = TemplateManager::getSingleton()->getSourceTemplate(beamtplName);
190  cerr << " ok" << endl;
191 
192  cerr << " setting up listener..." << flush;
193  scene->getListener().setOrientation( Vector3(0,0,1), Vector3(0,1,0) );
194  scene->getListener().setPosition( LVector3(0,0,0) );
195  cerr << " ok" << endl;
196 
197  cerr << " creating looping sources..." << flush;
198  SharedPtr<Source> absource = sm->createSource(abtpl);
199  absource->setPosition(Vector3(0,0,-1));
200  scene->add(absource);
201  cerr << " ok" << endl;
202 
203  cerr << " playing out scene..." << flush;
204 
205  absource->startPlaying();
206  for (i=0; i<40; ++i) // 4s = 40 ticks
207  smTick();
208 
209  sm->playSource(beamtpl, "testScene",
210  LVector3(-1,0,0),
211  Vector3(0,0,1), Vector3(0,0,0),
212  1);
213  for (i=0; i<40; ++i) // 4s = 40 ticks
214  smTick();
215 
216  sm->playSource(beamtpl, "testScene",
217  LVector3(+1,0,0),
218  Vector3(0,0,1), Vector3(0,0,0),
219  1);
220  for (i=0; i<80; ++i) // 8s = 80 ticks
221  smTick();
222 
223  absource->stopPlaying();
224  for (i=0; i<10; ++i) // 1s = 10 ticks
225  smTick();
226 
227  cerr << " ok" << endl;
228  }
void Audio::Test::testStreaming ( )

Definition at line 462 of file test.cpp.

References clearScene(), Audio::SceneManager::createScene(), Audio::SceneManager::createSource(), f, Audio::getRealTime(), Audio::SceneManager::getRenderer(), Audio::SceneManager::getScene(), i, int, VSFileSystem::MusicFile, realTime(), Audio::SceneManager::setSceneActive(), and smTick().

Referenced by main().

463  {
464  cerr << " Simple streaming (stream a music track)" << endl;
465 
466  clearScene();
467 
468  int i;
469  double timeDelta = 0.0;
470 
471  SceneManager *sm = SceneManager::getSingleton();
472 
473  // Create (and verify that) a test scene
474  SharedPtr<Scene> scene = sm->createScene("testScene");
475  sm->getScene("testScene");
476  sm->setSceneActive("testScene",true);
477 
478  // Simple streaming test scene:
479  // 1. A streaming music track playing as usual
480  cerr << " Creating resources" << endl;
481  cerr << " creating sounds..." << flush;
482  SharedPtr<Sound> music = sm->getRenderer()->getSound(
483  "AyMambo.ogg", VSFileSystem::MusicFile, true);
484  cerr << " ok" << endl;
485  cerr << " loading sounds..." << flush;
486  music->load();
487  cerr << " ok" << endl;
488 
489  cerr << " setting up listener..." << flush;
490  scene->getListener().setOrientation( Vector3(0,0,1), Vector3(0,1,0) );
491  scene->getListener().setPosition( LVector3(0,0,0) );
492  cerr << " ok" << endl;
493 
494  cerr << " creating sources..." << flush;
495  SharedPtr<Source> musicsource = sm->createSource(music);
496  musicsource->setPosition(Vector3(0,0,0));
497  musicsource->setGain(1.0f);
498  musicsource->setAttenuated(false);
499  musicsource->setRelative(true);
500  scene->add(musicsource);
501  cerr << " ok" << endl;
502 
503  cerr << " playing out scene..." << flush;
504 
505  double startPlayingTime = getRealTime();
506  musicsource->startPlaying();
507  for (i=0; i<200; ++i) { // 20s = 200 ticks
508  smTick();
509 
510  // Track drift
511  double realTime = getRealTime();
512  double curPlayingTime = musicsource->getPlayingTime();
513  double shouldPlayingTime = realTime - startPlayingTime;
514  double delta = fabs(curPlayingTime - shouldPlayingTime);
515  if (delta > timeDelta)
516  timeDelta = delta;
517 
518  // Resync supposed start time to account for systematic
519  // drift (which isn't that bad, and quite normal in fact)
520  startPlayingTime = realTime - curPlayingTime;
521 
522  cerr << "Time delta: " << int(delta * 1000) << "ms (max " << int(timeDelta * 1000) << "ms)\t\r" << flush;
523  }
524 
525  musicsource->stopPlaying();
526  for (i=0; i<10; ++i) // 1s = 10 ticks
527  smTick();
528 
529  if (timeDelta > (1.0 / 30.0))
530  cerr << "\nWARNING: Poor time tracking resolution\n";
531  cerr << " Time drift at " << int(timeDelta*1000) << "ms" << endl;
532 
533  cerr << " ok" << endl;
534  }