diff --git a/src/openrct2-ui/audio/AudioMixer.cpp b/src/openrct2-ui/audio/AudioMixer.cpp index 23be6e9215..a3974a02e7 100644 --- a/src/openrct2-ui/audio/AudioMixer.cpp +++ b/src/openrct2-ui/audio/AudioMixer.cpp @@ -74,7 +74,7 @@ namespace OpenRCT2::Audio want.samples = 2048; want.callback = [](void* arg, uint8_t* dst, int32_t length) -> void { auto mixer = static_cast(arg); - mixer->GetNextAudioChunk(dst, (size_t)length); + mixer->GetNextAudioChunk(dst, static_cast(length)); }; want.userdata = this; @@ -167,7 +167,7 @@ namespace OpenRCT2::Audio IAudioSource* source = _musicSources[pathId]; if (source == nullptr) { - const utf8* path = context_get_path_legacy((int32_t)pathId); + const utf8* path = context_get_path_legacy(static_cast(pathId)); source = AudioSource::CreateMemoryFromWAV(path, &_format); if (source == nullptr) { @@ -258,7 +258,7 @@ namespace OpenRCT2::Audio void MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t length) { int32_t byteRate = _format.GetByteRate(); - int32_t numSamples = (int32_t)(length / byteRate); + int32_t numSamples = static_cast(length / byteRate); double rate = 1; if (_format.format == AUDIO_S16SYS) { @@ -283,8 +283,8 @@ namespace OpenRCT2::Audio } // Read raw PCM from channel - int32_t readSamples = (int32_t)(numSamples * rate); - size_t readLength = (size_t)(readSamples / cvt.len_ratio) * byteRate; + int32_t readSamples = static_cast(numSamples * rate); + size_t readLength = static_cast(readSamples / cvt.len_ratio) * byteRate; _channelBuffer.resize(readLength); size_t bytesRead = channel->Read(_channelBuffer.data(), readLength); @@ -312,7 +312,7 @@ namespace OpenRCT2::Audio // Apply effects if (rate != 1) { - int32_t inRate = (int32_t)(bufferLen / byteRate); + int32_t inRate = static_cast(bufferLen / byteRate); int32_t outRate = numSamples; if (bytesRead != readLength) { @@ -320,7 +320,8 @@ namespace OpenRCT2::Audio outRate = _format.freq * (1 / rate); } _effectBuffer.resize(length); - bufferLen = ApplyResample(channel, buffer, (int32_t)(bufferLen / byteRate), numSamples, inRate, outRate); + bufferLen = ApplyResample( + channel, buffer, static_cast(bufferLen / byteRate), numSamples, inRate, outRate); buffer = _effectBuffer.data(); } @@ -330,7 +331,8 @@ namespace OpenRCT2::Audio // Finally mix on to destination buffer size_t dstLength = std::min(length, bufferLen); - SDL_MixAudioFormat(data, static_cast(buffer), _format.format, (uint32_t)dstLength, mixVolume); + SDL_MixAudioFormat( + data, static_cast(buffer), _format.format, static_cast(dstLength), mixVolume); channel->UpdateOldVolume(); } @@ -357,7 +359,8 @@ namespace OpenRCT2::Audio uint32_t inLen = srcSamples; uint32_t outLen = dstSamples; speex_resampler_process_interleaved_int( - resampler, static_cast(srcBuffer), &inLen, (spx_int16_t*)_effectBuffer.data(), &outLen); + resampler, static_cast(srcBuffer), &inLen, + reinterpret_cast(_effectBuffer.data()), &outLen); return outLen * byteRate; } @@ -369,10 +372,10 @@ namespace OpenRCT2::Audio switch (_format.format) { case AUDIO_S16SYS: - EffectPanS16(channel, static_cast(buffer), (int32_t)(len / sampleSize)); + EffectPanS16(channel, static_cast(buffer), static_cast(len / sampleSize)); break; case AUDIO_U8: - EffectPanU8(channel, static_cast(buffer), (int32_t)(len / sampleSize)); + EffectPanU8(channel, static_cast(buffer), static_cast(len / sampleSize)); break; } } @@ -399,21 +402,21 @@ namespace OpenRCT2::Audio break; } - int32_t startVolume = (int32_t)(channel->GetOldVolume() * volumeAdjust); - int32_t endVolume = (int32_t)(channel->GetVolume() * volumeAdjust); + int32_t startVolume = static_cast(channel->GetOldVolume() * volumeAdjust); + int32_t endVolume = static_cast(channel->GetVolume() * volumeAdjust); if (channel->IsStopping()) { endVolume = 0; } - int32_t mixVolume = (int32_t)(channel->GetVolume() * volumeAdjust); + int32_t mixVolume = static_cast(channel->GetVolume() * volumeAdjust); if (startVolume != endVolume) { // Set to max since we are adjusting the volume ourselves mixVolume = MIXER_VOLUME_MAX; // Fade between volume levels to smooth out sound and minimize clicks from sudden volume changes - int32_t fadeLength = (int32_t)len / _format.BytesPerSample(); + int32_t fadeLength = static_cast(len) / _format.BytesPerSample(); switch (_format.format) { case AUDIO_S16SYS: @@ -437,8 +440,8 @@ namespace OpenRCT2::Audio for (int32_t i = 0; i < length * 2; i += 2) { - data[i] = (int16_t)(data[i] * volumeL); - data[i + 1] = (int16_t)(data[i + 1] * volumeR); + data[i] = static_cast(data[i] * volumeL); + data[i + 1] = static_cast(data[i + 1] * volumeR); volumeL += d_left; volumeR += d_right; } @@ -453,9 +456,9 @@ namespace OpenRCT2::Audio for (int32_t i = 0; i < length * 2; i += 2) { - float t = (float)i / (length * 2); - data[i] = (uint8_t)(data[i] * ((1.0 - t) * oldVolumeL + t * volumeL)); - data[i + 1] = (uint8_t)(data[i + 1] * ((1.0 - t) * oldVolumeR + t * volumeR)); + float t = static_cast(i) / (length * 2); + data[i] = static_cast(data[i] * ((1.0 - t) * oldVolumeL + t * volumeL)); + data[i + 1] = static_cast(data[i + 1] * ((1.0 - t) * oldVolumeR + t * volumeR)); } } @@ -463,12 +466,12 @@ namespace OpenRCT2::Audio { static_assert(SDL_MIX_MAXVOLUME == MIXER_VOLUME_MAX, "Max volume differs between OpenRCT2 and SDL2"); - float startvolume_f = (float)startvolume / SDL_MIX_MAXVOLUME; - float endvolume_f = (float)endvolume / SDL_MIX_MAXVOLUME; + float startvolume_f = static_cast(startvolume) / SDL_MIX_MAXVOLUME; + float endvolume_f = static_cast(endvolume) / SDL_MIX_MAXVOLUME; for (int32_t i = 0; i < length; i++) { - float t = (float)i / length; - data[i] = (int16_t)(data[i] * ((1 - t) * startvolume_f + t * endvolume_f)); + float t = static_cast(i) / length; + data[i] = static_cast(data[i] * ((1 - t) * startvolume_f + t * endvolume_f)); } } @@ -476,12 +479,12 @@ namespace OpenRCT2::Audio { static_assert(SDL_MIX_MAXVOLUME == MIXER_VOLUME_MAX, "Max volume differs between OpenRCT2 and SDL2"); - float startvolume_f = (float)startvolume / SDL_MIX_MAXVOLUME; - float endvolume_f = (float)endvolume / SDL_MIX_MAXVOLUME; + float startvolume_f = static_cast(startvolume) / SDL_MIX_MAXVOLUME; + float endvolume_f = static_cast(endvolume) / SDL_MIX_MAXVOLUME; for (int32_t i = 0; i < length; i++) { - float t = (float)i / length; - data[i] = (uint8_t)(data[i] * ((1 - t) * startvolume_f + t * endvolume_f)); + float t = static_cast(i) / length; + data[i] = static_cast(data[i] * ((1 - t) * startvolume_f + t * endvolume_f)); } } @@ -496,8 +499,8 @@ namespace OpenRCT2::Audio _convertBuffer.resize(reqConvertBufferCapacity); std::copy_n(static_cast(src), len, _convertBuffer.data()); - cvt->len = (int32_t)len; - cvt->buf = (uint8_t*)_convertBuffer.data(); + cvt->len = static_cast(len); + cvt->buf = static_cast(_convertBuffer.data()); if (SDL_ConvertAudio(cvt) >= 0) { result = true;