fSoundAroundC.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fSoundAroundC.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.BaseClasses"
  8. #pragma link "GLS.Cadencer"
  9. #pragma link "GLS.Coordinates"
  10. #pragma link "GLS.GeomObjects"
  11. #pragma link "GLS.Objects"
  12. #pragma link "GLS.Scene"
  13. #pragma link "GLS.SoundManager"
  14. #pragma link "GLS.SceneViewer"
  15. #pragma link "GLS.FileWAV"
  16. #pragma link "GLS.FileMP3"
  17. #pragma link "GLS.Sounds.BASS"
  18. #pragma link "GLS.Sounds.FMOD"
  19. #pragma link "GLS.Sounds.OpenAL"
  20. #pragma resource "*.dfm"
  21. TForm1* Form1;
  22. int mx, my;
  23. //---------------------------------------------------------------------------
  24. __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {}
  25. //---------------------------------------------------------------------------
  26. void __fastcall TForm1::FormCreate(TObject* Sender)
  27. {
  28. TFileName Path = GetCurrentAssetPath() + "\\audio";
  29. SetCurrentDir(Path);
  30. // Load our sound samples
  31. GLSoundLibrary->Samples->AddFile("drumloop.wav", "drumloop.wav");
  32. GLSoundLibrary->Samples->AddFile("chimes.wav", "chimes.wav");
  33. GLSoundLibrary->Samples->AddFile("howl.mp3", "howl.mp3");
  34. }
  35. //---------------------------------------------------------------------------
  36. void __fastcall TForm1::SphereProgress(
  37. TObject* Sender, const double deltaTime, const double newTime)
  38. {
  39. Single alpha;
  40. // Move the red sphere (sound source) along an elliptic path
  41. alpha = 60 * DegToRad(newTime);
  42. ((TGLSphere*)Sender)
  43. ->Position->SetPoint(sin(alpha) * 2, 0.5, cos(alpha) * 5);
  44. }
  45. //---------------------------------------------------------------------------
  46. void __fastcall TForm1::TrackBar1Change(TObject* Sender)
  47. {
  48. // Move the listener forward/back
  49. Mickey->Position->Z = TrackBar1->Position / 10;
  50. Application->ProcessMessages();
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TForm1::TrackBarChange(TObject* Sender)
  54. {
  55. // Rotate the listener around the vertical axis
  56. DummyCube->TurnAngle = TrackBar->Position;
  57. Application->ProcessMessages();
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TForm1::Button1Click(TObject* Sender)
  61. {
  62. TGLBSoundEmitter* se = new TGLBSoundEmitter(Sphere->Behaviours);
  63. se->Source->SoundLibrary = GLSoundLibrary;
  64. se->Source->SoundName = "chimes.wav";
  65. se->Playing = True;
  66. }
  67. //---------------------------------------------------------------------------
  68. void __fastcall TForm1::btnHowlClick(TObject* Sender)
  69. {
  70. TGLBSoundEmitter* se = new TGLBSoundEmitter(Sphere->Behaviours);
  71. se->Source->SoundLibrary = GLSoundLibrary;
  72. se->Source->SoundName = "howl.mp3";
  73. se->Playing = True;
  74. }
  75. //---------------------------------------------------------------------------
  76. void __fastcall TForm1::TimerTimer(TObject* Sender)
  77. {
  78. String mngName;
  79. TGLSoundManager* sm;
  80. sm = ActiveSoundManager();
  81. // some stats
  82. if (dynamic_cast<TGLSMBASS*>(sm))
  83. mngName = "BASS";
  84. else if (dynamic_cast<TGLSMFMOD*>(sm))
  85. mngName = "FMOD";
  86. else if (dynamic_cast<TGLSMOpenAL*>(sm))
  87. mngName = "OpenAL";
  88. else
  89. mngName = "";
  90. if (sm)
  91. LabelFPS->Caption = Format("%.2f FPS, %s CPU use : %.2f%%",
  92. ARRAYOFCONST((GLSceneViewer->FramesPerSecond(), mngName,
  93. ActiveSoundManager()->CPUUsagePercent())));
  94. else
  95. LabelFPS->Caption = "No active sound manager.";
  96. GLSceneViewer->ResetPerformanceMonitor();
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TForm1::RBFMODClick(TObject* Sender)
  100. {
  101. TGLSoundManager *newManager, *sm;
  102. // This method switches managers. On a real world project, this would never
  103. // happen: you would choose and API and then cling to it, but the GLSS
  104. // completely wraps the underlying complexity and makes it a snap
  105. if (RBFMOD->Checked)
  106. newManager = GLSMFMOD;
  107. else
  108. newManager = GLSMBASS;
  109. sm = ActiveSoundManager();
  110. if (newManager != sm) {
  111. // shut down current one, and activate the new one
  112. if (sm) {
  113. sm->Active = False;
  114. newManager->Active = True;
  115. // restart sound
  116. GetOrCreateSoundEmitter(Sphere)->Playing = True;
  117. }
  118. }
  119. }
  120. //---------------------------------------------------------------------------
  121. void __fastcall TForm1::GLSceneViewerMouseMove(
  122. TObject* Sender, TShiftState Shift, int X, int Y)
  123. {
  124. if (Shift.Contains(ssLeft))
  125. GLCamera1->MoveAroundTarget(my - Y, mx - X);
  126. else if (Shift.Contains(ssRight))
  127. GLCamera1->AdjustDistanceToTarget(1 + (my - Y) * 0.01);
  128. mx = X;
  129. my = Y;
  130. }
  131. //---------------------------------------------------------------------------
  132. void __fastcall TForm1::GLSceneViewerMouseDown(
  133. TObject* Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  134. {
  135. mx = X;
  136. my = Y;
  137. }
  138. //---------------------------------------------------------------------------