Fix Ogg ov_read call on big-endian systems

In the `ov_read` API, the fouth parameter says what endianness the
samples should be returned in - `0` for little-endian, and `1` for
big-endian. SFML wants samples in the host endian, so we need to set
this parameter to 1 on big-endian systems.

Fixes a unit test failure on big-endian systems.
This commit is contained in:
James Cowgill 2024-12-08 00:15:42 +00:00 committed by Chris Thrasher
parent f930cbc562
commit 34ec2795a1
3 changed files with 6 additions and 2 deletions

View File

@ -135,6 +135,7 @@ For a closer look at breaking changes and how to migrate from SFML 2, check out
- Fixed `sf::SoundStream::play` bug (#2037)
- Fixed poor `sf::SoundStream::setPlayingOffset` precision (#3101)
- Fixed a bug when reading Ogg files on big endian systems (#3340)
### Network

View File

@ -169,6 +169,9 @@ target_compile_definitions(sfml-audio PRIVATE MA_NO_MP3 MA_NO_FLAC MA_NO_ENCODIN
# use standard fixed-width integer types
target_compile_definitions(sfml-audio PRIVATE MA_USE_STDINT)
# detect the endianness as required by Ogg
target_compile_definitions(sfml-audio PRIVATE SFML_IS_BIG_ENDIAN=$<STREQUAL:${CMAKE_CXX_BYTE_ORDER},BIG_ENDIAN>)
# setup dependencies
target_link_libraries(sfml-audio
PUBLIC SFML::System

View File

@ -196,8 +196,8 @@ std::uint64_t SoundFileReaderOgg::read(std::int16_t* samples, std::uint64_t maxC
std::uint64_t count = 0;
while (count < maxCount)
{
const int bytesToRead = static_cast<int>(maxCount - count) * static_cast<int>(sizeof(std::int16_t));
const long bytesRead = ov_read(&m_vorbis, reinterpret_cast<char*>(samples), bytesToRead, 0, 2, 1, nullptr);
const int bytesToRead = static_cast<int>(maxCount - count) * static_cast<int>(sizeof(std::int16_t));
const long bytesRead = ov_read(&m_vorbis, reinterpret_cast<char*>(samples), bytesToRead, SFML_IS_BIG_ENDIAN, 2, 1, nullptr);
if (bytesRead > 0)
{
const long samplesRead = bytesRead / static_cast<long>(sizeof(std::int16_t));