PrevUpHomeNext

Chapter 4. Introduction

Table of Contents

Hello world

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; 1

	oalplus::ContextMadeCurrent context(device); 2

	oalplus::ALUtilityToolkit alut(false, argc, argv); 3

	oalplus::Listener listener; 4
	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(); 5

	oalplus::Source source; 6
	source.Buffer(buffer);
	source.Position(0.0f, 0.0f,-1.0f);

	source.Play(); 7
	
	std::chrono::seconds duration(2);
	std::this_thread::sleep_for(duration); 8

	return 0;
}

1

Creates a wrapper for and opens the default audio device.

2

Creates a context using the device wrapper and makes it current.

3

Creates an instance of a wrapper of the ALUT library.

4

Creates a listener and sets its position, velocity and orientation.

5

Creates a Hello World sound and stores it into a buffer.

6

Create an audio source from the data in buffer and sets its position.

7

Makes the source play the queued sound.

8

Waits for a couple of seconds before exitting.


PrevUpHomeNext