aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-03-19 17:29:13 -0700
committerChris Robinson <[email protected]>2023-03-19 17:29:13 -0700
commitf53b31b2c14b6f35dcda8c33c880c2fa79fe0f4b (patch)
tree211c7554d8b75949c5d93404d37adffb45eaa642
parent186a29b77d8ec01c14d13797f9d51c7c21b22b60 (diff)
Simplify some samples-to-bytes conversions
-rw-r--r--al/source.cpp48
1 files changed, 8 insertions, 40 deletions
diff --git a/al/source.cpp b/al/source.cpp
index d30a7094..38e09476 100644
--- a/al/source.cpp
+++ b/al/source.cpp
@@ -334,29 +334,11 @@ double GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context)
break;
case AL_BYTE_OFFSET:
- if(BufferFmt->OriginalType == UserFmtIMA4)
- {
- ALuint FrameBlockSize{BufferFmt->mBlockAlign};
- ALuint align{(BufferFmt->mBlockAlign-1)/2 + 4};
- ALuint BlockSize{align * BufferFmt->channelsFromFmt()};
+ const ALuint BlockSamples{BufferFmt->mBlockAlign};
+ const ALuint BlockSize{BufferFmt->blockSizeFromFmt()};
- /* Round down to nearest ADPCM block */
- offset = static_cast<double>(readPos / FrameBlockSize * BlockSize);
- }
- else if(BufferFmt->OriginalType == UserFmtMSADPCM)
- {
- ALuint FrameBlockSize{BufferFmt->mBlockAlign};
- ALuint align{(FrameBlockSize-2)/2 + 7};
- ALuint BlockSize{align * BufferFmt->channelsFromFmt()};
-
- /* Round down to nearest ADPCM block */
- offset = static_cast<double>(readPos / FrameBlockSize * BlockSize);
- }
- else
- {
- const ALuint FrameSize{BufferFmt->frameSizeFromFmt()};
- offset = static_cast<double>(readPos * FrameSize);
- }
+ /* Round down to the block boundary. */
+ offset = static_cast<double>(readPos / BlockSamples) * BlockSize;
break;
}
return offset;
@@ -390,25 +372,11 @@ double GetSourceLength(const ALsource *source, ALenum name)
return static_cast<double>(length);
case AL_BYTE_LENGTH_SOFT:
- if(BufferFmt->OriginalType == UserFmtIMA4)
- {
- ALuint FrameBlockSize{BufferFmt->mBlockAlign};
- ALuint align{(BufferFmt->mBlockAlign-1)/2 + 4};
- ALuint BlockSize{align * BufferFmt->channelsFromFmt()};
-
- /* Round down to nearest ADPCM block */
- return static_cast<double>(length / FrameBlockSize) * BlockSize;
- }
- else if(BufferFmt->OriginalType == UserFmtMSADPCM)
- {
- ALuint FrameBlockSize{BufferFmt->mBlockAlign};
- ALuint align{(FrameBlockSize-2)/2 + 7};
- ALuint BlockSize{align * BufferFmt->channelsFromFmt()};
+ const ALuint BlockSamples{BufferFmt->mBlockAlign};
+ const ALuint BlockSize{BufferFmt->blockSizeFromFmt()};
- /* Round down to nearest ADPCM block */
- return static_cast<double>(length / FrameBlockSize) * BlockSize;
- }
- return static_cast<double>(length) * BufferFmt->frameSizeFromFmt();
+ /* Round down to the block boundary. */
+ return static_cast<double>(length / BlockSamples) * BlockSize;
}
return 0.0;
}