Use bits per sample rather than bytes as there are 4-bit sounds

This commit is contained in:
smallmodel 2024-11-30 23:23:49 +01:00
parent aa74934ae0
commit d5d5c7a55d
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
2 changed files with 10 additions and 10 deletions

View file

@ -4572,7 +4572,7 @@ U32 openal_channel_two_d_stream::sample_offset()
ALint numProcessedBuffers = 0;
ALint numQueuedBuffers = 0;
unsigned int totalQueueLength = 0;
unsigned int bytesPerSample = 0;
unsigned int bitsPerSample = 0;
unsigned int offset = 0;
ALint bits = 0, channels = 0;
@ -4586,7 +4586,7 @@ U32 openal_channel_two_d_stream::sample_offset()
alDieIfError();
totalQueueLength = getQueueLength();
bytesPerSample = getBytesPerSample();
bitsPerSample = getBitsPerSample();
assert(playerByteOffset < totalQueueLength);
assert(streamNextOffset >= totalQueueLength || stream);
@ -4614,7 +4614,7 @@ U32 openal_channel_two_d_stream::sample_offset()
offset = totalQueueLength - streamNextOffset + playerByteOffset;
}
return offset / bytesPerSample;
return offset * 8 / bitsPerSample;
}
/*
@ -4644,7 +4644,7 @@ void openal_channel_two_d_stream::set_sample_offset(U32 offset)
snd_stream_t *stream;
unsigned int bytesToRead, bytesRead;
unsigned int byteOffset;
unsigned int bytesPerSample;
unsigned int bitsPerSample;
unsigned int streamPosition;
ALuint format;
ALint numQueuedBuffers;
@ -4657,8 +4657,8 @@ void openal_channel_two_d_stream::set_sample_offset(U32 offset)
stream = (snd_stream_t *)streamHandle;
streamPosition = getCurrentStreamPosition();
bytesPerSample = getBytesPerSample();
byteOffset = offset * bytesPerSample;
bitsPerSample = getBitsPerSample();
byteOffset = offset * bitsPerSample / 8;
if (byteOffset >= streamPosition && byteOffset < streamNextOffset) {
//
@ -4908,13 +4908,13 @@ unsigned int openal_channel_two_d_stream::getCurrentStreamPosition() const
/*
==============
openal_channel_two_d_stream::getBytesPerSample
openal_channel_two_d_stream::getBitsPerSample
Return the number of bytes per sample.
It assumes that all pending buffers have the same channels and bits.
==============
*/
unsigned int openal_channel_two_d_stream::getBytesPerSample() const
unsigned int openal_channel_two_d_stream::getBitsPerSample() const
{
unsigned int bufferId;
ALint bits = 0, channels = 0;
@ -4925,5 +4925,5 @@ unsigned int openal_channel_two_d_stream::getBytesPerSample() const
qalGetBufferi(buffers[bufferId], AL_CHANNELS, &channels);
alDieIfError();
return bits * channels / 8;
return bits * channels;
}

View file

@ -165,7 +165,7 @@ private:
unsigned int getQueueLength() const;
unsigned int getCurrentStreamPosition() const;
unsigned int getBytesPerSample() const;
unsigned int getBitsPerSample() const;
};
struct openal_movie_channel : public openal_channel {