Delphi

OpenAL

Tutorials

Lesson #6 (the object-oriented way)

Until now we did not use the thing that makes delphi (object-pascal) a great tool to use: Object-oriented programming.

Now it is even easier to use OpenAL. In the uses we need to add oooal, then:

  • in the form create event we need
    sound1:=TalObject.Create;
    sound1.LoadFromFile('ding.wav');
  • in the form destroy event we need
    if sound1.playing then sound1.Stop;
    sound1.destroy;
  • changing the position is as easy as:
    sound1.xpos:=5.0;
    sound1.zpos:=5.0;
    if sound1.playing then sound1.update;

For the time being we still need to init openal in the form create event and close it in the form destroy event. Also setting up the listener pos is still done in the form create event.

How things work inside oooal.pas is explained in the previous lessons. oooal.pas will be extended in the future lessons.

Take a look at the example. It shows how to play a single sound and how to change a looped sound's position realtime.