SoundOpenAL.dpr 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. {: 3D Sound sample (OpenAL manager is used in this sample).
  2. This sample has a moving red sound source with a looping sound, and a "mickey"
  3. listener that you can move around using the trackbars.
  4. You already know the TGLScene, TGLSceneViewer, the TTimer is just used for
  5. regularly updating the Form's caption with FPS and CPU usage stats. You also
  6. know the TGLCadencer, but here, it not only cadenced the scene, but is also
  7. referred and used by the TGLSMOpenAL sound manager.
  8. A TGLSoundLibrary is used to load and store the sample, a 44kHz WAV file. The
  9. sound library can be used to embed sound files in the application, you just
  10. have to add a sample at design-time and this removes the need for an external
  11. file, but for our samples, we share a single wav files among all demos.
  12. Sound libraries are used to store sound samples, you may only play a sample
  13. that is available in library (you can add/remove samples dynamically).
  14. We also have sound manager. There can only be one *active* sound manager in
  15. any app at any time, it serves as an interface to a low-level sound API.
  16. 3D sounds are dynamic things, the easiest way to achieve this is to connect
  17. the manager to the cadencer by setting its "Cadencer" property, this way,
  18. it will get updated regularly.
  19. And now, the last part : a sound emitter behaviour has been attached to the
  20. red sphere, in this behaviour we specify a sample (by selecting a sound
  21. library, and a sample in the sound library). The "NbLoops" property was also
  22. adjusted, to keep our sound looping (playing again and again).
  23. That's basicly all you need to use GLScene Sound System. Note however, that
  24. depending on the low-level API you chose (ie. sound manager), some features
  25. amy or may not be available, but you don't need to worry about that, if
  26. a feature is unavailable on a particular driver, it will just be ignored.
  27. For the sake of the demo, all three samples are using different formats,
  28. the APIs take care of the conversions: "drumloop.wav" is a 44kHz PCM,
  29. "howl.mp3" a 16kHz MP3, and "chimes.wav" a 22kHz PCM... All three files
  30. however are mono, because stereo sounds cannot go 3D... Remember that only
  31. 3D sounds are required to be mono, if you have some background music or ambient
  32. soundtrack, it can be stereo (use the Sound System API directly to play it).
  33. The OpenAL manager currently accepts only simple *uncompressed* WAV files
  34. (8/16 bits, mono/stereo), so you will need to convert files to these format
  35. before using it.
  36. }
  37. program SoundOpenAL;
  38. uses
  39. Forms,
  40. fSoundOpenAL in 'fSoundOpenAL.pas' {Form1};
  41. {$R *.RES}
  42. begin
  43. Application.Initialize;
  44. Application.CreateForm(TForm1, Form1);
  45. Application.Run;
  46. end.