diff options
author | Chris Robinson <[email protected]> | 2023-03-07 13:30:15 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-03-07 13:30:15 -0800 |
commit | ed6b8230bd1f4ac502ce4915d24fedacf3eceee0 (patch) | |
tree | c7766a230fc26a2322ebd472a8022286f544545b /al | |
parent | f11313c62dd6ab8666023e90dc6fbf3fc70cb1da (diff) |
Add queries for the buffer byte/sample/sec length
These used to exist with the now-defunct AL_SOFT_buffer_samples extension, this
just restores those queries without extra baggage.
The sample length query are necessary when handling ADPCM buffers, since the
size/channels*8/bits calculation is incorrect with ADPCM. 'Bits' is usually
reported as 4 since most samples in a block are stored as nibbles, but that's
only approximate and doesn't account for the block header. The average number
of bits per sample in an ADPCM block can't be represented as an integer, so the
more blocks there are stored in the buffer, the more inaccurate the calculation
becomes.
Diffstat (limited to 'al')
-rw-r--r-- | al/buffer.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/al/buffer.cpp b/al/buffer.cpp index 05657a2a..ae7bf0d9 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -1191,6 +1191,11 @@ START_API_FUNC context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { + case AL_SEC_LENGTH_SOFT: + *value = (albuf->mSampleRate < 1) ? 0.0f : + (static_cast<float>(albuf->mSampleLen) / static_cast<float>(albuf->mSampleRate)); + break; + default: context->setError(AL_INVALID_ENUM, "Invalid buffer float property 0x%04x", param); } @@ -1276,10 +1281,18 @@ START_API_FUNC break; case AL_SIZE: + *value = albuf->mCallback ? 0 : static_cast<ALint>(albuf->mData.size()); + break; + + case AL_BYTE_LENGTH_SOFT: *value = static_cast<ALint>(albuf->mSampleLen / albuf->mBlockAlign * albuf->blockSizeFromFmt()); break; + case AL_SAMPLE_LENGTH_SOFT: + *value = static_cast<ALint>(albuf->mSampleLen); + break; + case AL_UNPACK_BLOCK_ALIGNMENT_SOFT: *value = static_cast<ALint>(albuf->UnpackAlign); break; |