nCine::AudioBuffer class

Fully decoded OpenAL audio buffer.

Holds an entire sound effect decoded into memory. Inherits from Object so a single buffer can be shared by multiple AudioBufferPlayer instances.

Base classes

class Object
Base class of all nCine objects.

Public types

enum class Format { Mono8, Stereo8, Mono16, Stereo16 }
Sample format.

Public static functions

static auto sType() -> ObjectType
Returns the static object type of this class.

Constructors, destructors, conversion operators

AudioBuffer()
Creates an empty OpenAL buffer.
AudioBuffer(StringView filename) explicit
Creates a buffer and loads it from the specified file.
AudioBuffer(std::unique_ptr<Death::IO::Stream> fileHandle, StringView filename)
Creates a buffer and loads it from an already opened stream.
~AudioBuffer() override
AudioBuffer(const AudioBuffer&) deleted
AudioBuffer(AudioBuffer&& other) noexcept

Public functions

auto operator=(const AudioBuffer&) -> AudioBuffer& deleted
auto operator=(AudioBuffer&& other) -> AudioBuffer& noexcept
void init(Format format, std::int32_t frequency)
Initializes an empty buffer with the specified format and frequency.
auto loadFromFile(StringView filename) -> bool
Loads audio data from the specified file.
auto loadFromStream(std::unique_ptr<Death::IO::Stream> fileHandle, StringView filename) -> bool
Loads audio data from an already opened stream.
auto loadFromSamples(const unsigned char* bufferPtr, std::int32_t bufferSize) -> bool
Loads samples in raw PCM format from a memory buffer.
auto bufferId() const -> std::uint32_t
Returns the OpenAL buffer id.
auto bytesPerSample() const -> std::int32_t
Returns the number of bytes per sample.
auto numChannels() const -> std::int32_t
Returns the number of audio channels.
auto frequency() const -> std::int32_t
Returns the sample frequency.
auto numSamples() const -> std::int32_t
Returns the total number of samples.
auto duration() const -> float
Returns the duration in seconds.
auto bufferSize() const -> std::int32_t
Returns the size of the buffer in bytes.

Enum documentation

enum class nCine::AudioBuffer::Format

Sample format.

Enumerators
Mono8

8-bit, single channel

Stereo8

8-bit, two channels

Mono16

16-bit, single channel

Stereo16

16-bit, two channels