From 766cfd2f1891b11f5de704f2a7fe7583459eb8b0 Mon Sep 17 00:00:00 2001 From: Crystal Squirrel Date: Sat, 15 Nov 2025 18:47:30 +0100 Subject: [PATCH 1/3] Replace reinterpret_cast with static_cast --- src/openrct2-ui/audio/AudioChannel.cpp | 2 +- src/openrct2-ui/audio/FlacAudioSource.cpp | 16 ++++++++-------- src/openrct2-ui/audio/MemoryAudioSource.cpp | 2 +- src/openrct2-ui/audio/OggAudioSource.cpp | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/openrct2-ui/audio/AudioChannel.cpp b/src/openrct2-ui/audio/AudioChannel.cpp index c033a0e700..f188e7637d 100644 --- a/src/openrct2-ui/audio/AudioChannel.cpp +++ b/src/openrct2-ui/audio/AudioChannel.cpp @@ -254,7 +254,7 @@ namespace OpenRCT2::Audio size_t readLen = _source->Read(dst, _offset, bytesToRead); if (readLen > 0) { - dst = reinterpret_cast(reinterpret_cast(dst) + readLen); + dst = static_cast(static_cast(dst) + readLen); bytesToRead -= readLen; bytesRead += readLen; _offset += readLen; diff --git a/src/openrct2-ui/audio/FlacAudioSource.cpp b/src/openrct2-ui/audio/FlacAudioSource.cpp index 17a5665659..accdcb299d 100644 --- a/src/openrct2-ui/audio/FlacAudioSource.cpp +++ b/src/openrct2-ui/audio/FlacAudioSource.cpp @@ -96,7 +96,7 @@ namespace OpenRCT2::Audio _currentOffset = offset; } - auto dst8 = reinterpret_cast(dst); + auto dst8 = static_cast(dst); auto bytesRead = ReadFromDecodeBuffer(dst8, len); dst8 += bytesRead; if (bytesRead < len) @@ -171,7 +171,7 @@ namespace OpenRCT2::Audio static FLAC__StreamDecoderReadStatus FlacCallbackRead( const FLAC__StreamDecoder* decoder, FLAC__byte buffer[], size_t* bytes, void* clientData) { - auto* self = reinterpret_cast(clientData); + auto* self = static_cast(clientData); if (*bytes > 0) { *bytes = SDL_RWread(self->_rw, buffer, sizeof(FLAC__byte), *bytes); @@ -193,7 +193,7 @@ namespace OpenRCT2::Audio static FLAC__StreamDecoderSeekStatus FlacCallbackSeek( const FLAC__StreamDecoder* decoder, FLAC__uint64 absoluteByteOffset, void* clientData) { - auto* self = reinterpret_cast(clientData); + auto* self = static_cast(clientData); if (SDL_RWseek(self->_rw, absoluteByteOffset, RW_SEEK_SET) < 0) { return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; @@ -207,7 +207,7 @@ namespace OpenRCT2::Audio static FLAC__StreamDecoderTellStatus FlacCallbackTell( const FLAC__StreamDecoder* decoder, FLAC__uint64* absoluteByteOffset, void* clientData) { - auto* self = reinterpret_cast(clientData); + auto* self = static_cast(clientData); auto pos = SDL_RWtell(self->_rw); if (pos < 0) { @@ -223,7 +223,7 @@ namespace OpenRCT2::Audio static FLAC__StreamDecoderLengthStatus FlacCallbackLength( const FLAC__StreamDecoder* decoder, FLAC__uint64* streamLength, void* clientData) { - auto* self = reinterpret_cast(clientData); + auto* self = static_cast(clientData); auto pos = SDL_RWtell(self->_rw); auto length = SDL_RWseek(self->_rw, 0, RW_SEEK_END); if (SDL_RWseek(self->_rw, pos, RW_SEEK_SET) != pos || length < 0) @@ -239,7 +239,7 @@ namespace OpenRCT2::Audio static FLAC__bool FlacCallbackEof(const FLAC__StreamDecoder* decoder, void* clientData) { - auto* self = reinterpret_cast(clientData); + auto* self = static_cast(clientData); auto pos = SDL_RWtell(self->_rw); auto end = SDL_RWseek(self->_rw, 0, RW_SEEK_END); if (pos == end) @@ -256,7 +256,7 @@ namespace OpenRCT2::Audio static FLAC__StreamDecoderWriteStatus FlacCallbackWrite( const FLAC__StreamDecoder* decoder, const FLAC__Frame* frame, const FLAC__int32* const buffer[], void* clientData) { - auto* self = reinterpret_cast(clientData); + auto* self = static_cast(clientData); // Determine sizes auto channels = self->_format.channels; @@ -301,7 +301,7 @@ namespace OpenRCT2::Audio static void FlacCallbackMetadata( const FLAC__StreamDecoder* decoder, const FLAC__StreamMetadata* metadata, void* clientData) { - auto* self = reinterpret_cast(clientData); + auto* self = static_cast(clientData); if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { self->_bitsPerSample = metadata->data.stream_info.bits_per_sample; diff --git a/src/openrct2-ui/audio/MemoryAudioSource.cpp b/src/openrct2-ui/audio/MemoryAudioSource.cpp index 696bd4293f..88dc696d32 100644 --- a/src/openrct2-ui/audio/MemoryAudioSource.cpp +++ b/src/openrct2-ui/audio/MemoryAudioSource.cpp @@ -55,7 +55,7 @@ namespace OpenRCT2::Audio auto src = _data.data(); if (src != nullptr) { - std::copy_n(src + offset, bytesToRead, reinterpret_cast(dst)); + std::copy_n(src + offset, bytesToRead, static_cast(dst)); } } return bytesToRead; diff --git a/src/openrct2-ui/audio/OggAudioSource.cpp b/src/openrct2-ui/audio/OggAudioSource.cpp index 99f07f046f..3fcf663cbd 100644 --- a/src/openrct2-ui/audio/OggAudioSource.cpp +++ b/src/openrct2-ui/audio/OggAudioSource.cpp @@ -101,7 +101,7 @@ namespace OpenRCT2::Audio } auto readLen = static_cast(len); - auto dst8 = reinterpret_cast(dst); + auto dst8 = static_cast(dst); int64_t totalBytesRead{}; int64_t bytesRead; do @@ -139,17 +139,17 @@ namespace OpenRCT2::Audio private: static size_t VorbisCallbackRead(void* ptr, size_t size, size_t nmemb, void* datasource) { - return SDL_RWread(reinterpret_cast(datasource), ptr, size, nmemb); + return SDL_RWread(static_cast(datasource), ptr, size, nmemb); } static int VorbisCallbackSeek(void* datasource, ogg_int64_t offset, int whence) { - return (SDL_RWseek(reinterpret_cast(datasource), offset, whence) < 0) ? -1 : 0; + return (SDL_RWseek(static_cast(datasource), offset, whence) < 0) ? -1 : 0; } static long VorbisCallbackTell(void* datasource) { - return static_cast(SDL_RWtell(reinterpret_cast(datasource))); + return static_cast(SDL_RWtell(static_cast(datasource))); } }; #endif From 22e50556a9e81cd3dbfa50ce80c34dc53fc815fd Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 15 Nov 2025 18:48:55 +0100 Subject: [PATCH 2/3] Rename _format to _outputFormat --- src/openrct2-ui/audio/AudioMixer.cpp | 39 ++++++++++++++-------------- src/openrct2-ui/audio/AudioMixer.h | 4 +-- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/openrct2-ui/audio/AudioMixer.cpp b/src/openrct2-ui/audio/AudioMixer.cpp index 01a7de4bde..aa69bd9ec1 100644 --- a/src/openrct2-ui/audio/AudioMixer.cpp +++ b/src/openrct2-ui/audio/AudioMixer.cpp @@ -40,9 +40,9 @@ void AudioMixer::Init(const char* device) SDL_AudioSpec have; _deviceId = SDL_OpenAudioDevice(device, 0, &want, &have, 0); - _format.format = have.format; - _format.channels = have.channels; - _format.freq = have.freq; + _outputFormat.format = have.format; + _outputFormat.channels = have.channels; + _outputFormat.freq = have.freq; SDL_PauseAudioDevice(_deviceId, 0); } @@ -121,7 +121,7 @@ void AudioMixer::RemoveReleasedSources() const AudioFormat& AudioMixer::GetFormat() const { - return _format; + return _outputFormat; } void AudioMixer::GetNextAudioChunk(uint8_t* dst, size_t length) @@ -173,10 +173,10 @@ void AudioMixer::UpdateAdjustedSound() void AudioMixer::MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t length) { - int32_t byteRate = _format.GetByteRate(); + int32_t byteRate = _outputFormat.GetByteRate(); auto numSamples = static_cast(length / byteRate); double rate = 1; - if (_format.format == AUDIO_S16SYS) + if (_outputFormat.format == AUDIO_S16SYS) { rate = channel->GetRate(); } @@ -185,11 +185,11 @@ void AudioMixer::MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t len SDL_AudioCVT cvt; cvt.len_ratio = 1; AudioFormat streamformat = channel->GetFormat(); - if (streamformat != _format) + if (streamformat != _outputFormat) { if (SDL_BuildAudioCVT( - &cvt, streamformat.format, streamformat.channels, streamformat.freq, _format.format, _format.channels, - _format.freq) + &cvt, streamformat.format, streamformat.channels, streamformat.freq, _outputFormat.format, + _outputFormat.channels, _outputFormat.freq) == -1) { // Unable to convert channel data @@ -232,8 +232,8 @@ void AudioMixer::MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t len int32_t outRate = numSamples; if (bytesRead != readLength) { - inRate = _format.freq; - outRate = _format.freq * (1 / rate); + inRate = _outputFormat.freq; + outRate = _outputFormat.freq * (1 / rate); } _effectBuffer.resize(length); bufferLen = ApplyResample(channel, buffer, static_cast(bufferLen / byteRate), numSamples, inRate, outRate); @@ -246,25 +246,26 @@ void AudioMixer::MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t len // Finally mix on to destination buffer size_t dstLength = std::min(length, bufferLen); - SDL_MixAudioFormat(data, static_cast(buffer), _format.format, static_cast(dstLength), mixVolume); + SDL_MixAudioFormat( + data, static_cast(buffer), _outputFormat.format, static_cast(dstLength), mixVolume); channel->UpdateOldVolume(); } /** * Resample the given buffer into _effectBuffer. - * Assumes that srcBuffer is the same format as _format. + * Assumes that srcBuffer is the same format as _outputFormat. */ size_t AudioMixer::ApplyResample( ISDLAudioChannel* channel, const void* srcBuffer, int32_t srcSamples, int32_t dstSamples, int32_t inRate, int32_t outRate) { - int32_t byteRate = _format.GetByteRate(); + int32_t byteRate = _outputFormat.GetByteRate(); // Create resampler SpeexResamplerState* resampler = channel->GetResampler(); if (resampler == nullptr) { - resampler = speex_resampler_init(_format.channels, _format.freq, _format.freq, 0, nullptr); + resampler = speex_resampler_init(_outputFormat.channels, _outputFormat.freq, _outputFormat.freq, 0, nullptr); channel->SetResampler(resampler); } speex_resampler_set_rate(resampler, inRate, outRate); @@ -280,9 +281,9 @@ size_t AudioMixer::ApplyResample( void AudioMixer::ApplyPan(const IAudioChannel* channel, void* buffer, size_t len, size_t sampleSize) { - if (channel->GetPan() != 0.5f && _format.channels == 2) + if (channel->GetPan() != 0.5f && _outputFormat.channels == 2) { - switch (_format.format) + switch (_outputFormat.format) { case AUDIO_S16SYS: EffectPanS16(channel, static_cast(buffer), static_cast(len / sampleSize)); @@ -331,8 +332,8 @@ int32_t AudioMixer::ApplyVolume(const IAudioChannel* channel, void* buffer, size mixVolume = kMixerVolumeMax; // Fade between volume levels to smooth out sound and minimize clicks from sudden volume changes - int32_t fadeLength = static_cast(len) / _format.BytesPerSample(); - switch (_format.format) + int32_t fadeLength = static_cast(len) / _outputFormat.BytesPerSample(); + switch (_outputFormat.format) { case AUDIO_S16SYS: EffectFadeS16(static_cast(buffer), fadeLength, startVolume, endVolume); diff --git a/src/openrct2-ui/audio/AudioMixer.h b/src/openrct2-ui/audio/AudioMixer.h index 549cb89b91..7e4aaa782c 100644 --- a/src/openrct2-ui/audio/AudioMixer.h +++ b/src/openrct2-ui/audio/AudioMixer.h @@ -33,7 +33,7 @@ namespace OpenRCT2::Audio std::vector> _sources; SDL_AudioDeviceID _deviceId = 0; - AudioFormat _format = {}; + AudioFormat _outputFormat = {}; std::list> _channels; float _volume = 1.0f; float _adjustSoundVolume = 0.0f; @@ -67,7 +67,7 @@ namespace OpenRCT2::Audio /** * Resample the given buffer into _effectBuffer. - * Assumes that srcBuffer is the same format as _format. + * Assumes that srcBuffer is the same format as _outputFormat. */ size_t ApplyResample( ISDLAudioChannel* channel, const void* srcBuffer, int32_t srcSamples, int32_t dstSamples, int32_t inRate, From 2ed1e8ef9009a54c5e7f1d31a293fe43db3a6e0d Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 15 Nov 2025 18:51:34 +0100 Subject: [PATCH 3/3] Rename byteRate to outputByteRate --- src/openrct2-ui/audio/AudioMixer.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/openrct2-ui/audio/AudioMixer.cpp b/src/openrct2-ui/audio/AudioMixer.cpp index aa69bd9ec1..856fbbca1b 100644 --- a/src/openrct2-ui/audio/AudioMixer.cpp +++ b/src/openrct2-ui/audio/AudioMixer.cpp @@ -173,8 +173,8 @@ void AudioMixer::UpdateAdjustedSound() void AudioMixer::MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t length) { - int32_t byteRate = _outputFormat.GetByteRate(); - auto numSamples = static_cast(length / byteRate); + int32_t outputByteRate = _outputFormat.GetByteRate(); + auto numSamples = static_cast(length / outputByteRate); double rate = 1; if (_outputFormat.format == AUDIO_S16SYS) { @@ -200,7 +200,7 @@ void AudioMixer::MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t len // Read raw PCM from channel int32_t readSamples = numSamples * rate; - auto readLength = static_cast(readSamples / cvt.len_ratio) * byteRate; + auto readLength = static_cast(readSamples / cvt.len_ratio) * outputByteRate; _channelBuffer.resize(readLength); size_t bytesRead = channel->Read(_channelBuffer.data(), readLength); @@ -228,7 +228,7 @@ void AudioMixer::MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t len // Apply effects if (rate != 1) { - auto inRate = static_cast(bufferLen / byteRate); + auto inRate = static_cast(bufferLen / outputByteRate); int32_t outRate = numSamples; if (bytesRead != readLength) { @@ -236,12 +236,13 @@ void AudioMixer::MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t len outRate = _outputFormat.freq * (1 / rate); } _effectBuffer.resize(length); - bufferLen = ApplyResample(channel, buffer, static_cast(bufferLen / byteRate), numSamples, inRate, outRate); + bufferLen = ApplyResample( + channel, buffer, static_cast(bufferLen / outputByteRate), numSamples, inRate, outRate); buffer = _effectBuffer.data(); } // Apply panning and volume - ApplyPan(channel, buffer, bufferLen, byteRate); + ApplyPan(channel, buffer, bufferLen, outputByteRate); int32_t mixVolume = ApplyVolume(channel, buffer, bufferLen); // Finally mix on to destination buffer @@ -259,7 +260,7 @@ void AudioMixer::MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t len size_t AudioMixer::ApplyResample( ISDLAudioChannel* channel, const void* srcBuffer, int32_t srcSamples, int32_t dstSamples, int32_t inRate, int32_t outRate) { - int32_t byteRate = _outputFormat.GetByteRate(); + int32_t outputByteRate = _outputFormat.GetByteRate(); // Create resampler SpeexResamplerState* resampler = channel->GetResampler(); @@ -276,7 +277,7 @@ size_t AudioMixer::ApplyResample( resampler, static_cast(srcBuffer), &inLen, reinterpret_cast(_effectBuffer.data()), &outLen); - return outLen * byteRate; + return outLen * outputByteRate; } void AudioMixer::ApplyPan(const IAudioChannel* channel, void* buffer, size_t len, size_t sampleSize)