nCine::AudioBuffer class

Fully decoded audio buffer.

Holds an entire sound effect decoded into memory. Inherits from Object so a single buffer can be shared by multiple AudioBufferPlayer instances. The samples live in a buffer object owned by the current IAudioDevice, which on some backends means dedicated sound memory rather than the main heap.

Where NCINE_HAS_NATIVE_AUDIO is defined, nothing is decoded: loadFromFile() hands the file over to the device (see IAudioDevice::loadNativeBuffer()), which plays it by itself, and the functions that take encoded or raw samples do not exist.

Base classes

class Object
Base class of all nCine objects.

Public types

using Format = IAudioDevice::BufferFormat
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 buffer.
AudioBuffer(StringView filename) explicit
Creates a buffer and loads it from the specified file.
~AudioBuffer() override
AudioBuffer(const AudioBuffer&) deleted
AudioBuffer(AudioBuffer&& other) noexcept
AudioBuffer(std::unique_ptr<Death::IO::Stream> fileHandle, StringView filename)
Creates a buffer and loads it from an already opened stream.

Public functions

auto operator=(const AudioBuffer&) -> AudioBuffer& deleted
auto operator=(AudioBuffer&& other) -> AudioBuffer& noexcept
auto loadFromFile(StringView filename) -> bool
Loads audio data from the specified file.
void init(Format format, std::int32_t frequency)
Initializes an empty buffer with the specified format and frequency.
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 backend 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.