Table of Contents
OALplus is a header-only library which implements a thin object-oriented facade over the OpenAL® C-language API. It provides wrappers which automate resource and object management and make the use of OpenAL in C++ safer and easier.
The following code shows a basic, working example of usage of the OALplus library.
#include <oalplus/al.hpp> #include <oalplus/all.hpp> #include <oalplus/alut.hpp> #include <chrono> #include <thread> int main(int argc, char** argv) { oalplus::Device device;oalplus::ContextMadeCurrent context(device);
oalplus::ALUtilityToolkit alut(false, argc, argv);
oalplus::Listener listener;
listener.Position(0.0f, 0.0f, 0.0f); listener.Velocity(0.0f, 0.0f, 0.0f); listener.Orientation(0.0f, 0.0f,-1.0f, 0.0f, 1.0f, 0.0f); oalplus::Buffer buffer = alut.CreateBufferHelloWorld();
oalplus::Source source;
source.Buffer(buffer); source.Position(0.0f, 0.0f,-1.0f); source.Play();
std::chrono::seconds duration(2); std::this_thread::sleep_for(duration);
return 0; }
Creates a wrapper for and opens the default audio device. |
|
Creates a context using the device wrapper and makes it current. |
|
Creates an instance of a wrapper of the ALUT library. |
|
Creates a listener and sets its position, velocity and orientation. |
|
Creates a Hello World sound and stores it into a buffer. |
|
Create an audio source from the data in buffer and sets its position. |
|
Makes the source play the queued sound. |
|
Waits for a couple of seconds before exitting. |