7#include <cgv/math/fvec.h>
8#include <cgv/math/fmat.h>
9#include <cgv/type/info/type_id.h>
15using ALuint =
unsigned int;
51 explicit OALContext(
const std::string& device_name);
77 void load_sample(std::string filepath, std::string symbolic_name =
"");
96 void load_sample(std::string symbolic_name,
const void*
data,
size_t data_length);
112 void load_samples(std::string folder,
bool recursive =
false);
173 ALCdevice* oal_device =
nullptr;
174 ALCcontext* oal_context =
nullptr;
177 std::map<std::string, ALuint> sample_buffers;
187class CGV_API OALListener final
190 OALListener() =
delete;
191 OALListener(
const OALListener& other) =
delete;
192 OALListener(OALListener&& other) =
delete;
193 OALListener& operator=(
const OALListener& other) =
delete;
194 OALListener& operator=(OALListener&& other) =
delete;
195 ~OALListener() =
delete;
254class CGV_API OALSource
257 OALSource() =
default;
258 OALSource(
const OALSource&) =
delete;
259 OALSource(OALSource&&) =
default;
260 OALSource& operator=(
const OALSource&) =
delete;
261 OALSource& operator=(OALSource&&) =
default;
409 bool append_sound_impl(std::string sound_name);
418#include <cgv/config/lib_end.h>
This class provides easy sample loading, device enumeration and error retrieval.
void load_samples(std::string folder, bool recursive=false)
Loads all audio files in a folder into the internal buffer list.
ALCdevice * get_native_device()
Gets the native device handle for direct OpenAL calls.
void make_current()
in case of multiple contexts, this makes this context current
std::string get_device_name() const
return device name of contexts device
static std::vector< std::string > enumerate_devices()
Enumerate audio output devices available on system.
std::string get_error_string()
Returns the last error from the OpenAL context.
static std::string get_default_device_name()
returns name of system's default device
static bool decode_sound_file(const void *data, size_t data_length, OALSoundFormat &format, std::vector< int16_t > &memory_buffer)
decode sound file that is already in memory data with data_length bytes to a newly constructed memory...
void create_buffer(const std::string &symbolic_name, const OALSoundFormat &format, const void *data, size_t data_length)
create a named sound buffer from a format descriptor and a data buffer of given length in bytes
void load_sample(std::string filepath, std::string symbolic_name="")
Loads a sound into the internal buffer list.
static bool load_sound_file(const std::string &filepath, OALSoundFormat &format, std::vector< int16_t > &memory_buffer)
load and decode sound file to newly constructed memory buffer
bool is_no_error()
Determines if there were any errors since last call.
void set_HRTF(bool active)
Toggles the OpenAL output mode to use HRTF.
OALContext(const std::string &device_name)
Construct context, connect to output device and make context current.
ALuint get_buffer_id(std::string sound_name) const
Gets the buffer identifier for the symbolic name.
ALCcontext * get_native_context()
Gets the native context handle for direct OpenAL calls.
static cgv::math::fvec< float, 3 > get_position()
Gets the listener position.
static cgv::math::fvec< float, 3 > get_velocity()
Gets the listener velocity.
static void set_position(cgv::math::fvec< float, 3 > pos)
Sets the listener position.
static void set_orientation(cgv::math::fvec< float, 3 > at, cgv::math::fvec< float, 3 > up)
Sets the listener orientation.
static cgv::math::fmat< float, 3, 2 > get_orientation()
Gets the listener orientation.
static void set_velocity(cgv::math::fvec< float, 3 > vel)
Sets the listener velocity.
void clear()
destruct source and restore uninitialized state
bool append_sound(std::string sound_name)
Append buffer of named sound to source's playback list.
void stop()
Stops the playback of the sound buffer and moves the playhead to the beginning.
void set_looping(bool should_loop)
Sets the looping property of the source.
void set_position(cgv::math::fvec< float, 3 > pos)
Sets the source position.
void play_pause(bool should_play)
Explicitly toggles between pausing and playing the sound buffer.
bool init(OALContext &ctx, std::string sound_name="")
This function links a source to a context.
void set_velocity(cgv::math::fvec< float, 3 > vel)
Sets the source velocity.
void play()
Commences the playback of the sound buffer.
void rewind()
Moves the playhead to the beginning of the buffer.
void pause()
Pauses the playback of the sound buffer without moving the playhead.
cgv::math::fvec< float, 3 > get_velocity() const
Gets the source velocity.
bool is_looping() const
Determines if the source has the looping property.
bool is_playing() const
Determines if the source is playing.
OALSourceState get_state() const
returns state of this source
float get_gain() const
Gets the source gain.
float get_pitch() const
Gets the source pitch.
cgv::math::fvec< float, 3 > get_position() const
Gets the source position.
void set_gain(float gain)
Sets the source gain.
void set_pitch(float pitch)
Sets the source pitch.
matrix of fixed size dimensions
A vector with zero based index.
namespace for data management components
this header is dependency free