From 111852a9831a57b9ce19299ebf28f1e1e6b61914 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 25 Sep 2020 00:27:08 -0400 Subject: effect_context: Make use of explicit where applicable While we're at it we can make the destructor of the base class virtual to ensure that any polymorphism issues never occur. --- src/audio_core/effect_context.h | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/effect_context.h b/src/audio_core/effect_context.h index 2f2da72dd..c2d2aa3ba 100644 --- a/src/audio_core/effect_context.h +++ b/src/audio_core/effect_context.h @@ -166,13 +166,13 @@ public: std::array raw; }; }; - static_assert(sizeof(EffectInfo::InParams) == 0xc0, "InParams is an invalid size"); + static_assert(sizeof(InParams) == 0xc0, "InParams is an invalid size"); struct OutParams { UsageStatus status{}; INSERT_PADDING_BYTES(15); }; - static_assert(sizeof(EffectInfo::OutParams) == 0x10, "OutParams is an invalid size"); + static_assert(sizeof(OutParams) == 0x10, "OutParams is an invalid size"); }; struct AuxAddress { @@ -184,8 +184,8 @@ struct AuxAddress { class EffectBase { public: - EffectBase(EffectType effect_type); - ~EffectBase(); + explicit EffectBase(EffectType effect_type); + virtual ~EffectBase(); virtual void Update(EffectInfo::InParams& in_params) = 0; virtual void UpdateForCommandGeneration() = 0; @@ -206,8 +206,7 @@ protected: template class EffectGeneric : public EffectBase { public: - EffectGeneric(EffectType effect_type) : EffectBase::EffectBase(effect_type) {} - ~EffectGeneric() = default; + explicit EffectGeneric(EffectType effect_type) : EffectBase(effect_type) {} T& GetParams() { return internal_params; @@ -224,7 +223,7 @@ private: class EffectStubbed : public EffectBase { public: explicit EffectStubbed(); - ~EffectStubbed(); + ~EffectStubbed() override; void Update(EffectInfo::InParams& in_params) override; void UpdateForCommandGeneration() override; @@ -233,7 +232,7 @@ public: class EffectI3dl2Reverb : public EffectGeneric { public: explicit EffectI3dl2Reverb(); - ~EffectI3dl2Reverb(); + ~EffectI3dl2Reverb() override; void Update(EffectInfo::InParams& in_params) override; void UpdateForCommandGeneration() override; @@ -245,7 +244,7 @@ private: class EffectBiquadFilter : public EffectGeneric { public: explicit EffectBiquadFilter(); - ~EffectBiquadFilter(); + ~EffectBiquadFilter() override; void Update(EffectInfo::InParams& in_params) override; void UpdateForCommandGeneration() override; @@ -254,7 +253,7 @@ public: class EffectAuxInfo : public EffectGeneric { public: explicit EffectAuxInfo(); - ~EffectAuxInfo(); + ~EffectAuxInfo() override; void Update(EffectInfo::InParams& in_params) override; void UpdateForCommandGeneration() override; @@ -275,7 +274,7 @@ private: class EffectDelay : public EffectGeneric { public: explicit EffectDelay(); - ~EffectDelay(); + ~EffectDelay() override; void Update(EffectInfo::InParams& in_params) override; void UpdateForCommandGeneration() override; @@ -287,7 +286,7 @@ private: class EffectBufferMixer : public EffectGeneric { public: explicit EffectBufferMixer(); - ~EffectBufferMixer(); + ~EffectBufferMixer() override; void Update(EffectInfo::InParams& in_params) override; void UpdateForCommandGeneration() override; @@ -296,7 +295,7 @@ public: class EffectReverb : public EffectGeneric { public: explicit EffectReverb(); - ~EffectReverb(); + ~EffectReverb() override; void Update(EffectInfo::InParams& in_params) override; void UpdateForCommandGeneration() override; -- cgit v1.2.3 From 8b4ecf22d485958f69ecbd2fa4ca55d9ce393826 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 25 Sep 2020 00:28:35 -0400 Subject: audio_core: Resolve sign conversion warnings While were at it, we can also enable sign conversion warnings and other common warnings as errors to prevent these from creeping back into the codebase. --- src/audio_core/CMakeLists.txt | 10 ++++++++++ src/audio_core/command_generator.cpp | 12 ++++++------ src/audio_core/effect_context.cpp | 8 ++++---- src/audio_core/effect_context.h | 8 ++++---- src/audio_core/info_updater.cpp | 7 +++---- src/audio_core/mix_context.cpp | 4 ++-- src/audio_core/splitter_context.cpp | 6 +++--- src/audio_core/voice_context.cpp | 4 ++-- 8 files changed, 34 insertions(+), 25 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index cb00ef60e..6a7075f73 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt @@ -44,6 +44,16 @@ add_library(audio_core STATIC create_target_directory_groups(audio_core) +if (NOT MSVC) + target_compile_options(audio_core PRIVATE + -Werror=ignored-qualifiers + -Werror=implicit-fallthrough + -Werror=reorder + -Werror=sign-compare + -Werror=unused-variable + ) +endif() + target_link_libraries(audio_core PUBLIC common core) target_link_libraries(audio_core PRIVATE SoundTouch) diff --git a/src/audio_core/command_generator.cpp b/src/audio_core/command_generator.cpp index 8f7da49e6..7f2597257 100644 --- a/src/audio_core/command_generator.cpp +++ b/src/audio_core/command_generator.cpp @@ -152,7 +152,7 @@ void CommandGenerator::GenerateVoiceCommand(ServerVoiceInfo& voice_info) { if (!destination_data->IsConfigured()) { continue; } - if (destination_data->GetMixId() >= mix_context.GetCount()) { + if (destination_data->GetMixId() >= static_cast(mix_context.GetCount())) { continue; } @@ -435,7 +435,7 @@ void CommandGenerator::GenerateAuxCommand(s32 mix_buffer_offset, EffectBase* inf GetMixBuffer(output_index), worker_params.sample_count, offset, write_count); memory.WriteBlock(aux->GetRecvInfo(), &recv_info, sizeof(AuxInfoDSP)); - if (samples_read != worker_params.sample_count && + if (samples_read != static_cast(worker_params.sample_count) && samples_read <= params.sample_count) { std::memset(GetMixBuffer(output_index), 0, params.sample_count - samples_read); } @@ -611,7 +611,8 @@ void CommandGenerator::GenerateMixCommands(ServerMixInfo& mix_info) { const auto& dest_mix = mix_context.GetInfo(destination_data->GetMixId()); const auto& dest_in_params = dest_mix.GetInParams(); const auto mix_index = (base - 1) % in_params.buffer_count + in_params.buffer_offset; - for (std::size_t i = 0; i < dest_in_params.buffer_count; i++) { + for (std::size_t i = 0; i < static_cast(dest_in_params.buffer_count); + i++) { const auto mixed_volume = in_params.volume * destination_data->GetMixVolume(i); if (mixed_volume != 0.0f) { GenerateMixCommand(dest_in_params.buffer_offset + i, mix_index, mixed_volume, @@ -704,7 +705,7 @@ s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_s std::vector buffer(samples_processed * channel_count); memory.ReadBlock(buffer_pos, buffer.data(), buffer.size() * sizeof(s16)); - for (std::size_t i = 0; i < samples_processed; i++) { + for (std::size_t i = 0; i < static_cast(samples_processed); i++) { sample_buffer[mix_offset + i] = buffer[i * channel_count + channel]; } } @@ -789,7 +790,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s position_in_frame += 2; // Decode entire frame - if (remaining_samples >= SAMPLES_PER_FRAME) { + if (remaining_samples >= static_cast(SAMPLES_PER_FRAME)) { for (std::size_t i = 0; i < SAMPLES_PER_FRAME / 2; i++) { // Sample 1 @@ -866,7 +867,6 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o const auto resample_rate = static_cast( static_cast(in_params.sample_rate) / static_cast(target_sample_rate) * static_cast(static_cast(in_params.pitch * 32768.0f))); - auto* output_base = output; if (dsp_state.fraction + sample_count * resample_rate > static_cast(SCALED_MIX_BUFFER_SIZE - 4ULL)) { return; diff --git a/src/audio_core/effect_context.cpp b/src/audio_core/effect_context.cpp index adfec3df5..4d9cdf524 100644 --- a/src/audio_core/effect_context.cpp +++ b/src/audio_core/effect_context.cpp @@ -184,19 +184,19 @@ void EffectAuxInfo::UpdateForCommandGeneration() { } } -const VAddr EffectAuxInfo::GetSendInfo() const { +VAddr EffectAuxInfo::GetSendInfo() const { return send_info; } -const VAddr EffectAuxInfo::GetSendBuffer() const { +VAddr EffectAuxInfo::GetSendBuffer() const { return send_buffer; } -const VAddr EffectAuxInfo::GetRecvInfo() const { +VAddr EffectAuxInfo::GetRecvInfo() const { return recv_info; } -const VAddr EffectAuxInfo::GetRecvBuffer() const { +VAddr EffectAuxInfo::GetRecvBuffer() const { return recv_buffer; } diff --git a/src/audio_core/effect_context.h b/src/audio_core/effect_context.h index c2d2aa3ba..2c4ce53ef 100644 --- a/src/audio_core/effect_context.h +++ b/src/audio_core/effect_context.h @@ -257,10 +257,10 @@ public: void Update(EffectInfo::InParams& in_params) override; void UpdateForCommandGeneration() override; - const VAddr GetSendInfo() const; - const VAddr GetSendBuffer() const; - const VAddr GetRecvInfo() const; - const VAddr GetRecvBuffer() const; + VAddr GetSendInfo() const; + VAddr GetSendBuffer() const; + VAddr GetRecvInfo() const; + VAddr GetRecvBuffer() const; private: VAddr send_info{}; diff --git a/src/audio_core/info_updater.cpp b/src/audio_core/info_updater.cpp index f53ce21a5..2940e53a9 100644 --- a/src/audio_core/info_updater.cpp +++ b/src/audio_core/info_updater.cpp @@ -64,7 +64,6 @@ bool InfoUpdater::UpdateBehaviorInfo(BehaviorInfo& in_behavior_info) { } bool InfoUpdater::UpdateMemoryPools(std::vector& memory_pool_info) { - const auto force_mapping = behavior_info.IsMemoryPoolForceMappingEnabled(); const auto memory_pool_count = memory_pool_info.size(); const auto total_memory_pool_in = sizeof(ServerMemoryPoolInfo::InParams) * memory_pool_count; const auto total_memory_pool_out = sizeof(ServerMemoryPoolInfo::OutParams) * memory_pool_count; @@ -174,7 +173,7 @@ bool InfoUpdater::UpdateVoices(VoiceContext& voice_context, } // Voice states for each channel std::array voice_states{}; - ASSERT(in_params.id < voice_count); + ASSERT(static_cast(in_params.id) < voice_count); // Grab our current voice info auto& voice_info = voice_context.GetInfo(static_cast(in_params.id)); @@ -352,8 +351,8 @@ ResultCode InfoUpdater::UpdateMixes(MixContext& mix_context, std::size_t mix_buf for (std::size_t i = 0; i < mix_count; i++) { const auto& in = mix_in_params[i]; total_buffer_count += in.buffer_count; - if (in.dest_mix_id > mix_count && in.dest_mix_id != AudioCommon::NO_MIX && - in.mix_id != AudioCommon::FINAL_MIX) { + if (static_cast(in.dest_mix_id) > mix_count && + in.dest_mix_id != AudioCommon::NO_MIX && in.mix_id != AudioCommon::FINAL_MIX) { LOG_ERROR( Audio, "Invalid mix destination, mix_id={:X}, dest_mix_id={:X}, mix_buffer_count={:X}", diff --git a/src/audio_core/mix_context.cpp b/src/audio_core/mix_context.cpp index 042891490..4bca72eb0 100644 --- a/src/audio_core/mix_context.cpp +++ b/src/audio_core/mix_context.cpp @@ -53,7 +53,7 @@ void MixContext::UpdateDistancesFromFinalMix() { auto mix_id = in_params.mix_id; // Needs to be referenced out of scope s32 distance_to_final_mix{AudioCommon::FINAL_MIX}; - for (; distance_to_final_mix < info_count; distance_to_final_mix++) { + for (; distance_to_final_mix < static_cast(info_count); distance_to_final_mix++) { if (mix_id == AudioCommon::FINAL_MIX) { // If we're at the final mix, we're done break; @@ -77,7 +77,7 @@ void MixContext::UpdateDistancesFromFinalMix() { } // If we're out of range for our distance, mark it as no final mix - if (distance_to_final_mix >= info_count) { + if (distance_to_final_mix >= static_cast(info_count)) { distance_to_final_mix = AudioCommon::NO_FINAL_MIX; } diff --git a/src/audio_core/splitter_context.cpp b/src/audio_core/splitter_context.cpp index 79bb2f516..f21b53147 100644 --- a/src/audio_core/splitter_context.cpp +++ b/src/audio_core/splitter_context.cpp @@ -306,7 +306,7 @@ bool SplitterContext::UpdateInfo(const std::vector& input, std::size_t& inpu break; } - if (header.send_id < 0 || header.send_id > info_count) { + if (header.send_id < 0 || static_cast(header.send_id) > info_count) { LOG_ERROR(Audio, "Bad splitter data id"); break; } @@ -348,7 +348,7 @@ bool SplitterContext::UpdateData(const std::vector& input, std::size_t& inpu break; } - if (header.splitter_id < 0 || header.splitter_id > data_count) { + if (header.splitter_id < 0 || static_cast(header.splitter_id) > data_count) { LOG_ERROR(Audio, "Bad splitter data id"); break; } @@ -434,7 +434,7 @@ const std::vector& NodeStates::GetIndexList() const { } void NodeStates::PushTsortResult(s32 index) { - ASSERT(index < node_count); + ASSERT(index < static_cast(node_count)); index_list[index_pos++] = index; } diff --git a/src/audio_core/voice_context.cpp b/src/audio_core/voice_context.cpp index 1d8f69844..863ac9267 100644 --- a/src/audio_core/voice_context.cpp +++ b/src/audio_core/voice_context.cpp @@ -488,11 +488,11 @@ s32 VoiceContext::DecodePcm16(s32* output_buffer, ServerWaveBuffer* wave_buffer, // Fast path if (channel_count == 1) { - for (std::size_t i = 0; i < samples_processed; i++) { + for (std::ptrdiff_t i = 0; i < samples_processed; i++) { output_buffer[i] = buffer_data[i]; } } else { - for (std::size_t i = 0; i < samples_processed; i++) { + for (std::ptrdiff_t i = 0; i < samples_processed; i++) { output_buffer[i] = buffer_data[i * channel_count + channel]; } } -- cgit v1.2.3 From 966966dc0260077b9e607995e1930afa1a2ecc40 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 25 Sep 2020 13:19:39 -0400 Subject: audio_core: Remove unnecessary inclusions Same behavior, but removes header dependencies where they don't need to be. --- src/audio_core/audio_renderer.cpp | 5 +---- src/audio_core/audio_renderer.h | 1 - src/audio_core/command_generator.h | 1 - src/audio_core/common.h | 1 + src/audio_core/stream.cpp | 1 - 5 files changed, 2 insertions(+), 7 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp index 56dc892b1..a7e851bb8 100644 --- a/src/audio_core/audio_renderer.cpp +++ b/src/audio_core/audio_renderer.cpp @@ -3,16 +3,13 @@ // Refer to the license.txt file included. #include -#include "audio_core/algorithm/interpolate.h" + #include "audio_core/audio_out.h" #include "audio_core/audio_renderer.h" -#include "audio_core/codec.h" #include "audio_core/common.h" #include "audio_core/info_updater.h" #include "audio_core/voice_context.h" -#include "common/assert.h" #include "common/logging/log.h" -#include "core/core.h" #include "core/hle/kernel/writable_event.h" #include "core/memory.h" #include "core/settings.h" diff --git a/src/audio_core/audio_renderer.h b/src/audio_core/audio_renderer.h index 2bca795ba..2fd93e058 100644 --- a/src/audio_core/audio_renderer.h +++ b/src/audio_core/audio_renderer.h @@ -21,7 +21,6 @@ #include "common/common_funcs.h" #include "common/common_types.h" #include "common/swap.h" -#include "core/hle/kernel/object.h" #include "core/hle/result.h" namespace Core::Timing { diff --git a/src/audio_core/command_generator.h b/src/audio_core/command_generator.h index 967d24078..53e57748b 100644 --- a/src/audio_core/command_generator.h +++ b/src/audio_core/command_generator.h @@ -7,7 +7,6 @@ #include #include "audio_core/common.h" #include "audio_core/voice_context.h" -#include "common/common_funcs.h" #include "common/common_types.h" namespace Core::Memory { diff --git a/src/audio_core/common.h b/src/audio_core/common.h index 72ebce221..7b4a1e9e8 100644 --- a/src/audio_core/common.h +++ b/src/audio_core/common.h @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #pragma once + #include "common/common_funcs.h" #include "common/common_types.h" #include "common/swap.h" diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index cb33926bc..4bbb1e0c4 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp @@ -12,7 +12,6 @@ #include "common/assert.h" #include "common/logging/log.h" #include "core/core_timing.h" -#include "core/core_timing_util.h" #include "core/settings.h" namespace AudioCore { -- cgit v1.2.3 From 7c0908f301867b7f8667d7720094a3ad3616dd53 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 25 Sep 2020 14:18:09 -0400 Subject: codec: Make lookup table static constexpr Allows compilers to elide needing to push these values on the stack every time the function is called. --- src/audio_core/codec.cpp | 5 +++-- src/audio_core/codec.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/codec.cpp b/src/audio_core/codec.cpp index c5a0d98ce..2fb91c13a 100644 --- a/src/audio_core/codec.cpp +++ b/src/audio_core/codec.cpp @@ -16,8 +16,9 @@ std::vector DecodeADPCM(const u8* const data, std::size_t size, const ADPCM constexpr std::size_t FRAME_LEN = 8; constexpr std::size_t SAMPLES_PER_FRAME = 14; - constexpr std::array SIGNED_NIBBLES = { - {0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1}}; + static constexpr std::array SIGNED_NIBBLES{ + 0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1, + }; const std::size_t sample_count = (size / FRAME_LEN) * SAMPLES_PER_FRAME; const std::size_t ret_size = diff --git a/src/audio_core/codec.h b/src/audio_core/codec.h index ef2ce01a8..9507abb1b 100644 --- a/src/audio_core/codec.h +++ b/src/audio_core/codec.h @@ -38,7 +38,7 @@ using ADPCM_Coeff = std::array; * @param state ADPCM state, this is updated with new state * @return Decoded stereo signed PCM16 data, sample_count in length */ -std::vector DecodeADPCM(const u8* const data, std::size_t size, const ADPCM_Coeff& coeff, +std::vector DecodeADPCM(const u8* data, std::size_t size, const ADPCM_Coeff& coeff, ADPCMState& state); }; // namespace AudioCore::Codec -- cgit v1.2.3 From 407393130589abe4d68ab7e144a4a74fe58e1b5a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 25 Sep 2020 17:09:59 -0400 Subject: cubeb_sink: Use static_cast instead of reinterpret_cast in DataCallback() Conversions from void* to the proper data type are well-defined and supported by static_cast. We don't need to use reinterpret_cast here. --- src/audio_core/cubeb_sink.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp index 83c06c0ed..eb82791f6 100644 --- a/src/audio_core/cubeb_sink.cpp +++ b/src/audio_core/cubeb_sink.cpp @@ -192,8 +192,8 @@ SinkStream& CubebSink::AcquireSinkStream(u32 sample_rate, u32 num_channels, long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, void* output_buffer, long num_frames) { - CubebSinkStream* impl = static_cast(user_data); - u8* buffer = reinterpret_cast(output_buffer); + auto* impl = static_cast(user_data); + auto* buffer = static_cast(output_buffer); if (!impl) { return {}; -- cgit v1.2.3 From dc83ca8914222230873c6a3b6056d8f9c183f42c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 25 Sep 2020 17:14:02 -0400 Subject: behavior_info: Fix typo Renerer -> Renderer --- src/audio_core/behavior_info.cpp | 6 +++--- src/audio_core/behavior_info.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/behavior_info.cpp b/src/audio_core/behavior_info.cpp index 5d62adb0b..3c2e3e6f1 100644 --- a/src/audio_core/behavior_info.cpp +++ b/src/audio_core/behavior_info.cpp @@ -57,15 +57,15 @@ bool BehaviorInfo::IsLongSizePreDelaySupported() const { return AudioCommon::IsRevisionSupported(3, user_revision); } -bool BehaviorInfo::IsAudioRenererProcessingTimeLimit80PercentSupported() const { +bool BehaviorInfo::IsAudioRendererProcessingTimeLimit80PercentSupported() const { return AudioCommon::IsRevisionSupported(5, user_revision); } -bool BehaviorInfo::IsAudioRenererProcessingTimeLimit75PercentSupported() const { +bool BehaviorInfo::IsAudioRendererProcessingTimeLimit75PercentSupported() const { return AudioCommon::IsRevisionSupported(4, user_revision); } -bool BehaviorInfo::IsAudioRenererProcessingTimeLimit70PercentSupported() const { +bool BehaviorInfo::IsAudioRendererProcessingTimeLimit70PercentSupported() const { return AudioCommon::IsRevisionSupported(1, user_revision); } diff --git a/src/audio_core/behavior_info.h b/src/audio_core/behavior_info.h index 50948e8df..512a4ebe3 100644 --- a/src/audio_core/behavior_info.h +++ b/src/audio_core/behavior_info.h @@ -49,9 +49,9 @@ public: bool IsAdpcmLoopContextBugFixed() const; bool IsSplitterSupported() const; bool IsLongSizePreDelaySupported() const; - bool IsAudioRenererProcessingTimeLimit80PercentSupported() const; - bool IsAudioRenererProcessingTimeLimit75PercentSupported() const; - bool IsAudioRenererProcessingTimeLimit70PercentSupported() const; + bool IsAudioRendererProcessingTimeLimit80PercentSupported() const; + bool IsAudioRendererProcessingTimeLimit75PercentSupported() const; + bool IsAudioRendererProcessingTimeLimit70PercentSupported() const; bool IsElapsedFrameCountSupported() const; bool IsMemoryPoolForceMappingEnabled() const; bool IsFlushVoiceWaveBuffersSupported() const; -- cgit v1.2.3 From 90c61411640c049c6a5c376782b37d94f949f1f5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 25 Sep 2020 18:30:49 -0400 Subject: command_generator: Make lookup table static constexpr Allows compilers to elide needing to push these values on the stack every time the function is called. --- src/audio_core/command_generator.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/command_generator.cpp b/src/audio_core/command_generator.cpp index 8f7da49e6..07c932e93 100644 --- a/src/audio_core/command_generator.cpp +++ b/src/audio_core/command_generator.cpp @@ -726,8 +726,9 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s return 0; } - constexpr std::array SIGNED_NIBBLES = { - {0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1}}; + static constexpr std::array SIGNED_NIBBLES{ + 0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1, + }; constexpr std::size_t FRAME_LEN = 8; constexpr std::size_t NIBBLES_PER_SAMPLE = 16; -- cgit v1.2.3 From 9f9b64d280d50b39c92e8e12c6f45ef78a72b4ea Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 13 Oct 2020 16:00:33 -0400 Subject: audio_core/CMakeLists: Make warnings consistent with core Normalizes the warnings shared between audio_core and core. --- src/audio_core/CMakeLists.txt | 3 +++ src/audio_core/algorithm/filter.cpp | 3 ++- src/audio_core/algorithm/interpolate.cpp | 5 +++-- src/audio_core/command_generator.cpp | 3 +-- src/audio_core/cubeb_sink.cpp | 6 ++++-- src/audio_core/voice_context.cpp | 5 ++++- 6 files changed, 17 insertions(+), 8 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index 6a7075f73..54940a034 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt @@ -46,10 +46,13 @@ create_target_directory_groups(audio_core) if (NOT MSVC) target_compile_options(audio_core PRIVATE + -Werror=conversion -Werror=ignored-qualifiers -Werror=implicit-fallthrough -Werror=reorder -Werror=sign-compare + -Werror=unused-but-set-parameter + -Werror=unused-but-set-variable -Werror=unused-variable ) endif() diff --git a/src/audio_core/algorithm/filter.cpp b/src/audio_core/algorithm/filter.cpp index f65bf64f7..f34a5b9f3 100644 --- a/src/audio_core/algorithm/filter.cpp +++ b/src/audio_core/algorithm/filter.cpp @@ -55,7 +55,8 @@ void Filter::Process(std::vector& signal) { /// @param total_count The total number of biquads to be cascaded. /// @param index 0-index of the biquad to calculate the Q value for. static double CascadingBiquadQ(std::size_t total_count, std::size_t index) { - const double pole = M_PI * (2 * index + 1) / (4.0 * total_count); + const auto pole = + M_PI * static_cast(2 * index + 1) / (4.0 * static_cast(total_count)); return 1.0 / (2.0 * std::cos(pole)); } diff --git a/src/audio_core/algorithm/interpolate.cpp b/src/audio_core/algorithm/interpolate.cpp index 689a54508..699fcb84c 100644 --- a/src/audio_core/algorithm/interpolate.cpp +++ b/src/audio_core/algorithm/interpolate.cpp @@ -146,7 +146,7 @@ std::vector Interpolate(InterpolationState& state, std::vector input, return {}; if (ratio <= 0) { - LOG_CRITICAL(Audio, "Nonsensical interpolation ratio {}", ratio); + LOG_ERROR(Audio, "Nonsensical interpolation ratio {}", ratio); return input; } @@ -164,7 +164,8 @@ std::vector Interpolate(InterpolationState& state, std::vector input, const std::size_t num_frames{input.size() / 2}; std::vector output; - output.reserve(static_cast(input.size() / ratio + InterpolationState::taps)); + output.reserve(static_cast(static_cast(input.size()) / ratio + + InterpolationState::taps)); for (std::size_t frame{}; frame < num_frames; ++frame) { const std::size_t lut_index{(state.fraction >> 8) * InterpolationState::taps}; diff --git a/src/audio_core/command_generator.cpp b/src/audio_core/command_generator.cpp index bba40d13d..fb8700ccf 100644 --- a/src/audio_core/command_generator.cpp +++ b/src/audio_core/command_generator.cpp @@ -793,7 +793,6 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s // Decode entire frame if (remaining_samples >= static_cast(SAMPLES_PER_FRAME)) { for (std::size_t i = 0; i < SAMPLES_PER_FRAME / 2; i++) { - // Sample 1 const s32 s0 = SIGNED_NIBBLES[buffer[buffer_offset] >> 4]; const s32 s1 = SIGNED_NIBBLES[buffer[buffer_offset++] & 0xf]; @@ -802,7 +801,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s sample_buffer[cur_mix_offset++] = sample_1; sample_buffer[cur_mix_offset++] = sample_2; } - remaining_samples -= SAMPLES_PER_FRAME; + remaining_samples -= static_cast(SAMPLES_PER_FRAME); position_in_frame += SAMPLES_PER_FRAME; continue; } diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp index eb82791f6..6eaa60815 100644 --- a/src/audio_core/cubeb_sink.cpp +++ b/src/audio_core/cubeb_sink.cpp @@ -93,8 +93,10 @@ public: constexpr s32 clev{707}; // center mixing level coefficient constexpr s32 slev{707}; // surround mixing level coefficient - buf.push_back(left + (clev * center / 1000) + (slev * surround_left / 1000)); - buf.push_back(right + (clev * center / 1000) + (slev * surround_right / 1000)); + buf.push_back(static_cast(left + (clev * center / 1000) + + (slev * surround_left / 1000))); + buf.push_back(static_cast(right + (clev * center / 1000) + + (slev * surround_right / 1000))); } queue.Push(buf); return; diff --git a/src/audio_core/voice_context.cpp b/src/audio_core/voice_context.cpp index 863ac9267..c46ee55f1 100644 --- a/src/audio_core/voice_context.cpp +++ b/src/audio_core/voice_context.cpp @@ -128,7 +128,10 @@ void ServerVoiceInfo::UpdateParameters(const VoiceInfo::InParams& voice_in, in_params.wave_buffer_count = voice_in.wave_buffer_count; in_params.wave_bufffer_head = voice_in.wave_buffer_head; if (behavior_info.IsFlushVoiceWaveBuffersSupported()) { - in_params.wave_buffer_flush_request_count += voice_in.wave_buffer_flush_request_count; + const auto in_request_count = in_params.wave_buffer_flush_request_count; + const auto voice_request_count = voice_in.wave_buffer_flush_request_count; + in_params.wave_buffer_flush_request_count = + static_cast(in_request_count + voice_request_count); } in_params.mix_id = voice_in.mix_id; if (behavior_info.IsSplitterSupported()) { -- cgit v1.2.3 From be1954e04cb5a0c3a526f78ed5490a5e65310280 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 15 Oct 2020 14:49:45 -0400 Subject: core: Fix clang build Recent changes to the build system that made more warnings be flagged as errors caused building via clang to break. Fixes #4795 --- src/audio_core/CMakeLists.txt | 5 +- src/audio_core/algorithm/interpolate.cpp | 6 +- src/audio_core/audio_renderer.cpp | 4 +- src/audio_core/codec.cpp | 6 +- src/audio_core/command_generator.cpp | 212 +++++++++++++++++-------------- src/audio_core/command_generator.h | 4 +- src/audio_core/cubeb_sink.cpp | 2 +- src/audio_core/cubeb_sink.h | 2 +- src/audio_core/info_updater.cpp | 4 +- src/audio_core/mix_context.cpp | 17 +-- src/audio_core/sink_context.cpp | 5 +- src/audio_core/splitter_context.cpp | 60 ++++----- src/audio_core/time_stretch.h | 10 +- src/audio_core/voice_context.cpp | 47 ++++--- 14 files changed, 215 insertions(+), 169 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index 54940a034..74c1453aa 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt @@ -51,8 +51,9 @@ if (NOT MSVC) -Werror=implicit-fallthrough -Werror=reorder -Werror=sign-compare - -Werror=unused-but-set-parameter - -Werror=unused-but-set-variable + -Werror=sign-conversion + $<$:-Werror=unused-but-set-parameter> + $<$:-Werror=unused-but-set-variable> -Werror=unused-variable ) endif() diff --git a/src/audio_core/algorithm/interpolate.cpp b/src/audio_core/algorithm/interpolate.cpp index 699fcb84c..587ee5b7b 100644 --- a/src/audio_core/algorithm/interpolate.cpp +++ b/src/audio_core/algorithm/interpolate.cpp @@ -167,8 +167,8 @@ std::vector Interpolate(InterpolationState& state, std::vector input, output.reserve(static_cast(static_cast(input.size()) / ratio + InterpolationState::taps)); - for (std::size_t frame{}; frame < num_frames; ++frame) { - const std::size_t lut_index{(state.fraction >> 8) * InterpolationState::taps}; + for (std::size_t frame = 0; frame < num_frames; ++frame) { + const auto lut_index{static_cast(state.fraction >> 8) * InterpolationState::taps}; std::rotate(state.history.begin(), state.history.end() - 1, state.history.end()); state.history[0][0] = input[frame * 2 + 0]; @@ -225,7 +225,7 @@ void Resample(s32* output, const s32* input, s32 pitch, s32& fraction, std::size output[i] = (l0 * s0 + l1 * s1 + l2 * s2 + l3 * s3) >> 15; fraction += pitch; - index += (fraction >> 15); + index += static_cast(fraction >> 15); fraction &= 0x7fff; } } diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp index a7e851bb8..094bace9c 100644 --- a/src/audio_core/audio_renderer.cpp +++ b/src/audio_core/audio_renderer.cpp @@ -187,8 +187,8 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) { const auto& in_params = final_mix.GetInParams(); std::vector mix_buffers(channel_count); for (std::size_t i = 0; i < channel_count; i++) { - mix_buffers[i] = - command_generator.GetMixBuffer(in_params.buffer_offset + buffer_offsets[i]); + mix_buffers[i] = command_generator.GetMixBuffer( + static_cast(in_params.buffer_offset) + buffer_offsets[i]); } for (std::size_t i = 0; i < BUFFER_SIZE; i++) { diff --git a/src/audio_core/codec.cpp b/src/audio_core/codec.cpp index 2fb91c13a..d89f94ea2 100644 --- a/src/audio_core/codec.cpp +++ b/src/audio_core/codec.cpp @@ -32,7 +32,7 @@ std::vector DecodeADPCM(const u8* const data, std::size_t size, const ADPCM for (std::size_t framei = 0; framei < NUM_FRAMES; framei++) { const int frame_header = data[framei * FRAME_LEN]; const int scale = 1 << (frame_header & 0xF); - const int idx = (frame_header >> 4) & 0x7; + const auto idx = static_cast((frame_header >> 4) & 0x7); // Coefficients are fixed point with 11 bits fractional part. const int coef1 = coeff[idx * 2 + 0]; @@ -57,11 +57,11 @@ std::vector DecodeADPCM(const u8* const data, std::size_t size, const ADPCM std::size_t outputi = framei * SAMPLES_PER_FRAME; std::size_t datai = framei * FRAME_LEN + 1; for (std::size_t i = 0; i < SAMPLES_PER_FRAME && outputi < sample_count; i += 2) { - const s16 sample1 = decode_sample(SIGNED_NIBBLES[data[datai] >> 4]); + const s16 sample1 = decode_sample(SIGNED_NIBBLES[static_cast(data[datai] >> 4)]); ret[outputi] = sample1; outputi++; - const s16 sample2 = decode_sample(SIGNED_NIBBLES[data[datai] & 0xF]); + const s16 sample2 = decode_sample(SIGNED_NIBBLES[static_cast(data[datai] & 0xF)]); ret[outputi] = sample2; outputi++; diff --git a/src/audio_core/command_generator.cpp b/src/audio_core/command_generator.cpp index fb8700ccf..c0edb625d 100644 --- a/src/audio_core/command_generator.cpp +++ b/src/audio_core/command_generator.cpp @@ -15,8 +15,8 @@ constexpr std::size_t MIX_BUFFER_SIZE = 0x3f00; constexpr std::size_t SCALED_MIX_BUFFER_SIZE = MIX_BUFFER_SIZE << 15ULL; template -void ApplyMix(s32* output, const s32* input, s32 gain, s32 sample_count) { - for (std::size_t i = 0; i < static_cast(sample_count); i += N) { +void ApplyMix(s32* output, const s32* input, s32 gain, std::size_t sample_count) { + for (std::size_t i = 0; i < sample_count; i += N) { for (std::size_t j = 0; j < N; j++) { output[i + j] += static_cast((static_cast(input[i + j]) * gain + 0x4000) >> 15); @@ -111,7 +111,8 @@ void CommandGenerator::GenerateVoiceCommand(ServerVoiceInfo& voice_info) { const auto channel_count = in_params.channel_count; for (s32 channel = 0; channel < channel_count; channel++) { - const auto resource_id = in_params.voice_channel_resource_id[channel]; + const auto resource_id = + static_cast(in_params.voice_channel_resource_id[static_cast(channel)]); auto& dsp_state = voice_context.GetDspSharedState(resource_id); auto& channel_resource = voice_context.GetChannelResource(resource_id); @@ -132,14 +133,15 @@ void CommandGenerator::GenerateVoiceCommand(ServerVoiceInfo& voice_info) { if (in_params.mix_id != AudioCommon::NO_MIX) { // If we're using a mix id - auto& mix_info = mix_context.GetInfo(in_params.mix_id); + auto& mix_info = mix_context.GetInfo(static_cast(in_params.mix_id)); const auto& dest_mix_params = mix_info.GetInParams(); // Voice Mixing GenerateVoiceMixCommand( channel_resource.GetCurrentMixVolume(), channel_resource.GetLastMixVolume(), - dsp_state, dest_mix_params.buffer_offset, dest_mix_params.buffer_count, - worker_params.mix_buffer_count + channel, in_params.node_id); + dsp_state, static_cast(dest_mix_params.buffer_offset), + static_cast(dest_mix_params.buffer_count), + worker_params.mix_buffer_count + static_cast(channel), in_params.node_id); // Update last mix volumes channel_resource.UpdateLastMixVolumes(); @@ -156,12 +158,15 @@ void CommandGenerator::GenerateVoiceCommand(ServerVoiceInfo& voice_info) { continue; } - const auto& mix_info = mix_context.GetInfo(destination_data->GetMixId()); + const auto& mix_info = + mix_context.GetInfo(static_cast(destination_data->GetMixId())); const auto& dest_mix_params = mix_info.GetInParams(); GenerateVoiceMixCommand( destination_data->CurrentMixVolumes(), destination_data->LastMixVolumes(), - dsp_state, dest_mix_params.buffer_offset, dest_mix_params.buffer_count, - worker_params.mix_buffer_count + channel, in_params.node_id); + dsp_state, static_cast(dest_mix_params.buffer_offset), + static_cast(dest_mix_params.buffer_count), + worker_params.mix_buffer_count + static_cast(channel), + in_params.node_id); destination_data->MarkDirty(); } } @@ -219,9 +224,10 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo if (depop) { if (in_params.mix_id != AudioCommon::NO_MIX) { - auto& mix_info = mix_context.GetInfo(in_params.mix_id); + auto& mix_info = mix_context.GetInfo(static_cast(in_params.mix_id)); const auto& mix_in = mix_info.GetInParams(); - GenerateDepopPrepareCommand(dsp_state, mix_in.buffer_count, mix_in.buffer_offset); + GenerateDepopPrepareCommand(dsp_state, static_cast(mix_in.buffer_count), + static_cast(mix_in.buffer_offset)); } else if (in_params.splitter_info_id != AudioCommon::NO_SPLITTER) { s32 index{}; while (const auto* destination = @@ -229,23 +235,24 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo if (!destination->IsConfigured()) { continue; } - auto& mix_info = mix_context.GetInfo(destination->GetMixId()); + auto& mix_info = mix_context.GetInfo(static_cast(destination->GetMixId())); const auto& mix_in = mix_info.GetInParams(); - GenerateDepopPrepareCommand(dsp_state, mix_in.buffer_count, mix_in.buffer_offset); + GenerateDepopPrepareCommand(dsp_state, static_cast(mix_in.buffer_count), + static_cast(mix_in.buffer_offset)); } } } else { switch (in_params.sample_format) { case SampleFormat::Pcm16: DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(channel), dsp_state, channel, - worker_params.sample_rate, worker_params.sample_count, - in_params.node_id); + static_cast(worker_params.sample_rate), + static_cast(worker_params.sample_count), in_params.node_id); break; case SampleFormat::Adpcm: ASSERT(channel == 0 && in_params.channel_count == 1); DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(0), dsp_state, 0, - worker_params.sample_rate, worker_params.sample_count, - in_params.node_id); + static_cast(worker_params.sample_rate), + static_cast(worker_params.sample_count), in_params.node_id); break; default: UNREACHABLE_MSG("Unimplemented sample format={}", in_params.sample_format); @@ -255,7 +262,7 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo void CommandGenerator::GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voice_info, VoiceState& dsp_state, - s32 mix_buffer_count, s32 channel) { + u32 mix_buffer_count, s32 channel) { for (std::size_t i = 0; i < AudioCommon::MAX_BIQUAD_FILTERS; i++) { const auto& in_params = voice_info.GetInParams(); auto& biquad_filter = in_params.biquad_filter[i]; @@ -335,8 +342,8 @@ void CommandGenerator::GenerateDepopForMixBuffersCommand(std::size_t mix_buffer_ continue; } - depop_buffer[i] = - ApplyMixDepop(GetMixBuffer(i), depop_buffer[i], delta, worker_params.sample_count); + depop_buffer[i] = ApplyMixDepop(GetMixBuffer(i), depop_buffer[i], delta, + static_cast(worker_params.sample_count)); } } @@ -348,7 +355,7 @@ void CommandGenerator::GenerateEffectCommand(ServerMixInfo& mix_info) { if (index == AudioCommon::NO_EFFECT_ORDER) { break; } - auto* info = effect_context.GetInfo(index); + auto* info = effect_context.GetInfo(static_cast(index)); const auto type = info->GetType(); // TODO(ogniK): Finish remaining effects @@ -377,11 +384,11 @@ void CommandGenerator::GenerateI3dl2ReverbEffectCommand(s32 mix_buffer_offset, E } const auto& params = dynamic_cast(info)->GetParams(); const auto channel_count = params.channel_count; - for (s32 i = 0; i < channel_count; i++) { + for (size_t i = 0; i < channel_count; i++) { // TODO(ogniK): Actually implement reverb if (params.input[i] != params.output[i]) { - const auto* input = GetMixBuffer(mix_buffer_offset + params.input[i]); - auto* output = GetMixBuffer(mix_buffer_offset + params.output[i]); + const auto* input = GetMixBuffer(static_cast(mix_buffer_offset + params.input[i])); + auto* output = GetMixBuffer(static_cast(mix_buffer_offset + params.output[i])); ApplyMix<1>(output, input, 32768, worker_params.sample_count); } } @@ -392,13 +399,14 @@ void CommandGenerator::GenerateBiquadFilterEffectCommand(s32 mix_buffer_offset, if (!enabled) { return; } + const auto& params = dynamic_cast(info)->GetParams(); - const auto channel_count = params.channel_count; - for (s32 i = 0; i < channel_count; i++) { + const auto channel_count = static_cast(params.channel_count); + for (size_t i = 0; i < channel_count; i++) { // TODO(ogniK): Actually implement biquad filter if (params.input[i] != params.output[i]) { - const auto* input = GetMixBuffer(mix_buffer_offset + params.input[i]); - auto* output = GetMixBuffer(mix_buffer_offset + params.output[i]); + const auto* input = GetMixBuffer(static_cast(mix_buffer_offset + params.input[i])); + auto* output = GetMixBuffer(static_cast(mix_buffer_offset + params.output[i])); ApplyMix<1>(output, input, 32768, worker_params.sample_count); } } @@ -425,26 +433,30 @@ void CommandGenerator::GenerateAuxCommand(s32 mix_buffer_offset, EffectBase* inf memory.ReadBlock(aux->GetSendInfo(), &send_info, sizeof(AuxInfoDSP)); memory.ReadBlock(aux->GetRecvInfo(), &recv_info, sizeof(AuxInfoDSP)); - WriteAuxBuffer(send_info, aux->GetSendBuffer(), params.sample_count, - GetMixBuffer(input_index), worker_params.sample_count, offset, - write_count); + WriteAuxBuffer(send_info, aux->GetSendBuffer(), + static_cast(params.sample_count), + GetMixBuffer(static_cast(input_index)), + worker_params.sample_count, offset, write_count); memory.WriteBlock(aux->GetSendInfo(), &send_info, sizeof(AuxInfoDSP)); const auto samples_read = ReadAuxBuffer( - recv_info, aux->GetRecvBuffer(), params.sample_count, - GetMixBuffer(output_index), worker_params.sample_count, offset, write_count); + recv_info, aux->GetRecvBuffer(), static_cast(params.sample_count), + GetMixBuffer(static_cast(output_index)), worker_params.sample_count, + offset, write_count); memory.WriteBlock(aux->GetRecvInfo(), &recv_info, sizeof(AuxInfoDSP)); if (samples_read != static_cast(worker_params.sample_count) && samples_read <= params.sample_count) { - std::memset(GetMixBuffer(output_index), 0, params.sample_count - samples_read); + std::memset(GetMixBuffer(static_cast(output_index)), 0, + static_cast(params.sample_count - samples_read)); } } else { AuxInfoDSP empty{}; memory.WriteBlock(aux->GetSendInfo(), &empty, sizeof(AuxInfoDSP)); memory.WriteBlock(aux->GetRecvInfo(), &empty, sizeof(AuxInfoDSP)); if (output_index != input_index) { - std::memcpy(GetMixBuffer(output_index), GetMixBuffer(input_index), + std::memcpy(GetMixBuffer(static_cast(output_index)), + GetMixBuffer(static_cast(input_index)), worker_params.sample_count * sizeof(s32)); } } @@ -458,7 +470,8 @@ ServerSplitterDestinationData* CommandGenerator::GetDestinationData(s32 splitter if (splitter_id == AudioCommon::NO_SPLITTER) { return nullptr; } - return splitter_context.GetDestinationData(splitter_id, index); + return splitter_context.GetDestinationData(static_cast(splitter_id), + static_cast(index)); } s32 CommandGenerator::WriteAuxBuffer(AuxInfoDSP& dsp_info, VAddr send_buffer, u32 max_samples, @@ -488,7 +501,7 @@ s32 CommandGenerator::WriteAuxBuffer(AuxInfoDSP& dsp_info, VAddr send_buffer, u3 if (write_count != 0) { dsp_info.write_offset = (dsp_info.write_offset + write_count) % max_samples; } - return sample_count; + return static_cast(sample_count); } s32 CommandGenerator::ReadAuxBuffer(AuxInfoDSP& recv_info, VAddr recv_buffer, u32 max_samples, @@ -518,7 +531,7 @@ s32 CommandGenerator::ReadAuxBuffer(AuxInfoDSP& recv_info, VAddr recv_buffer, u3 if (read_count != 0) { recv_info.read_offset = (recv_info.read_offset + read_count) % max_samples; } - return sample_count; + return static_cast(sample_count); } void CommandGenerator::GenerateVolumeRampCommand(float last_volume, float current_volume, @@ -537,15 +550,15 @@ void CommandGenerator::GenerateVolumeRampCommand(float last_volume, float curren } // Apply generic gain on samples ApplyGain(GetChannelMixBuffer(channel), GetChannelMixBuffer(channel), last, delta, - worker_params.sample_count); + static_cast(worker_params.sample_count)); } void CommandGenerator::GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volumes, const MixVolumeBuffer& last_mix_volumes, - VoiceState& dsp_state, s32 mix_buffer_offset, - s32 mix_buffer_count, s32 voice_index, s32 node_id) { + VoiceState& dsp_state, u32 mix_buffer_offset, + u32 mix_buffer_count, u32 voice_index, s32 node_id) { // Loop all our mix buffers - for (s32 i = 0; i < mix_buffer_count; i++) { + for (size_t i = 0; i < mix_buffer_count; i++) { if (last_mix_volumes[i] != 0.0f || mix_volumes[i] != 0.0f) { const auto delta = static_cast((mix_volumes[i] - last_mix_volumes[i])) / static_cast(worker_params.sample_count); @@ -558,9 +571,9 @@ void CommandGenerator::GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volume mix_volumes[i]); } - dsp_state.previous_samples[i] = - ApplyMixRamp(GetMixBuffer(mix_buffer_offset + i), GetMixBuffer(voice_index), - last_mix_volumes[i], delta, worker_params.sample_count); + dsp_state.previous_samples[i] = ApplyMixRamp( + GetMixBuffer(mix_buffer_offset + i), GetMixBuffer(voice_index), last_mix_volumes[i], + delta, static_cast(worker_params.sample_count)); } else { dsp_state.previous_samples[i] = 0; } @@ -572,7 +585,8 @@ void CommandGenerator::GenerateSubMixCommand(ServerMixInfo& mix_info) { LOG_DEBUG(Audio, "(DSP_TRACE) GenerateSubMixCommand"); } const auto& in_params = mix_info.GetInParams(); - GenerateDepopForMixBuffersCommand(in_params.buffer_count, in_params.buffer_offset, + GenerateDepopForMixBuffersCommand(static_cast(in_params.buffer_count), + static_cast(in_params.buffer_offset), in_params.sample_rate); GenerateEffectCommand(mix_info); @@ -586,18 +600,18 @@ void CommandGenerator::GenerateMixCommands(ServerMixInfo& mix_info) { } const auto& in_params = mix_info.GetInParams(); if (in_params.dest_mix_id != AudioCommon::NO_MIX) { - const auto& dest_mix = mix_context.GetInfo(in_params.dest_mix_id); + const auto& dest_mix = mix_context.GetInfo(static_cast(in_params.dest_mix_id)); const auto& dest_in_params = dest_mix.GetInParams(); - const auto buffer_count = in_params.buffer_count; + const auto buffer_count = static_cast(in_params.buffer_count); - for (s32 i = 0; i < buffer_count; i++) { - for (s32 j = 0; j < dest_in_params.buffer_count; j++) { + for (u32 i = 0; i < buffer_count; i++) { + for (u32 j = 0; j < static_cast(dest_in_params.buffer_count); j++) { const auto mixed_volume = in_params.volume * in_params.mix_volume[i][j]; if (mixed_volume != 0.0f) { - GenerateMixCommand(dest_in_params.buffer_offset + j, - in_params.buffer_offset + i, mixed_volume, - in_params.node_id); + GenerateMixCommand(static_cast(dest_in_params.buffer_offset) + j, + static_cast(in_params.buffer_offset) + i, + mixed_volume, static_cast(in_params.node_id)); } } } @@ -608,15 +622,17 @@ void CommandGenerator::GenerateMixCommands(ServerMixInfo& mix_info) { continue; } - const auto& dest_mix = mix_context.GetInfo(destination_data->GetMixId()); + const auto& dest_mix = + mix_context.GetInfo(static_cast(destination_data->GetMixId())); const auto& dest_in_params = dest_mix.GetInParams(); const auto mix_index = (base - 1) % in_params.buffer_count + in_params.buffer_offset; for (std::size_t i = 0; i < static_cast(dest_in_params.buffer_count); i++) { const auto mixed_volume = in_params.volume * destination_data->GetMixVolume(i); if (mixed_volume != 0.0f) { - GenerateMixCommand(dest_in_params.buffer_offset + i, mix_index, mixed_volume, - in_params.node_id); + GenerateMixCommand(static_cast(dest_in_params.buffer_offset) + i, + static_cast(mix_index), mixed_volume, + static_cast(in_params.node_id)); } } } @@ -635,7 +651,8 @@ void CommandGenerator::GenerateMixCommand(std::size_t output_offset, std::size_t auto* output = GetMixBuffer(output_offset); const auto* input = GetMixBuffer(input_offset); - const s32 gain = static_cast(volume * 32768.0f); + const auto gain = static_cast(volume * 32768.0f); + // Mix with loop unrolling if (worker_params.sample_count % 4 == 0) { ApplyMix<4>(output, input, gain, worker_params.sample_count); @@ -653,7 +670,8 @@ void CommandGenerator::GenerateFinalMixCommand() { auto& mix_info = mix_context.GetFinalMixInfo(); const auto& in_params = mix_info.GetInParams(); - GenerateDepopForMixBuffersCommand(in_params.buffer_count, in_params.buffer_offset, + GenerateDepopForMixBuffersCommand(static_cast(in_params.buffer_count), + static_cast(in_params.buffer_offset), in_params.sample_rate); GenerateEffectCommand(mix_info); @@ -667,16 +685,16 @@ void CommandGenerator::GenerateFinalMixCommand() { in_params.node_id, in_params.buffer_offset + i, in_params.buffer_offset + i, in_params.volume); } - ApplyGainWithoutDelta(GetMixBuffer(in_params.buffer_offset + i), - GetMixBuffer(in_params.buffer_offset + i), gain, - worker_params.sample_count); + ApplyGainWithoutDelta(GetMixBuffer(static_cast(in_params.buffer_offset + i)), + GetMixBuffer(static_cast(in_params.buffer_offset + i)), gain, + static_cast(worker_params.sample_count)); } } s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 sample_count, s32 channel, std::size_t mix_offset) { const auto& in_params = voice_info.GetInParams(); - const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index]; + const auto& wave_buffer = in_params.wave_buffer[static_cast(dsp_state.wave_buffer_index)]; if (wave_buffer.buffer_address == 0) { return 0; } @@ -689,24 +707,26 @@ s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_s const auto samples_remaining = (wave_buffer.end_sample_offset - wave_buffer.start_sample_offset) - dsp_state.offset; const auto start_offset = - ((wave_buffer.start_sample_offset + dsp_state.offset) * in_params.channel_count) * + static_cast((wave_buffer.start_sample_offset + dsp_state.offset) * + in_params.channel_count) * sizeof(s16); const auto buffer_pos = wave_buffer.buffer_address + start_offset; const auto samples_processed = std::min(sample_count, samples_remaining); if (in_params.channel_count == 1) { - std::vector buffer(samples_processed); + std::vector buffer(static_cast(samples_processed)); memory.ReadBlock(buffer_pos, buffer.data(), buffer.size() * sizeof(s16)); for (std::size_t i = 0; i < buffer.size(); i++) { sample_buffer[mix_offset + i] = buffer[i]; } } else { const auto channel_count = in_params.channel_count; - std::vector buffer(samples_processed * channel_count); + std::vector buffer(static_cast(samples_processed * channel_count)); memory.ReadBlock(buffer_pos, buffer.data(), buffer.size() * sizeof(s16)); for (std::size_t i = 0; i < static_cast(samples_processed); i++) { - sample_buffer[mix_offset + i] = buffer[i * channel_count + channel]; + sample_buffer[mix_offset + i] = + buffer[i * static_cast(channel_count) + static_cast(channel)]; } } @@ -716,7 +736,7 @@ s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_s s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 sample_count, s32 channel, std::size_t mix_offset) { const auto& in_params = voice_info.GetInParams(); - const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index]; + const auto& wave_buffer = in_params.wave_buffer[static_cast(dsp_state.wave_buffer_index)]; if (wave_buffer.buffer_address == 0) { return 0; } @@ -736,7 +756,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s constexpr std::size_t SAMPLES_PER_FRAME = 14; auto frame_header = dsp_state.context.header; - s32 idx = (frame_header >> 4) & 0xf; + auto idx = static_cast((frame_header >> 4) & 0xf); s32 scale = frame_header & 0xf; s16 yn1 = dsp_state.context.yn1; s16 yn2 = dsp_state.context.yn2; @@ -753,9 +773,10 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s const auto samples_processed = std::min(sample_count, samples_remaining); const auto sample_pos = wave_buffer.start_sample_offset + dsp_state.offset; - const auto samples_remaining_in_frame = sample_pos % SAMPLES_PER_FRAME; - auto position_in_frame = ((sample_pos / SAMPLES_PER_FRAME) * NIBBLES_PER_SAMPLE) + - samples_remaining_in_frame + (samples_remaining_in_frame != 0 ? 2 : 0); + const auto samples_remaining_in_frame = static_cast(sample_pos) % SAMPLES_PER_FRAME; + auto position_in_frame = + ((static_cast(sample_pos) / SAMPLES_PER_FRAME) * NIBBLES_PER_SAMPLE) + + samples_remaining_in_frame + (samples_remaining_in_frame != 0 ? 2 : 0); const auto decode_sample = [&](const int nibble) -> s16 { const int xn = nibble * (1 << scale); @@ -774,7 +795,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s std::size_t buffer_offset{}; std::vector buffer( - std::max((samples_processed / FRAME_LEN) * SAMPLES_PER_FRAME, FRAME_LEN)); + std::max((static_cast(samples_processed) / FRAME_LEN) * SAMPLES_PER_FRAME, FRAME_LEN)); memory.ReadBlock(wave_buffer.buffer_address + (position_in_frame / 2), buffer.data(), buffer.size()); std::size_t cur_mix_offset = mix_offset; @@ -784,7 +805,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s if (position_in_frame % NIBBLES_PER_SAMPLE == 0) { // Read header frame_header = buffer[buffer_offset++]; - idx = (frame_header >> 4) & 0xf; + idx = static_cast((frame_header >> 4) & 0xf); scale = frame_header & 0xf; coef1 = coeffs[idx * 2]; coef2 = coeffs[idx * 2 + 1]; @@ -794,8 +815,8 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s if (remaining_samples >= static_cast(SAMPLES_PER_FRAME)) { for (std::size_t i = 0; i < SAMPLES_PER_FRAME / 2; i++) { // Sample 1 - const s32 s0 = SIGNED_NIBBLES[buffer[buffer_offset] >> 4]; - const s32 s1 = SIGNED_NIBBLES[buffer[buffer_offset++] & 0xf]; + const s32 s0 = SIGNED_NIBBLES[static_cast(buffer[buffer_offset] >> 4)]; + const s32 s1 = SIGNED_NIBBLES[static_cast(buffer[buffer_offset++] & 0xf)]; const s16 sample_1 = decode_sample(s0); const s16 sample_2 = decode_sample(s1); sample_buffer[cur_mix_offset++] = sample_1; @@ -807,14 +828,14 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s } } // Decode mid frame - s32 current_nibble = buffer[buffer_offset]; - if (position_in_frame++ & 0x1) { + auto current_nibble = static_cast(buffer[buffer_offset]); + if ((position_in_frame++ & 1) != 0) { current_nibble &= 0xf; buffer_offset++; } else { current_nibble >>= 4; } - const s16 sample = decode_sample(SIGNED_NIBBLES[current_nibble]); + const s16 sample = decode_sample(SIGNED_NIBBLES[static_cast(current_nibble)]); sample_buffer[cur_mix_offset++] = sample; remaining_samples--; } @@ -835,7 +856,7 @@ const s32* CommandGenerator::GetMixBuffer(std::size_t index) const { } std::size_t CommandGenerator::GetMixChannelBufferOffset(s32 channel) const { - return worker_params.mix_buffer_count + channel; + return worker_params.mix_buffer_count + static_cast(channel); } std::size_t CommandGenerator::GetTotalMixBufferCount() const { @@ -843,11 +864,11 @@ std::size_t CommandGenerator::GetTotalMixBufferCount() const { } s32* CommandGenerator::GetChannelMixBuffer(s32 channel) { - return GetMixBuffer(worker_params.mix_buffer_count + channel); + return GetMixBuffer(worker_params.mix_buffer_count + static_cast(channel)); } const s32* CommandGenerator::GetChannelMixBuffer(s32 channel) const { - return GetMixBuffer(worker_params.mix_buffer_count + channel); + return GetMixBuffer(worker_params.mix_buffer_count + static_cast(channel)); } void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* output, @@ -895,9 +916,10 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o s32 samples_read{}; while (samples_read < samples_to_read) { - const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index]; + const auto& wave_buffer = + in_params.wave_buffer[static_cast(dsp_state.wave_buffer_index)]; // No more data can be read - if (!dsp_state.is_wave_buffer_valid[dsp_state.wave_buffer_index]) { + if (!dsp_state.is_wave_buffer_valid[static_cast(dsp_state.wave_buffer_index)]) { is_buffer_completed = true; break; } @@ -921,7 +943,7 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o UNREACHABLE_MSG("Unimplemented sample format={}", in_params.sample_format); } - temp_mix_offset += samples_decoded; + temp_mix_offset += static_cast(samples_decoded); samples_read += samples_decoded; dsp_state.offset += samples_decoded; dsp_state.played_sample_count += samples_decoded; @@ -944,10 +966,12 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o } else { // Update our wave buffer states - dsp_state.is_wave_buffer_valid[dsp_state.wave_buffer_index] = false; + dsp_state.is_wave_buffer_valid[static_cast(dsp_state.wave_buffer_index)] = + false; dsp_state.wave_buffer_consumed++; dsp_state.wave_buffer_index = - (dsp_state.wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS; + static_cast(dsp_state.wave_buffer_index + 1) % + AudioCommon::MAX_WAVE_BUFFERS; if (wave_buffer.end_of_stream) { dsp_state.played_sample_count = 0; } @@ -957,16 +981,20 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o if (in_params.behavior_flags.is_pitch_and_src_skipped.Value()) { // No need to resample - std::memcpy(output, sample_buffer.data(), samples_read * sizeof(s32)); + std::memcpy(output, sample_buffer.data(), + static_cast(samples_read) * sizeof(s32)); } else { - std::fill(sample_buffer.begin() + temp_mix_offset, - sample_buffer.begin() + temp_mix_offset + (samples_to_read - samples_read), - 0); + { + const auto begin = sample_buffer.begin() + static_cast(temp_mix_offset); + const auto end = begin + (samples_to_read - samples_read); + std::fill(begin, end, 0); + } AudioCore::Resample(output, sample_buffer.data(), resample_rate, dsp_state.fraction, - samples_to_output); + static_cast(samples_to_output)); // Resample for (std::size_t i = 0; i < AudioCommon::MAX_SAMPLE_HISTORY; i++) { - dsp_state.sample_history[i] = sample_buffer[samples_to_read + i]; + dsp_state.sample_history[i] = + sample_buffer[static_cast(samples_to_read) + i]; } } output += samples_to_output; diff --git a/src/audio_core/command_generator.h b/src/audio_core/command_generator.h index 53e57748b..6cba70ae3 100644 --- a/src/audio_core/command_generator.h +++ b/src/audio_core/command_generator.h @@ -50,12 +50,12 @@ public: private: void GenerateDataSourceCommand(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 channel); void GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voice_info, VoiceState& dsp_state, - s32 mix_buffer_count, s32 channel); + u32 mix_buffer_count, s32 channel); void GenerateVolumeRampCommand(float last_volume, float current_volume, s32 channel, s32 node_id); void GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volumes, const MixVolumeBuffer& last_mix_volumes, VoiceState& dsp_state, - s32 mix_buffer_offset, s32 mix_buffer_count, s32 voice_index, + u32 mix_buffer_offset, u32 mix_buffer_count, u32 voice_index, s32 node_id); void GenerateSubMixCommand(ServerMixInfo& mix_info); void GenerateMixCommands(ServerMixInfo& mix_info); diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp index 6eaa60815..a20b6ad5f 100644 --- a/src/audio_core/cubeb_sink.cpp +++ b/src/audio_core/cubeb_sink.cpp @@ -202,7 +202,7 @@ long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const } const std::size_t num_channels = impl->GetNumChannels(); - const std::size_t samples_to_write = num_channels * num_frames; + const std::size_t samples_to_write = num_channels * static_cast(num_frames); std::size_t samples_written; /* diff --git a/src/audio_core/cubeb_sink.h b/src/audio_core/cubeb_sink.h index 7ce850f47..c50d0b7bd 100644 --- a/src/audio_core/cubeb_sink.h +++ b/src/audio_core/cubeb_sink.h @@ -27,7 +27,7 @@ private: std::vector sink_streams; #ifdef _WIN32 - u32 com_init_result = 0; + s32 com_init_result = 0; #endif }; diff --git a/src/audio_core/info_updater.cpp b/src/audio_core/info_updater.cpp index 2940e53a9..f999a8b17 100644 --- a/src/audio_core/info_updater.cpp +++ b/src/audio_core/info_updater.cpp @@ -350,7 +350,7 @@ ResultCode InfoUpdater::UpdateMixes(MixContext& mix_context, std::size_t mix_buf std::size_t total_buffer_count{}; for (std::size_t i = 0; i < mix_count; i++) { const auto& in = mix_in_params[i]; - total_buffer_count += in.buffer_count; + total_buffer_count += static_cast(in.buffer_count); if (static_cast(in.dest_mix_id) > mix_count && in.dest_mix_id != AudioCommon::NO_MIX && in.mix_id != AudioCommon::FINAL_MIX) { LOG_ERROR( @@ -379,7 +379,7 @@ ResultCode InfoUpdater::UpdateMixes(MixContext& mix_context, std::size_t mix_buf const auto& mix_in = mix_in_params[i]; std::size_t target_mix{}; if (behavior_info.IsMixInParameterDirtyOnlyUpdateSupported()) { - target_mix = mix_in.mix_id; + target_mix = static_cast(mix_in.mix_id); } else { // Non dirty supported games just use i instead of the actual mix_id target_mix = i; diff --git a/src/audio_core/mix_context.cpp b/src/audio_core/mix_context.cpp index 4bca72eb0..c28bee453 100644 --- a/src/audio_core/mix_context.cpp +++ b/src/audio_core/mix_context.cpp @@ -62,7 +62,7 @@ void MixContext::UpdateDistancesFromFinalMix() { distance_to_final_mix = AudioCommon::NO_FINAL_MIX; break; } else { - const auto& dest_mix = GetInfo(mix_id); + const auto& dest_mix = GetInfo(static_cast(mix_id)); const auto dest_mix_distance = dest_mix.GetInParams().final_mix_distance; if (dest_mix_distance == AudioCommon::NO_FINAL_MIX) { @@ -129,7 +129,7 @@ bool MixContext::TsortInfo(SplitterContext& splitter_context) { std::size_t info_id{}; for (auto itr = sorted_list.rbegin(); itr != sorted_list.rend(); ++itr) { // Set our sorted info - sorted_info[info_id++] = &GetInfo(*itr); + sorted_info[info_id++] = &GetInfo(static_cast(*itr)); } // Calculate the mix buffer offset @@ -218,7 +218,8 @@ bool ServerMixInfo::Update(EdgeMatrix& edge_matrix, const MixInfo::InParams& mix for (std::size_t i = 0; i < effect_count; i++) { auto* effect_info = effect_context.GetInfo(i); if (effect_info->GetMixID() == in_params.mix_id) { - effect_processing_order[effect_info->GetProcessingOrder()] = static_cast(i); + const auto processing_order = static_cast(effect_info->GetProcessingOrder()); + effect_processing_order[processing_order] = static_cast(i); } } @@ -265,7 +266,7 @@ bool ServerMixInfo::UpdateConnection(EdgeMatrix& edge_matrix, const MixInfo::InP if (in_params.dest_mix_id == mix_in.dest_mix_id && in_params.splitter_id == mix_in.splitter_id && ((in_params.splitter_id == AudioCommon::NO_SPLITTER) || - !splitter_context.GetInfo(in_params.splitter_id).HasNewConnection())) { + !splitter_context.GetInfo(static_cast(in_params.splitter_id)).HasNewConnection())) { return false; } // Remove current edges for mix id @@ -275,11 +276,11 @@ bool ServerMixInfo::UpdateConnection(EdgeMatrix& edge_matrix, const MixInfo::InP edge_matrix.Connect(in_params.mix_id, mix_in.dest_mix_id); } else if (mix_in.splitter_id != AudioCommon::NO_SPLITTER) { // Recurse our splitter linked and set our edges - auto& splitter_info = splitter_context.GetInfo(mix_in.splitter_id); - const auto length = splitter_info.GetLength(); - for (s32 i = 0; i < length; i++) { + auto& splitter_info = splitter_context.GetInfo(static_cast(mix_in.splitter_id)); + const auto length = static_cast(splitter_info.GetLength()); + for (size_t i = 0; i < length; i++) { const auto* splitter_destination = - splitter_context.GetDestinationData(mix_in.splitter_id, i); + splitter_context.GetDestinationData(static_cast(mix_in.splitter_id), i); if (splitter_destination == nullptr) { continue; } diff --git a/src/audio_core/sink_context.cpp b/src/audio_core/sink_context.cpp index 0882b411a..3d713814a 100644 --- a/src/audio_core/sink_context.cpp +++ b/src/audio_core/sink_context.cpp @@ -23,8 +23,9 @@ bool SinkContext::InUse() const { } std::vector SinkContext::OutputBuffers() const { - std::vector buffer_ret(use_count); - std::memcpy(buffer_ret.data(), buffers.data(), use_count); + const auto output_use_count = static_cast(use_count); + std::vector buffer_ret(output_use_count); + std::memcpy(buffer_ret.data(), buffers.data(), output_use_count); return buffer_ret; } diff --git a/src/audio_core/splitter_context.cpp b/src/audio_core/splitter_context.cpp index f21b53147..f3e870648 100644 --- a/src/audio_core/splitter_context.cpp +++ b/src/audio_core/splitter_context.cpp @@ -109,7 +109,7 @@ std::size_t ServerSplitterInfo::Update(SplitterInfo::InInfoPrams& header) { new_connection = true; // We need to update the size here due to the splitter bug being present and providing an // incorrect size. We're suppose to also update the header here but we just ignore and continue - return (sizeof(s32_le) * (header.length - 1)) + (sizeof(s32_le) * 3); + return (sizeof(s32_le) * static_cast(header.length - 1)) + (sizeof(s32_le) * 3); } ServerSplitterDestinationData* ServerSplitterInfo::GetHead() { @@ -306,13 +306,14 @@ bool SplitterContext::UpdateInfo(const std::vector& input, std::size_t& inpu break; } - if (header.send_id < 0 || static_cast(header.send_id) > info_count) { + const auto send_id = static_cast(header.send_id); + if (header.send_id < 0 || send_id > info_count) { LOG_ERROR(Audio, "Bad splitter data id"); break; } UpdateOffsets(sizeof(SplitterInfo::InInfoPrams)); - auto& info = GetInfo(header.send_id); + auto& info = GetInfo(send_id); if (!RecomposeDestination(info, header, input, input_offset)) { LOG_ERROR(Audio, "Failed to recompose destination for splitter!"); return false; @@ -348,11 +349,12 @@ bool SplitterContext::UpdateData(const std::vector& input, std::size_t& inpu break; } - if (header.splitter_id < 0 || static_cast(header.splitter_id) > data_count) { + const auto splitter_id = static_cast(header.splitter_id); + if (header.splitter_id < 0 || splitter_id > data_count) { LOG_ERROR(Audio, "Bad splitter data id"); break; } - GetData(header.splitter_id).Update(header); + GetData(splitter_id).Update(header); } return true; } @@ -386,9 +388,9 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info, return true; } - auto* start_head = &GetData(header.resource_id_base); + auto* start_head = &GetData(static_cast(header.resource_id_base)); current_head = start_head; - std::vector resource_ids(size - 1); + std::vector resource_ids(static_cast(size - 1)); if (!AudioCommon::CanConsumeBuffer(input.size(), input_offset, resource_ids.size() * sizeof(s32_le))) { LOG_ERROR(Audio, "Buffer is an invalid size!"); @@ -397,8 +399,8 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info, std::memcpy(resource_ids.data(), input.data() + input_offset, resource_ids.size() * sizeof(s32_le)); - for (auto resource_id : resource_ids) { - auto* head = &GetData(resource_id); + for (const auto resource_id : resource_ids) { + auto* head = &GetData(static_cast(resource_id)); current_head->SetNextDestination(head); current_head = head; } @@ -444,7 +446,7 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) { const auto node_id = static_cast(i); // If we don't have a state, send to our index stack for work - if (GetState(i) == NodeStates::State::NoState) { + if (GetState(i) == State::NoState) { index_stack.push(node_id); } @@ -453,19 +455,19 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) { // Get the current node const auto current_stack_index = index_stack.top(); // Check if we've seen the node yet - const auto index_state = GetState(current_stack_index); - if (index_state == NodeStates::State::NoState) { + const auto index_state = GetState(static_cast(current_stack_index)); + if (index_state == State::NoState) { // Mark the node as seen - UpdateState(NodeStates::State::InFound, current_stack_index); - } else if (index_state == NodeStates::State::InFound) { + UpdateState(State::InFound, static_cast(current_stack_index)); + } else if (index_state == State::InFound) { // We've seen this node before, mark it as completed - UpdateState(NodeStates::State::InCompleted, current_stack_index); + UpdateState(State::InCompleted, static_cast(current_stack_index)); // Update our index list PushTsortResult(current_stack_index); // Pop the stack index_stack.pop(); continue; - } else if (index_state == NodeStates::State::InCompleted) { + } else if (index_state == State::InCompleted) { // If our node is already sorted, clear it index_stack.pop(); continue; @@ -479,11 +481,11 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) { } // Check if our node exists - const auto node_state = GetState(j); - if (node_state == NodeStates::State::NoState) { + const auto node_state = GetState(static_cast(j)); + if (node_state == State::NoState) { // Add more work index_stack.push(j); - } else if (node_state == NodeStates::State::InFound) { + } else if (node_state == State::InFound) { UNREACHABLE_MSG("Node start marked as found"); ResetState(); return false; @@ -507,17 +509,17 @@ void NodeStates::ResetState() { } } -void NodeStates::UpdateState(NodeStates::State state, std::size_t i) { +void NodeStates::UpdateState(State state, std::size_t i) { switch (state) { - case NodeStates::State::NoState: + case State::NoState: was_node_found[i] = false; was_node_completed[i] = false; break; - case NodeStates::State::InFound: + case State::InFound: was_node_found[i] = true; was_node_completed[i] = false; break; - case NodeStates::State::InCompleted: + case State::InCompleted: was_node_found[i] = false; was_node_completed[i] = true; break; @@ -528,13 +530,13 @@ NodeStates::State NodeStates::GetState(std::size_t i) { ASSERT(i < node_count); if (was_node_found[i]) { // If our node exists in our found list - return NodeStates::State::InFound; + return State::InFound; } else if (was_node_completed[i]) { // If node is in the completed list - return NodeStates::State::InCompleted; + return State::InCompleted; } else { // If in neither - return NodeStates::State::NoState; + return State::NoState; } } @@ -601,16 +603,16 @@ std::size_t EdgeMatrix::GetNodeCount() const { void EdgeMatrix::SetState(s32 a, s32 b, bool state) { ASSERT(InRange(a, b)); - edge_matrix.at(a * node_count + b) = state; + edge_matrix.at(static_cast(a) * node_count + static_cast(b)) = state; } bool EdgeMatrix::GetState(s32 a, s32 b) { ASSERT(InRange(a, b)); - return edge_matrix.at(a * node_count + b); + return edge_matrix.at(static_cast(a) * node_count + static_cast(b)); } bool EdgeMatrix::InRange(s32 a, s32 b) const { - const std::size_t pos = a * node_count + b; + const std::size_t pos = static_cast(a) * node_count + static_cast(b); return pos < (node_count * node_count); } diff --git a/src/audio_core/time_stretch.h b/src/audio_core/time_stretch.h index bb2270b96..3808e554d 100644 --- a/src/audio_core/time_stretch.h +++ b/src/audio_core/time_stretch.h @@ -5,9 +5,17 @@ #pragma once #include -#include #include "common/common_types.h" +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-conversion" +#endif +#include +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + namespace AudioCore { class TimeStretcher { diff --git a/src/audio_core/voice_context.cpp b/src/audio_core/voice_context.cpp index c46ee55f1..276b96ca4 100644 --- a/src/audio_core/voice_context.cpp +++ b/src/audio_core/voice_context.cpp @@ -98,7 +98,7 @@ void ServerVoiceInfo::UpdateParameters(const VoiceInfo::InParams& voice_in, BehaviorInfo& behavior_info) { in_params.in_use = voice_in.is_in_use; in_params.id = voice_in.id; - in_params.node_id = voice_in.node_id; + in_params.node_id = static_cast(voice_in.node_id); in_params.last_playstate = in_params.current_playstate; switch (voice_in.play_state) { case PlayState::Paused: @@ -220,8 +220,10 @@ void ServerVoiceInfo::UpdateWaveBuffer(ServerWaveBuffer& out_wavebuffer, if (sample_format == SampleFormat::Pcm16) { const auto buffer_size = in_wave_buffer.buffer_size; if (in_wave_buffer.start_sample_offset < 0 || in_wave_buffer.end_sample_offset < 0 || - (buffer_size < (sizeof(s16) * in_wave_buffer.start_sample_offset)) || - (buffer_size < (sizeof(s16) * in_wave_buffer.end_sample_offset))) { + (buffer_size < + (sizeof(s16) * static_cast(in_wave_buffer.start_sample_offset))) || + (buffer_size < + (sizeof(s16) * static_cast(in_wave_buffer.end_sample_offset)))) { // TODO(ogniK): Write error info return; } @@ -254,8 +256,8 @@ void ServerVoiceInfo::WriteOutStatus( voice_out.played_sample_count = 0; voice_out.voice_dropped = false; } else if (!in_params.is_new) { - voice_out.wave_buffer_consumed = voice_states[0]->wave_buffer_consumed; - voice_out.played_sample_count = voice_states[0]->played_sample_count; + voice_out.wave_buffer_consumed = static_cast(voice_states[0]->wave_buffer_consumed); + voice_out.played_sample_count = static_cast(voice_states[0]->played_sample_count); voice_out.voice_dropped = in_params.voice_drop_flag; } else { voice_out.wave_buffer_consumed = 0; @@ -293,8 +295,8 @@ bool ServerVoiceInfo::UpdateForCommandGeneration(VoiceContext& voice_context) { in_params.is_new = false; } - const s32 channel_count = in_params.channel_count; - for (s32 i = 0; i < channel_count; i++) { + const auto channel_count = static_cast(in_params.channel_count); + for (size_t i = 0; i < channel_count; i++) { const auto channel_resource = in_params.voice_channel_resource_id[i]; dsp_voice_states[i] = &voice_context.GetDspSharedState(static_cast(channel_resource)); @@ -303,8 +305,9 @@ bool ServerVoiceInfo::UpdateForCommandGeneration(VoiceContext& voice_context) { } void ServerVoiceInfo::ResetResources(VoiceContext& voice_context) { - const s32 channel_count = in_params.channel_count; - for (s32 i = 0; i < channel_count; i++) { + const auto channel_count = static_cast(in_params.channel_count); + + for (size_t i = 0; i < channel_count; i++) { const auto channel_resource = in_params.voice_channel_resource_id[i]; auto& dsp_state = voice_context.GetDspSharedState(static_cast(channel_resource)); @@ -325,9 +328,9 @@ bool ServerVoiceInfo::UpdateParametersForCommandGeneration( switch (in_params.current_playstate) { case ServerPlayState::Play: { - for (std::size_t i = 0; i < AudioCommon::MAX_WAVE_BUFFERS; i++) { + for (size_t i = 0; i < AudioCommon::MAX_WAVE_BUFFERS; i++) { if (!in_params.wave_buffer[i].sent_to_dsp) { - for (s32 channel = 0; channel < channel_count; channel++) { + for (size_t channel = 0; channel < static_cast(channel_count); channel++) { dsp_voice_states[channel]->is_wave_buffer_valid[i] = true; } in_params.wave_buffer[i].sent_to_dsp = true; @@ -344,12 +347,13 @@ bool ServerVoiceInfo::UpdateParametersForCommandGeneration( case ServerPlayState::RequestStop: { for (std::size_t i = 0; i < AudioCommon::MAX_WAVE_BUFFERS; i++) { in_params.wave_buffer[i].sent_to_dsp = true; - for (s32 channel = 0; channel < channel_count; channel++) { + for (std::size_t channel = 0; channel < static_cast(channel_count); channel++) { auto* dsp_state = dsp_voice_states[channel]; if (dsp_state->is_wave_buffer_valid[i]) { dsp_state->wave_buffer_index = - (dsp_state->wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS; + static_cast(static_cast(dsp_state->wave_buffer_index + 1) % + AudioCommon::MAX_WAVE_BUFFERS); dsp_state->wave_buffer_consumed++; } @@ -357,7 +361,7 @@ bool ServerVoiceInfo::UpdateParametersForCommandGeneration( } } - for (s32 channel = 0; channel < channel_count; channel++) { + for (size_t channel = 0; channel < static_cast(channel_count); channel++) { auto* dsp_state = dsp_voice_states[channel]; dsp_state->offset = 0; dsp_state->played_sample_count = 0; @@ -383,15 +387,16 @@ void ServerVoiceInfo::FlushWaveBuffers( auto wave_head = in_params.wave_bufffer_head; for (u8 i = 0; i < flush_count; i++) { - in_params.wave_buffer[wave_head].sent_to_dsp = true; - for (s32 channel = 0; channel < channel_count; channel++) { + in_params.wave_buffer[static_cast(wave_head)].sent_to_dsp = true; + for (size_t channel = 0; channel < static_cast(channel_count); channel++) { auto* dsp_state = dsp_voice_states[channel]; dsp_state->wave_buffer_consumed++; - dsp_state->is_wave_buffer_valid[wave_head] = false; - dsp_state->wave_buffer_index = - (dsp_state->wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS; + dsp_state->is_wave_buffer_valid[static_cast(wave_head)] = false; + dsp_state->wave_buffer_index = static_cast( + static_cast(dsp_state->wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS); } - wave_head = (wave_head + 1) % AudioCommon::MAX_WAVE_BUFFERS; + wave_head = + static_cast(static_cast(wave_head + 1) % AudioCommon::MAX_WAVE_BUFFERS); } } @@ -483,7 +488,7 @@ s32 VoiceContext::DecodePcm16(s32* output_buffer, ServerWaveBuffer* wave_buffer, const auto samples_remaining = (wave_buffer->end_sample_offset - wave_buffer->start_sample_offset) - buffer_offset; const auto start_offset = (wave_buffer->start_sample_offset + buffer_offset) * channel_count; - const auto buffer_pos = wave_buffer->buffer_address + start_offset; + const auto buffer_pos = wave_buffer->buffer_address + static_cast(start_offset); s16* buffer_data = reinterpret_cast(memory.GetPointer(buffer_pos)); -- cgit v1.2.3 From 3d592972dc3fd61cc88771b889eff237e4e03e0f Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 20 Oct 2020 19:07:39 -0700 Subject: Revert "core: Fix clang build" --- src/audio_core/CMakeLists.txt | 5 +- src/audio_core/algorithm/interpolate.cpp | 6 +- src/audio_core/audio_renderer.cpp | 4 +- src/audio_core/codec.cpp | 6 +- src/audio_core/command_generator.cpp | 212 ++++++++++++++----------------- src/audio_core/command_generator.h | 4 +- src/audio_core/cubeb_sink.cpp | 2 +- src/audio_core/cubeb_sink.h | 2 +- src/audio_core/info_updater.cpp | 4 +- src/audio_core/mix_context.cpp | 17 ++- src/audio_core/sink_context.cpp | 5 +- src/audio_core/splitter_context.cpp | 60 +++++---- src/audio_core/time_stretch.h | 10 +- src/audio_core/voice_context.cpp | 47 +++---- 14 files changed, 169 insertions(+), 215 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index 74c1453aa..54940a034 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt @@ -51,9 +51,8 @@ if (NOT MSVC) -Werror=implicit-fallthrough -Werror=reorder -Werror=sign-compare - -Werror=sign-conversion - $<$:-Werror=unused-but-set-parameter> - $<$:-Werror=unused-but-set-variable> + -Werror=unused-but-set-parameter + -Werror=unused-but-set-variable -Werror=unused-variable ) endif() diff --git a/src/audio_core/algorithm/interpolate.cpp b/src/audio_core/algorithm/interpolate.cpp index 587ee5b7b..699fcb84c 100644 --- a/src/audio_core/algorithm/interpolate.cpp +++ b/src/audio_core/algorithm/interpolate.cpp @@ -167,8 +167,8 @@ std::vector Interpolate(InterpolationState& state, std::vector input, output.reserve(static_cast(static_cast(input.size()) / ratio + InterpolationState::taps)); - for (std::size_t frame = 0; frame < num_frames; ++frame) { - const auto lut_index{static_cast(state.fraction >> 8) * InterpolationState::taps}; + for (std::size_t frame{}; frame < num_frames; ++frame) { + const std::size_t lut_index{(state.fraction >> 8) * InterpolationState::taps}; std::rotate(state.history.begin(), state.history.end() - 1, state.history.end()); state.history[0][0] = input[frame * 2 + 0]; @@ -225,7 +225,7 @@ void Resample(s32* output, const s32* input, s32 pitch, s32& fraction, std::size output[i] = (l0 * s0 + l1 * s1 + l2 * s2 + l3 * s3) >> 15; fraction += pitch; - index += static_cast(fraction >> 15); + index += (fraction >> 15); fraction &= 0x7fff; } } diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp index 094bace9c..a7e851bb8 100644 --- a/src/audio_core/audio_renderer.cpp +++ b/src/audio_core/audio_renderer.cpp @@ -187,8 +187,8 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) { const auto& in_params = final_mix.GetInParams(); std::vector mix_buffers(channel_count); for (std::size_t i = 0; i < channel_count; i++) { - mix_buffers[i] = command_generator.GetMixBuffer( - static_cast(in_params.buffer_offset) + buffer_offsets[i]); + mix_buffers[i] = + command_generator.GetMixBuffer(in_params.buffer_offset + buffer_offsets[i]); } for (std::size_t i = 0; i < BUFFER_SIZE; i++) { diff --git a/src/audio_core/codec.cpp b/src/audio_core/codec.cpp index d89f94ea2..2fb91c13a 100644 --- a/src/audio_core/codec.cpp +++ b/src/audio_core/codec.cpp @@ -32,7 +32,7 @@ std::vector DecodeADPCM(const u8* const data, std::size_t size, const ADPCM for (std::size_t framei = 0; framei < NUM_FRAMES; framei++) { const int frame_header = data[framei * FRAME_LEN]; const int scale = 1 << (frame_header & 0xF); - const auto idx = static_cast((frame_header >> 4) & 0x7); + const int idx = (frame_header >> 4) & 0x7; // Coefficients are fixed point with 11 bits fractional part. const int coef1 = coeff[idx * 2 + 0]; @@ -57,11 +57,11 @@ std::vector DecodeADPCM(const u8* const data, std::size_t size, const ADPCM std::size_t outputi = framei * SAMPLES_PER_FRAME; std::size_t datai = framei * FRAME_LEN + 1; for (std::size_t i = 0; i < SAMPLES_PER_FRAME && outputi < sample_count; i += 2) { - const s16 sample1 = decode_sample(SIGNED_NIBBLES[static_cast(data[datai] >> 4)]); + const s16 sample1 = decode_sample(SIGNED_NIBBLES[data[datai] >> 4]); ret[outputi] = sample1; outputi++; - const s16 sample2 = decode_sample(SIGNED_NIBBLES[static_cast(data[datai] & 0xF)]); + const s16 sample2 = decode_sample(SIGNED_NIBBLES[data[datai] & 0xF]); ret[outputi] = sample2; outputi++; diff --git a/src/audio_core/command_generator.cpp b/src/audio_core/command_generator.cpp index c0edb625d..fb8700ccf 100644 --- a/src/audio_core/command_generator.cpp +++ b/src/audio_core/command_generator.cpp @@ -15,8 +15,8 @@ constexpr std::size_t MIX_BUFFER_SIZE = 0x3f00; constexpr std::size_t SCALED_MIX_BUFFER_SIZE = MIX_BUFFER_SIZE << 15ULL; template -void ApplyMix(s32* output, const s32* input, s32 gain, std::size_t sample_count) { - for (std::size_t i = 0; i < sample_count; i += N) { +void ApplyMix(s32* output, const s32* input, s32 gain, s32 sample_count) { + for (std::size_t i = 0; i < static_cast(sample_count); i += N) { for (std::size_t j = 0; j < N; j++) { output[i + j] += static_cast((static_cast(input[i + j]) * gain + 0x4000) >> 15); @@ -111,8 +111,7 @@ void CommandGenerator::GenerateVoiceCommand(ServerVoiceInfo& voice_info) { const auto channel_count = in_params.channel_count; for (s32 channel = 0; channel < channel_count; channel++) { - const auto resource_id = - static_cast(in_params.voice_channel_resource_id[static_cast(channel)]); + const auto resource_id = in_params.voice_channel_resource_id[channel]; auto& dsp_state = voice_context.GetDspSharedState(resource_id); auto& channel_resource = voice_context.GetChannelResource(resource_id); @@ -133,15 +132,14 @@ void CommandGenerator::GenerateVoiceCommand(ServerVoiceInfo& voice_info) { if (in_params.mix_id != AudioCommon::NO_MIX) { // If we're using a mix id - auto& mix_info = mix_context.GetInfo(static_cast(in_params.mix_id)); + auto& mix_info = mix_context.GetInfo(in_params.mix_id); const auto& dest_mix_params = mix_info.GetInParams(); // Voice Mixing GenerateVoiceMixCommand( channel_resource.GetCurrentMixVolume(), channel_resource.GetLastMixVolume(), - dsp_state, static_cast(dest_mix_params.buffer_offset), - static_cast(dest_mix_params.buffer_count), - worker_params.mix_buffer_count + static_cast(channel), in_params.node_id); + dsp_state, dest_mix_params.buffer_offset, dest_mix_params.buffer_count, + worker_params.mix_buffer_count + channel, in_params.node_id); // Update last mix volumes channel_resource.UpdateLastMixVolumes(); @@ -158,15 +156,12 @@ void CommandGenerator::GenerateVoiceCommand(ServerVoiceInfo& voice_info) { continue; } - const auto& mix_info = - mix_context.GetInfo(static_cast(destination_data->GetMixId())); + const auto& mix_info = mix_context.GetInfo(destination_data->GetMixId()); const auto& dest_mix_params = mix_info.GetInParams(); GenerateVoiceMixCommand( destination_data->CurrentMixVolumes(), destination_data->LastMixVolumes(), - dsp_state, static_cast(dest_mix_params.buffer_offset), - static_cast(dest_mix_params.buffer_count), - worker_params.mix_buffer_count + static_cast(channel), - in_params.node_id); + dsp_state, dest_mix_params.buffer_offset, dest_mix_params.buffer_count, + worker_params.mix_buffer_count + channel, in_params.node_id); destination_data->MarkDirty(); } } @@ -224,10 +219,9 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo if (depop) { if (in_params.mix_id != AudioCommon::NO_MIX) { - auto& mix_info = mix_context.GetInfo(static_cast(in_params.mix_id)); + auto& mix_info = mix_context.GetInfo(in_params.mix_id); const auto& mix_in = mix_info.GetInParams(); - GenerateDepopPrepareCommand(dsp_state, static_cast(mix_in.buffer_count), - static_cast(mix_in.buffer_offset)); + GenerateDepopPrepareCommand(dsp_state, mix_in.buffer_count, mix_in.buffer_offset); } else if (in_params.splitter_info_id != AudioCommon::NO_SPLITTER) { s32 index{}; while (const auto* destination = @@ -235,24 +229,23 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo if (!destination->IsConfigured()) { continue; } - auto& mix_info = mix_context.GetInfo(static_cast(destination->GetMixId())); + auto& mix_info = mix_context.GetInfo(destination->GetMixId()); const auto& mix_in = mix_info.GetInParams(); - GenerateDepopPrepareCommand(dsp_state, static_cast(mix_in.buffer_count), - static_cast(mix_in.buffer_offset)); + GenerateDepopPrepareCommand(dsp_state, mix_in.buffer_count, mix_in.buffer_offset); } } } else { switch (in_params.sample_format) { case SampleFormat::Pcm16: DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(channel), dsp_state, channel, - static_cast(worker_params.sample_rate), - static_cast(worker_params.sample_count), in_params.node_id); + worker_params.sample_rate, worker_params.sample_count, + in_params.node_id); break; case SampleFormat::Adpcm: ASSERT(channel == 0 && in_params.channel_count == 1); DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(0), dsp_state, 0, - static_cast(worker_params.sample_rate), - static_cast(worker_params.sample_count), in_params.node_id); + worker_params.sample_rate, worker_params.sample_count, + in_params.node_id); break; default: UNREACHABLE_MSG("Unimplemented sample format={}", in_params.sample_format); @@ -262,7 +255,7 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo void CommandGenerator::GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voice_info, VoiceState& dsp_state, - u32 mix_buffer_count, s32 channel) { + s32 mix_buffer_count, s32 channel) { for (std::size_t i = 0; i < AudioCommon::MAX_BIQUAD_FILTERS; i++) { const auto& in_params = voice_info.GetInParams(); auto& biquad_filter = in_params.biquad_filter[i]; @@ -342,8 +335,8 @@ void CommandGenerator::GenerateDepopForMixBuffersCommand(std::size_t mix_buffer_ continue; } - depop_buffer[i] = ApplyMixDepop(GetMixBuffer(i), depop_buffer[i], delta, - static_cast(worker_params.sample_count)); + depop_buffer[i] = + ApplyMixDepop(GetMixBuffer(i), depop_buffer[i], delta, worker_params.sample_count); } } @@ -355,7 +348,7 @@ void CommandGenerator::GenerateEffectCommand(ServerMixInfo& mix_info) { if (index == AudioCommon::NO_EFFECT_ORDER) { break; } - auto* info = effect_context.GetInfo(static_cast(index)); + auto* info = effect_context.GetInfo(index); const auto type = info->GetType(); // TODO(ogniK): Finish remaining effects @@ -384,11 +377,11 @@ void CommandGenerator::GenerateI3dl2ReverbEffectCommand(s32 mix_buffer_offset, E } const auto& params = dynamic_cast(info)->GetParams(); const auto channel_count = params.channel_count; - for (size_t i = 0; i < channel_count; i++) { + for (s32 i = 0; i < channel_count; i++) { // TODO(ogniK): Actually implement reverb if (params.input[i] != params.output[i]) { - const auto* input = GetMixBuffer(static_cast(mix_buffer_offset + params.input[i])); - auto* output = GetMixBuffer(static_cast(mix_buffer_offset + params.output[i])); + const auto* input = GetMixBuffer(mix_buffer_offset + params.input[i]); + auto* output = GetMixBuffer(mix_buffer_offset + params.output[i]); ApplyMix<1>(output, input, 32768, worker_params.sample_count); } } @@ -399,14 +392,13 @@ void CommandGenerator::GenerateBiquadFilterEffectCommand(s32 mix_buffer_offset, if (!enabled) { return; } - const auto& params = dynamic_cast(info)->GetParams(); - const auto channel_count = static_cast(params.channel_count); - for (size_t i = 0; i < channel_count; i++) { + const auto channel_count = params.channel_count; + for (s32 i = 0; i < channel_count; i++) { // TODO(ogniK): Actually implement biquad filter if (params.input[i] != params.output[i]) { - const auto* input = GetMixBuffer(static_cast(mix_buffer_offset + params.input[i])); - auto* output = GetMixBuffer(static_cast(mix_buffer_offset + params.output[i])); + const auto* input = GetMixBuffer(mix_buffer_offset + params.input[i]); + auto* output = GetMixBuffer(mix_buffer_offset + params.output[i]); ApplyMix<1>(output, input, 32768, worker_params.sample_count); } } @@ -433,30 +425,26 @@ void CommandGenerator::GenerateAuxCommand(s32 mix_buffer_offset, EffectBase* inf memory.ReadBlock(aux->GetSendInfo(), &send_info, sizeof(AuxInfoDSP)); memory.ReadBlock(aux->GetRecvInfo(), &recv_info, sizeof(AuxInfoDSP)); - WriteAuxBuffer(send_info, aux->GetSendBuffer(), - static_cast(params.sample_count), - GetMixBuffer(static_cast(input_index)), - worker_params.sample_count, offset, write_count); + WriteAuxBuffer(send_info, aux->GetSendBuffer(), params.sample_count, + GetMixBuffer(input_index), worker_params.sample_count, offset, + write_count); memory.WriteBlock(aux->GetSendInfo(), &send_info, sizeof(AuxInfoDSP)); const auto samples_read = ReadAuxBuffer( - recv_info, aux->GetRecvBuffer(), static_cast(params.sample_count), - GetMixBuffer(static_cast(output_index)), worker_params.sample_count, - offset, write_count); + recv_info, aux->GetRecvBuffer(), params.sample_count, + GetMixBuffer(output_index), worker_params.sample_count, offset, write_count); memory.WriteBlock(aux->GetRecvInfo(), &recv_info, sizeof(AuxInfoDSP)); if (samples_read != static_cast(worker_params.sample_count) && samples_read <= params.sample_count) { - std::memset(GetMixBuffer(static_cast(output_index)), 0, - static_cast(params.sample_count - samples_read)); + std::memset(GetMixBuffer(output_index), 0, params.sample_count - samples_read); } } else { AuxInfoDSP empty{}; memory.WriteBlock(aux->GetSendInfo(), &empty, sizeof(AuxInfoDSP)); memory.WriteBlock(aux->GetRecvInfo(), &empty, sizeof(AuxInfoDSP)); if (output_index != input_index) { - std::memcpy(GetMixBuffer(static_cast(output_index)), - GetMixBuffer(static_cast(input_index)), + std::memcpy(GetMixBuffer(output_index), GetMixBuffer(input_index), worker_params.sample_count * sizeof(s32)); } } @@ -470,8 +458,7 @@ ServerSplitterDestinationData* CommandGenerator::GetDestinationData(s32 splitter if (splitter_id == AudioCommon::NO_SPLITTER) { return nullptr; } - return splitter_context.GetDestinationData(static_cast(splitter_id), - static_cast(index)); + return splitter_context.GetDestinationData(splitter_id, index); } s32 CommandGenerator::WriteAuxBuffer(AuxInfoDSP& dsp_info, VAddr send_buffer, u32 max_samples, @@ -501,7 +488,7 @@ s32 CommandGenerator::WriteAuxBuffer(AuxInfoDSP& dsp_info, VAddr send_buffer, u3 if (write_count != 0) { dsp_info.write_offset = (dsp_info.write_offset + write_count) % max_samples; } - return static_cast(sample_count); + return sample_count; } s32 CommandGenerator::ReadAuxBuffer(AuxInfoDSP& recv_info, VAddr recv_buffer, u32 max_samples, @@ -531,7 +518,7 @@ s32 CommandGenerator::ReadAuxBuffer(AuxInfoDSP& recv_info, VAddr recv_buffer, u3 if (read_count != 0) { recv_info.read_offset = (recv_info.read_offset + read_count) % max_samples; } - return static_cast(sample_count); + return sample_count; } void CommandGenerator::GenerateVolumeRampCommand(float last_volume, float current_volume, @@ -550,15 +537,15 @@ void CommandGenerator::GenerateVolumeRampCommand(float last_volume, float curren } // Apply generic gain on samples ApplyGain(GetChannelMixBuffer(channel), GetChannelMixBuffer(channel), last, delta, - static_cast(worker_params.sample_count)); + worker_params.sample_count); } void CommandGenerator::GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volumes, const MixVolumeBuffer& last_mix_volumes, - VoiceState& dsp_state, u32 mix_buffer_offset, - u32 mix_buffer_count, u32 voice_index, s32 node_id) { + VoiceState& dsp_state, s32 mix_buffer_offset, + s32 mix_buffer_count, s32 voice_index, s32 node_id) { // Loop all our mix buffers - for (size_t i = 0; i < mix_buffer_count; i++) { + for (s32 i = 0; i < mix_buffer_count; i++) { if (last_mix_volumes[i] != 0.0f || mix_volumes[i] != 0.0f) { const auto delta = static_cast((mix_volumes[i] - last_mix_volumes[i])) / static_cast(worker_params.sample_count); @@ -571,9 +558,9 @@ void CommandGenerator::GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volume mix_volumes[i]); } - dsp_state.previous_samples[i] = ApplyMixRamp( - GetMixBuffer(mix_buffer_offset + i), GetMixBuffer(voice_index), last_mix_volumes[i], - delta, static_cast(worker_params.sample_count)); + dsp_state.previous_samples[i] = + ApplyMixRamp(GetMixBuffer(mix_buffer_offset + i), GetMixBuffer(voice_index), + last_mix_volumes[i], delta, worker_params.sample_count); } else { dsp_state.previous_samples[i] = 0; } @@ -585,8 +572,7 @@ void CommandGenerator::GenerateSubMixCommand(ServerMixInfo& mix_info) { LOG_DEBUG(Audio, "(DSP_TRACE) GenerateSubMixCommand"); } const auto& in_params = mix_info.GetInParams(); - GenerateDepopForMixBuffersCommand(static_cast(in_params.buffer_count), - static_cast(in_params.buffer_offset), + GenerateDepopForMixBuffersCommand(in_params.buffer_count, in_params.buffer_offset, in_params.sample_rate); GenerateEffectCommand(mix_info); @@ -600,18 +586,18 @@ void CommandGenerator::GenerateMixCommands(ServerMixInfo& mix_info) { } const auto& in_params = mix_info.GetInParams(); if (in_params.dest_mix_id != AudioCommon::NO_MIX) { - const auto& dest_mix = mix_context.GetInfo(static_cast(in_params.dest_mix_id)); + const auto& dest_mix = mix_context.GetInfo(in_params.dest_mix_id); const auto& dest_in_params = dest_mix.GetInParams(); - const auto buffer_count = static_cast(in_params.buffer_count); + const auto buffer_count = in_params.buffer_count; - for (u32 i = 0; i < buffer_count; i++) { - for (u32 j = 0; j < static_cast(dest_in_params.buffer_count); j++) { + for (s32 i = 0; i < buffer_count; i++) { + for (s32 j = 0; j < dest_in_params.buffer_count; j++) { const auto mixed_volume = in_params.volume * in_params.mix_volume[i][j]; if (mixed_volume != 0.0f) { - GenerateMixCommand(static_cast(dest_in_params.buffer_offset) + j, - static_cast(in_params.buffer_offset) + i, - mixed_volume, static_cast(in_params.node_id)); + GenerateMixCommand(dest_in_params.buffer_offset + j, + in_params.buffer_offset + i, mixed_volume, + in_params.node_id); } } } @@ -622,17 +608,15 @@ void CommandGenerator::GenerateMixCommands(ServerMixInfo& mix_info) { continue; } - const auto& dest_mix = - mix_context.GetInfo(static_cast(destination_data->GetMixId())); + const auto& dest_mix = mix_context.GetInfo(destination_data->GetMixId()); const auto& dest_in_params = dest_mix.GetInParams(); const auto mix_index = (base - 1) % in_params.buffer_count + in_params.buffer_offset; for (std::size_t i = 0; i < static_cast(dest_in_params.buffer_count); i++) { const auto mixed_volume = in_params.volume * destination_data->GetMixVolume(i); if (mixed_volume != 0.0f) { - GenerateMixCommand(static_cast(dest_in_params.buffer_offset) + i, - static_cast(mix_index), mixed_volume, - static_cast(in_params.node_id)); + GenerateMixCommand(dest_in_params.buffer_offset + i, mix_index, mixed_volume, + in_params.node_id); } } } @@ -651,8 +635,7 @@ void CommandGenerator::GenerateMixCommand(std::size_t output_offset, std::size_t auto* output = GetMixBuffer(output_offset); const auto* input = GetMixBuffer(input_offset); - const auto gain = static_cast(volume * 32768.0f); - + const s32 gain = static_cast(volume * 32768.0f); // Mix with loop unrolling if (worker_params.sample_count % 4 == 0) { ApplyMix<4>(output, input, gain, worker_params.sample_count); @@ -670,8 +653,7 @@ void CommandGenerator::GenerateFinalMixCommand() { auto& mix_info = mix_context.GetFinalMixInfo(); const auto& in_params = mix_info.GetInParams(); - GenerateDepopForMixBuffersCommand(static_cast(in_params.buffer_count), - static_cast(in_params.buffer_offset), + GenerateDepopForMixBuffersCommand(in_params.buffer_count, in_params.buffer_offset, in_params.sample_rate); GenerateEffectCommand(mix_info); @@ -685,16 +667,16 @@ void CommandGenerator::GenerateFinalMixCommand() { in_params.node_id, in_params.buffer_offset + i, in_params.buffer_offset + i, in_params.volume); } - ApplyGainWithoutDelta(GetMixBuffer(static_cast(in_params.buffer_offset + i)), - GetMixBuffer(static_cast(in_params.buffer_offset + i)), gain, - static_cast(worker_params.sample_count)); + ApplyGainWithoutDelta(GetMixBuffer(in_params.buffer_offset + i), + GetMixBuffer(in_params.buffer_offset + i), gain, + worker_params.sample_count); } } s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 sample_count, s32 channel, std::size_t mix_offset) { const auto& in_params = voice_info.GetInParams(); - const auto& wave_buffer = in_params.wave_buffer[static_cast(dsp_state.wave_buffer_index)]; + const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index]; if (wave_buffer.buffer_address == 0) { return 0; } @@ -707,26 +689,24 @@ s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_s const auto samples_remaining = (wave_buffer.end_sample_offset - wave_buffer.start_sample_offset) - dsp_state.offset; const auto start_offset = - static_cast((wave_buffer.start_sample_offset + dsp_state.offset) * - in_params.channel_count) * + ((wave_buffer.start_sample_offset + dsp_state.offset) * in_params.channel_count) * sizeof(s16); const auto buffer_pos = wave_buffer.buffer_address + start_offset; const auto samples_processed = std::min(sample_count, samples_remaining); if (in_params.channel_count == 1) { - std::vector buffer(static_cast(samples_processed)); + std::vector buffer(samples_processed); memory.ReadBlock(buffer_pos, buffer.data(), buffer.size() * sizeof(s16)); for (std::size_t i = 0; i < buffer.size(); i++) { sample_buffer[mix_offset + i] = buffer[i]; } } else { const auto channel_count = in_params.channel_count; - std::vector buffer(static_cast(samples_processed * channel_count)); + std::vector buffer(samples_processed * channel_count); memory.ReadBlock(buffer_pos, buffer.data(), buffer.size() * sizeof(s16)); for (std::size_t i = 0; i < static_cast(samples_processed); i++) { - sample_buffer[mix_offset + i] = - buffer[i * static_cast(channel_count) + static_cast(channel)]; + sample_buffer[mix_offset + i] = buffer[i * channel_count + channel]; } } @@ -736,7 +716,7 @@ s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_s s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 sample_count, s32 channel, std::size_t mix_offset) { const auto& in_params = voice_info.GetInParams(); - const auto& wave_buffer = in_params.wave_buffer[static_cast(dsp_state.wave_buffer_index)]; + const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index]; if (wave_buffer.buffer_address == 0) { return 0; } @@ -756,7 +736,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s constexpr std::size_t SAMPLES_PER_FRAME = 14; auto frame_header = dsp_state.context.header; - auto idx = static_cast((frame_header >> 4) & 0xf); + s32 idx = (frame_header >> 4) & 0xf; s32 scale = frame_header & 0xf; s16 yn1 = dsp_state.context.yn1; s16 yn2 = dsp_state.context.yn2; @@ -773,10 +753,9 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s const auto samples_processed = std::min(sample_count, samples_remaining); const auto sample_pos = wave_buffer.start_sample_offset + dsp_state.offset; - const auto samples_remaining_in_frame = static_cast(sample_pos) % SAMPLES_PER_FRAME; - auto position_in_frame = - ((static_cast(sample_pos) / SAMPLES_PER_FRAME) * NIBBLES_PER_SAMPLE) + - samples_remaining_in_frame + (samples_remaining_in_frame != 0 ? 2 : 0); + const auto samples_remaining_in_frame = sample_pos % SAMPLES_PER_FRAME; + auto position_in_frame = ((sample_pos / SAMPLES_PER_FRAME) * NIBBLES_PER_SAMPLE) + + samples_remaining_in_frame + (samples_remaining_in_frame != 0 ? 2 : 0); const auto decode_sample = [&](const int nibble) -> s16 { const int xn = nibble * (1 << scale); @@ -795,7 +774,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s std::size_t buffer_offset{}; std::vector buffer( - std::max((static_cast(samples_processed) / FRAME_LEN) * SAMPLES_PER_FRAME, FRAME_LEN)); + std::max((samples_processed / FRAME_LEN) * SAMPLES_PER_FRAME, FRAME_LEN)); memory.ReadBlock(wave_buffer.buffer_address + (position_in_frame / 2), buffer.data(), buffer.size()); std::size_t cur_mix_offset = mix_offset; @@ -805,7 +784,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s if (position_in_frame % NIBBLES_PER_SAMPLE == 0) { // Read header frame_header = buffer[buffer_offset++]; - idx = static_cast((frame_header >> 4) & 0xf); + idx = (frame_header >> 4) & 0xf; scale = frame_header & 0xf; coef1 = coeffs[idx * 2]; coef2 = coeffs[idx * 2 + 1]; @@ -815,8 +794,8 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s if (remaining_samples >= static_cast(SAMPLES_PER_FRAME)) { for (std::size_t i = 0; i < SAMPLES_PER_FRAME / 2; i++) { // Sample 1 - const s32 s0 = SIGNED_NIBBLES[static_cast(buffer[buffer_offset] >> 4)]; - const s32 s1 = SIGNED_NIBBLES[static_cast(buffer[buffer_offset++] & 0xf)]; + const s32 s0 = SIGNED_NIBBLES[buffer[buffer_offset] >> 4]; + const s32 s1 = SIGNED_NIBBLES[buffer[buffer_offset++] & 0xf]; const s16 sample_1 = decode_sample(s0); const s16 sample_2 = decode_sample(s1); sample_buffer[cur_mix_offset++] = sample_1; @@ -828,14 +807,14 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s } } // Decode mid frame - auto current_nibble = static_cast(buffer[buffer_offset]); - if ((position_in_frame++ & 1) != 0) { + s32 current_nibble = buffer[buffer_offset]; + if (position_in_frame++ & 0x1) { current_nibble &= 0xf; buffer_offset++; } else { current_nibble >>= 4; } - const s16 sample = decode_sample(SIGNED_NIBBLES[static_cast(current_nibble)]); + const s16 sample = decode_sample(SIGNED_NIBBLES[current_nibble]); sample_buffer[cur_mix_offset++] = sample; remaining_samples--; } @@ -856,7 +835,7 @@ const s32* CommandGenerator::GetMixBuffer(std::size_t index) const { } std::size_t CommandGenerator::GetMixChannelBufferOffset(s32 channel) const { - return worker_params.mix_buffer_count + static_cast(channel); + return worker_params.mix_buffer_count + channel; } std::size_t CommandGenerator::GetTotalMixBufferCount() const { @@ -864,11 +843,11 @@ std::size_t CommandGenerator::GetTotalMixBufferCount() const { } s32* CommandGenerator::GetChannelMixBuffer(s32 channel) { - return GetMixBuffer(worker_params.mix_buffer_count + static_cast(channel)); + return GetMixBuffer(worker_params.mix_buffer_count + channel); } const s32* CommandGenerator::GetChannelMixBuffer(s32 channel) const { - return GetMixBuffer(worker_params.mix_buffer_count + static_cast(channel)); + return GetMixBuffer(worker_params.mix_buffer_count + channel); } void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* output, @@ -916,10 +895,9 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o s32 samples_read{}; while (samples_read < samples_to_read) { - const auto& wave_buffer = - in_params.wave_buffer[static_cast(dsp_state.wave_buffer_index)]; + const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index]; // No more data can be read - if (!dsp_state.is_wave_buffer_valid[static_cast(dsp_state.wave_buffer_index)]) { + if (!dsp_state.is_wave_buffer_valid[dsp_state.wave_buffer_index]) { is_buffer_completed = true; break; } @@ -943,7 +921,7 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o UNREACHABLE_MSG("Unimplemented sample format={}", in_params.sample_format); } - temp_mix_offset += static_cast(samples_decoded); + temp_mix_offset += samples_decoded; samples_read += samples_decoded; dsp_state.offset += samples_decoded; dsp_state.played_sample_count += samples_decoded; @@ -966,12 +944,10 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o } else { // Update our wave buffer states - dsp_state.is_wave_buffer_valid[static_cast(dsp_state.wave_buffer_index)] = - false; + dsp_state.is_wave_buffer_valid[dsp_state.wave_buffer_index] = false; dsp_state.wave_buffer_consumed++; dsp_state.wave_buffer_index = - static_cast(dsp_state.wave_buffer_index + 1) % - AudioCommon::MAX_WAVE_BUFFERS; + (dsp_state.wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS; if (wave_buffer.end_of_stream) { dsp_state.played_sample_count = 0; } @@ -981,20 +957,16 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o if (in_params.behavior_flags.is_pitch_and_src_skipped.Value()) { // No need to resample - std::memcpy(output, sample_buffer.data(), - static_cast(samples_read) * sizeof(s32)); + std::memcpy(output, sample_buffer.data(), samples_read * sizeof(s32)); } else { - { - const auto begin = sample_buffer.begin() + static_cast(temp_mix_offset); - const auto end = begin + (samples_to_read - samples_read); - std::fill(begin, end, 0); - } + std::fill(sample_buffer.begin() + temp_mix_offset, + sample_buffer.begin() + temp_mix_offset + (samples_to_read - samples_read), + 0); AudioCore::Resample(output, sample_buffer.data(), resample_rate, dsp_state.fraction, - static_cast(samples_to_output)); + samples_to_output); // Resample for (std::size_t i = 0; i < AudioCommon::MAX_SAMPLE_HISTORY; i++) { - dsp_state.sample_history[i] = - sample_buffer[static_cast(samples_to_read) + i]; + dsp_state.sample_history[i] = sample_buffer[samples_to_read + i]; } } output += samples_to_output; diff --git a/src/audio_core/command_generator.h b/src/audio_core/command_generator.h index 6cba70ae3..53e57748b 100644 --- a/src/audio_core/command_generator.h +++ b/src/audio_core/command_generator.h @@ -50,12 +50,12 @@ public: private: void GenerateDataSourceCommand(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 channel); void GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voice_info, VoiceState& dsp_state, - u32 mix_buffer_count, s32 channel); + s32 mix_buffer_count, s32 channel); void GenerateVolumeRampCommand(float last_volume, float current_volume, s32 channel, s32 node_id); void GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volumes, const MixVolumeBuffer& last_mix_volumes, VoiceState& dsp_state, - u32 mix_buffer_offset, u32 mix_buffer_count, u32 voice_index, + s32 mix_buffer_offset, s32 mix_buffer_count, s32 voice_index, s32 node_id); void GenerateSubMixCommand(ServerMixInfo& mix_info); void GenerateMixCommands(ServerMixInfo& mix_info); diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp index a20b6ad5f..6eaa60815 100644 --- a/src/audio_core/cubeb_sink.cpp +++ b/src/audio_core/cubeb_sink.cpp @@ -202,7 +202,7 @@ long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const } const std::size_t num_channels = impl->GetNumChannels(); - const std::size_t samples_to_write = num_channels * static_cast(num_frames); + const std::size_t samples_to_write = num_channels * num_frames; std::size_t samples_written; /* diff --git a/src/audio_core/cubeb_sink.h b/src/audio_core/cubeb_sink.h index c50d0b7bd..7ce850f47 100644 --- a/src/audio_core/cubeb_sink.h +++ b/src/audio_core/cubeb_sink.h @@ -27,7 +27,7 @@ private: std::vector sink_streams; #ifdef _WIN32 - s32 com_init_result = 0; + u32 com_init_result = 0; #endif }; diff --git a/src/audio_core/info_updater.cpp b/src/audio_core/info_updater.cpp index f999a8b17..2940e53a9 100644 --- a/src/audio_core/info_updater.cpp +++ b/src/audio_core/info_updater.cpp @@ -350,7 +350,7 @@ ResultCode InfoUpdater::UpdateMixes(MixContext& mix_context, std::size_t mix_buf std::size_t total_buffer_count{}; for (std::size_t i = 0; i < mix_count; i++) { const auto& in = mix_in_params[i]; - total_buffer_count += static_cast(in.buffer_count); + total_buffer_count += in.buffer_count; if (static_cast(in.dest_mix_id) > mix_count && in.dest_mix_id != AudioCommon::NO_MIX && in.mix_id != AudioCommon::FINAL_MIX) { LOG_ERROR( @@ -379,7 +379,7 @@ ResultCode InfoUpdater::UpdateMixes(MixContext& mix_context, std::size_t mix_buf const auto& mix_in = mix_in_params[i]; std::size_t target_mix{}; if (behavior_info.IsMixInParameterDirtyOnlyUpdateSupported()) { - target_mix = static_cast(mix_in.mix_id); + target_mix = mix_in.mix_id; } else { // Non dirty supported games just use i instead of the actual mix_id target_mix = i; diff --git a/src/audio_core/mix_context.cpp b/src/audio_core/mix_context.cpp index c28bee453..4bca72eb0 100644 --- a/src/audio_core/mix_context.cpp +++ b/src/audio_core/mix_context.cpp @@ -62,7 +62,7 @@ void MixContext::UpdateDistancesFromFinalMix() { distance_to_final_mix = AudioCommon::NO_FINAL_MIX; break; } else { - const auto& dest_mix = GetInfo(static_cast(mix_id)); + const auto& dest_mix = GetInfo(mix_id); const auto dest_mix_distance = dest_mix.GetInParams().final_mix_distance; if (dest_mix_distance == AudioCommon::NO_FINAL_MIX) { @@ -129,7 +129,7 @@ bool MixContext::TsortInfo(SplitterContext& splitter_context) { std::size_t info_id{}; for (auto itr = sorted_list.rbegin(); itr != sorted_list.rend(); ++itr) { // Set our sorted info - sorted_info[info_id++] = &GetInfo(static_cast(*itr)); + sorted_info[info_id++] = &GetInfo(*itr); } // Calculate the mix buffer offset @@ -218,8 +218,7 @@ bool ServerMixInfo::Update(EdgeMatrix& edge_matrix, const MixInfo::InParams& mix for (std::size_t i = 0; i < effect_count; i++) { auto* effect_info = effect_context.GetInfo(i); if (effect_info->GetMixID() == in_params.mix_id) { - const auto processing_order = static_cast(effect_info->GetProcessingOrder()); - effect_processing_order[processing_order] = static_cast(i); + effect_processing_order[effect_info->GetProcessingOrder()] = static_cast(i); } } @@ -266,7 +265,7 @@ bool ServerMixInfo::UpdateConnection(EdgeMatrix& edge_matrix, const MixInfo::InP if (in_params.dest_mix_id == mix_in.dest_mix_id && in_params.splitter_id == mix_in.splitter_id && ((in_params.splitter_id == AudioCommon::NO_SPLITTER) || - !splitter_context.GetInfo(static_cast(in_params.splitter_id)).HasNewConnection())) { + !splitter_context.GetInfo(in_params.splitter_id).HasNewConnection())) { return false; } // Remove current edges for mix id @@ -276,11 +275,11 @@ bool ServerMixInfo::UpdateConnection(EdgeMatrix& edge_matrix, const MixInfo::InP edge_matrix.Connect(in_params.mix_id, mix_in.dest_mix_id); } else if (mix_in.splitter_id != AudioCommon::NO_SPLITTER) { // Recurse our splitter linked and set our edges - auto& splitter_info = splitter_context.GetInfo(static_cast(mix_in.splitter_id)); - const auto length = static_cast(splitter_info.GetLength()); - for (size_t i = 0; i < length; i++) { + auto& splitter_info = splitter_context.GetInfo(mix_in.splitter_id); + const auto length = splitter_info.GetLength(); + for (s32 i = 0; i < length; i++) { const auto* splitter_destination = - splitter_context.GetDestinationData(static_cast(mix_in.splitter_id), i); + splitter_context.GetDestinationData(mix_in.splitter_id, i); if (splitter_destination == nullptr) { continue; } diff --git a/src/audio_core/sink_context.cpp b/src/audio_core/sink_context.cpp index 3d713814a..0882b411a 100644 --- a/src/audio_core/sink_context.cpp +++ b/src/audio_core/sink_context.cpp @@ -23,9 +23,8 @@ bool SinkContext::InUse() const { } std::vector SinkContext::OutputBuffers() const { - const auto output_use_count = static_cast(use_count); - std::vector buffer_ret(output_use_count); - std::memcpy(buffer_ret.data(), buffers.data(), output_use_count); + std::vector buffer_ret(use_count); + std::memcpy(buffer_ret.data(), buffers.data(), use_count); return buffer_ret; } diff --git a/src/audio_core/splitter_context.cpp b/src/audio_core/splitter_context.cpp index f3e870648..f21b53147 100644 --- a/src/audio_core/splitter_context.cpp +++ b/src/audio_core/splitter_context.cpp @@ -109,7 +109,7 @@ std::size_t ServerSplitterInfo::Update(SplitterInfo::InInfoPrams& header) { new_connection = true; // We need to update the size here due to the splitter bug being present and providing an // incorrect size. We're suppose to also update the header here but we just ignore and continue - return (sizeof(s32_le) * static_cast(header.length - 1)) + (sizeof(s32_le) * 3); + return (sizeof(s32_le) * (header.length - 1)) + (sizeof(s32_le) * 3); } ServerSplitterDestinationData* ServerSplitterInfo::GetHead() { @@ -306,14 +306,13 @@ bool SplitterContext::UpdateInfo(const std::vector& input, std::size_t& inpu break; } - const auto send_id = static_cast(header.send_id); - if (header.send_id < 0 || send_id > info_count) { + if (header.send_id < 0 || static_cast(header.send_id) > info_count) { LOG_ERROR(Audio, "Bad splitter data id"); break; } UpdateOffsets(sizeof(SplitterInfo::InInfoPrams)); - auto& info = GetInfo(send_id); + auto& info = GetInfo(header.send_id); if (!RecomposeDestination(info, header, input, input_offset)) { LOG_ERROR(Audio, "Failed to recompose destination for splitter!"); return false; @@ -349,12 +348,11 @@ bool SplitterContext::UpdateData(const std::vector& input, std::size_t& inpu break; } - const auto splitter_id = static_cast(header.splitter_id); - if (header.splitter_id < 0 || splitter_id > data_count) { + if (header.splitter_id < 0 || static_cast(header.splitter_id) > data_count) { LOG_ERROR(Audio, "Bad splitter data id"); break; } - GetData(splitter_id).Update(header); + GetData(header.splitter_id).Update(header); } return true; } @@ -388,9 +386,9 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info, return true; } - auto* start_head = &GetData(static_cast(header.resource_id_base)); + auto* start_head = &GetData(header.resource_id_base); current_head = start_head; - std::vector resource_ids(static_cast(size - 1)); + std::vector resource_ids(size - 1); if (!AudioCommon::CanConsumeBuffer(input.size(), input_offset, resource_ids.size() * sizeof(s32_le))) { LOG_ERROR(Audio, "Buffer is an invalid size!"); @@ -399,8 +397,8 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info, std::memcpy(resource_ids.data(), input.data() + input_offset, resource_ids.size() * sizeof(s32_le)); - for (const auto resource_id : resource_ids) { - auto* head = &GetData(static_cast(resource_id)); + for (auto resource_id : resource_ids) { + auto* head = &GetData(resource_id); current_head->SetNextDestination(head); current_head = head; } @@ -446,7 +444,7 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) { const auto node_id = static_cast(i); // If we don't have a state, send to our index stack for work - if (GetState(i) == State::NoState) { + if (GetState(i) == NodeStates::State::NoState) { index_stack.push(node_id); } @@ -455,19 +453,19 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) { // Get the current node const auto current_stack_index = index_stack.top(); // Check if we've seen the node yet - const auto index_state = GetState(static_cast(current_stack_index)); - if (index_state == State::NoState) { + const auto index_state = GetState(current_stack_index); + if (index_state == NodeStates::State::NoState) { // Mark the node as seen - UpdateState(State::InFound, static_cast(current_stack_index)); - } else if (index_state == State::InFound) { + UpdateState(NodeStates::State::InFound, current_stack_index); + } else if (index_state == NodeStates::State::InFound) { // We've seen this node before, mark it as completed - UpdateState(State::InCompleted, static_cast(current_stack_index)); + UpdateState(NodeStates::State::InCompleted, current_stack_index); // Update our index list PushTsortResult(current_stack_index); // Pop the stack index_stack.pop(); continue; - } else if (index_state == State::InCompleted) { + } else if (index_state == NodeStates::State::InCompleted) { // If our node is already sorted, clear it index_stack.pop(); continue; @@ -481,11 +479,11 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) { } // Check if our node exists - const auto node_state = GetState(static_cast(j)); - if (node_state == State::NoState) { + const auto node_state = GetState(j); + if (node_state == NodeStates::State::NoState) { // Add more work index_stack.push(j); - } else if (node_state == State::InFound) { + } else if (node_state == NodeStates::State::InFound) { UNREACHABLE_MSG("Node start marked as found"); ResetState(); return false; @@ -509,17 +507,17 @@ void NodeStates::ResetState() { } } -void NodeStates::UpdateState(State state, std::size_t i) { +void NodeStates::UpdateState(NodeStates::State state, std::size_t i) { switch (state) { - case State::NoState: + case NodeStates::State::NoState: was_node_found[i] = false; was_node_completed[i] = false; break; - case State::InFound: + case NodeStates::State::InFound: was_node_found[i] = true; was_node_completed[i] = false; break; - case State::InCompleted: + case NodeStates::State::InCompleted: was_node_found[i] = false; was_node_completed[i] = true; break; @@ -530,13 +528,13 @@ NodeStates::State NodeStates::GetState(std::size_t i) { ASSERT(i < node_count); if (was_node_found[i]) { // If our node exists in our found list - return State::InFound; + return NodeStates::State::InFound; } else if (was_node_completed[i]) { // If node is in the completed list - return State::InCompleted; + return NodeStates::State::InCompleted; } else { // If in neither - return State::NoState; + return NodeStates::State::NoState; } } @@ -603,16 +601,16 @@ std::size_t EdgeMatrix::GetNodeCount() const { void EdgeMatrix::SetState(s32 a, s32 b, bool state) { ASSERT(InRange(a, b)); - edge_matrix.at(static_cast(a) * node_count + static_cast(b)) = state; + edge_matrix.at(a * node_count + b) = state; } bool EdgeMatrix::GetState(s32 a, s32 b) { ASSERT(InRange(a, b)); - return edge_matrix.at(static_cast(a) * node_count + static_cast(b)); + return edge_matrix.at(a * node_count + b); } bool EdgeMatrix::InRange(s32 a, s32 b) const { - const std::size_t pos = static_cast(a) * node_count + static_cast(b); + const std::size_t pos = a * node_count + b; return pos < (node_count * node_count); } diff --git a/src/audio_core/time_stretch.h b/src/audio_core/time_stretch.h index 3808e554d..bb2270b96 100644 --- a/src/audio_core/time_stretch.h +++ b/src/audio_core/time_stretch.h @@ -5,16 +5,8 @@ #pragma once #include -#include "common/common_types.h" - -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsign-conversion" -#endif #include -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif +#include "common/common_types.h" namespace AudioCore { diff --git a/src/audio_core/voice_context.cpp b/src/audio_core/voice_context.cpp index 276b96ca4..c46ee55f1 100644 --- a/src/audio_core/voice_context.cpp +++ b/src/audio_core/voice_context.cpp @@ -98,7 +98,7 @@ void ServerVoiceInfo::UpdateParameters(const VoiceInfo::InParams& voice_in, BehaviorInfo& behavior_info) { in_params.in_use = voice_in.is_in_use; in_params.id = voice_in.id; - in_params.node_id = static_cast(voice_in.node_id); + in_params.node_id = voice_in.node_id; in_params.last_playstate = in_params.current_playstate; switch (voice_in.play_state) { case PlayState::Paused: @@ -220,10 +220,8 @@ void ServerVoiceInfo::UpdateWaveBuffer(ServerWaveBuffer& out_wavebuffer, if (sample_format == SampleFormat::Pcm16) { const auto buffer_size = in_wave_buffer.buffer_size; if (in_wave_buffer.start_sample_offset < 0 || in_wave_buffer.end_sample_offset < 0 || - (buffer_size < - (sizeof(s16) * static_cast(in_wave_buffer.start_sample_offset))) || - (buffer_size < - (sizeof(s16) * static_cast(in_wave_buffer.end_sample_offset)))) { + (buffer_size < (sizeof(s16) * in_wave_buffer.start_sample_offset)) || + (buffer_size < (sizeof(s16) * in_wave_buffer.end_sample_offset))) { // TODO(ogniK): Write error info return; } @@ -256,8 +254,8 @@ void ServerVoiceInfo::WriteOutStatus( voice_out.played_sample_count = 0; voice_out.voice_dropped = false; } else if (!in_params.is_new) { - voice_out.wave_buffer_consumed = static_cast(voice_states[0]->wave_buffer_consumed); - voice_out.played_sample_count = static_cast(voice_states[0]->played_sample_count); + voice_out.wave_buffer_consumed = voice_states[0]->wave_buffer_consumed; + voice_out.played_sample_count = voice_states[0]->played_sample_count; voice_out.voice_dropped = in_params.voice_drop_flag; } else { voice_out.wave_buffer_consumed = 0; @@ -295,8 +293,8 @@ bool ServerVoiceInfo::UpdateForCommandGeneration(VoiceContext& voice_context) { in_params.is_new = false; } - const auto channel_count = static_cast(in_params.channel_count); - for (size_t i = 0; i < channel_count; i++) { + const s32 channel_count = in_params.channel_count; + for (s32 i = 0; i < channel_count; i++) { const auto channel_resource = in_params.voice_channel_resource_id[i]; dsp_voice_states[i] = &voice_context.GetDspSharedState(static_cast(channel_resource)); @@ -305,9 +303,8 @@ bool ServerVoiceInfo::UpdateForCommandGeneration(VoiceContext& voice_context) { } void ServerVoiceInfo::ResetResources(VoiceContext& voice_context) { - const auto channel_count = static_cast(in_params.channel_count); - - for (size_t i = 0; i < channel_count; i++) { + const s32 channel_count = in_params.channel_count; + for (s32 i = 0; i < channel_count; i++) { const auto channel_resource = in_params.voice_channel_resource_id[i]; auto& dsp_state = voice_context.GetDspSharedState(static_cast(channel_resource)); @@ -328,9 +325,9 @@ bool ServerVoiceInfo::UpdateParametersForCommandGeneration( switch (in_params.current_playstate) { case ServerPlayState::Play: { - for (size_t i = 0; i < AudioCommon::MAX_WAVE_BUFFERS; i++) { + for (std::size_t i = 0; i < AudioCommon::MAX_WAVE_BUFFERS; i++) { if (!in_params.wave_buffer[i].sent_to_dsp) { - for (size_t channel = 0; channel < static_cast(channel_count); channel++) { + for (s32 channel = 0; channel < channel_count; channel++) { dsp_voice_states[channel]->is_wave_buffer_valid[i] = true; } in_params.wave_buffer[i].sent_to_dsp = true; @@ -347,13 +344,12 @@ bool ServerVoiceInfo::UpdateParametersForCommandGeneration( case ServerPlayState::RequestStop: { for (std::size_t i = 0; i < AudioCommon::MAX_WAVE_BUFFERS; i++) { in_params.wave_buffer[i].sent_to_dsp = true; - for (std::size_t channel = 0; channel < static_cast(channel_count); channel++) { + for (s32 channel = 0; channel < channel_count; channel++) { auto* dsp_state = dsp_voice_states[channel]; if (dsp_state->is_wave_buffer_valid[i]) { dsp_state->wave_buffer_index = - static_cast(static_cast(dsp_state->wave_buffer_index + 1) % - AudioCommon::MAX_WAVE_BUFFERS); + (dsp_state->wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS; dsp_state->wave_buffer_consumed++; } @@ -361,7 +357,7 @@ bool ServerVoiceInfo::UpdateParametersForCommandGeneration( } } - for (size_t channel = 0; channel < static_cast(channel_count); channel++) { + for (s32 channel = 0; channel < channel_count; channel++) { auto* dsp_state = dsp_voice_states[channel]; dsp_state->offset = 0; dsp_state->played_sample_count = 0; @@ -387,16 +383,15 @@ void ServerVoiceInfo::FlushWaveBuffers( auto wave_head = in_params.wave_bufffer_head; for (u8 i = 0; i < flush_count; i++) { - in_params.wave_buffer[static_cast(wave_head)].sent_to_dsp = true; - for (size_t channel = 0; channel < static_cast(channel_count); channel++) { + in_params.wave_buffer[wave_head].sent_to_dsp = true; + for (s32 channel = 0; channel < channel_count; channel++) { auto* dsp_state = dsp_voice_states[channel]; dsp_state->wave_buffer_consumed++; - dsp_state->is_wave_buffer_valid[static_cast(wave_head)] = false; - dsp_state->wave_buffer_index = static_cast( - static_cast(dsp_state->wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS); + dsp_state->is_wave_buffer_valid[wave_head] = false; + dsp_state->wave_buffer_index = + (dsp_state->wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS; } - wave_head = - static_cast(static_cast(wave_head + 1) % AudioCommon::MAX_WAVE_BUFFERS); + wave_head = (wave_head + 1) % AudioCommon::MAX_WAVE_BUFFERS; } } @@ -488,7 +483,7 @@ s32 VoiceContext::DecodePcm16(s32* output_buffer, ServerWaveBuffer* wave_buffer, const auto samples_remaining = (wave_buffer->end_sample_offset - wave_buffer->start_sample_offset) - buffer_offset; const auto start_offset = (wave_buffer->start_sample_offset + buffer_offset) * channel_count; - const auto buffer_pos = wave_buffer->buffer_address + static_cast(start_offset); + const auto buffer_pos = wave_buffer->buffer_address + start_offset; s16* buffer_data = reinterpret_cast(memory.GetPointer(buffer_pos)); -- cgit v1.2.3 From e408bd3b7ce0f584475da88a770319bccca780b4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 20 Oct 2020 22:15:59 -0400 Subject: core: Fix clang build pt.2 Resolves the clang build issue in a more unintrusive way. --- src/audio_core/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index 54940a034..68c67507b 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt @@ -51,9 +51,12 @@ if (NOT MSVC) -Werror=implicit-fallthrough -Werror=reorder -Werror=sign-compare - -Werror=unused-but-set-parameter - -Werror=unused-but-set-variable -Werror=unused-variable + + $<$:-Werror=unused-but-set-parameter> + $<$:-Werror=unused-but-set-variable> + + -Wno-sign-conversion ) endif() -- cgit v1.2.3 From 9a4beac95a0f88ec312a28d06da8270aa58736e3 Mon Sep 17 00:00:00 2001 From: Chloe Marcec Date: Tue, 17 Nov 2020 14:14:29 +1100 Subject: audren: Make use of nodiscard, rework downmixing, release all buffers Preliminary work for upmixing & general cleanup. Fixes basic issues in games such as Shovel Knight and slightly improves the LEGO games. Upmixing stitll needs to be implemented. Audio levels in a few games will be fixed as we now use the downmix coefficients when possible instead of supplying our own --- src/audio_core/audio_out.cpp | 4 ++ src/audio_core/audio_out.h | 3 + src/audio_core/audio_renderer.cpp | 110 ++++++++++++++++++++++++++++--------- src/audio_core/audio_renderer.h | 20 +++---- src/audio_core/behavior_info.h | 30 +++++----- src/audio_core/command_generator.h | 14 ++--- src/audio_core/common.h | 2 +- src/audio_core/effect_context.h | 26 ++++----- src/audio_core/mix_context.h | 26 ++++----- src/audio_core/sink_context.cpp | 18 +++++- src/audio_core/sink_context.h | 13 +++-- src/audio_core/stream.cpp | 9 +++ src/audio_core/stream.h | 21 ++++--- 13 files changed, 194 insertions(+), 102 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/audio_out.cpp b/src/audio_core/audio_out.cpp index 8619a3f03..fe3a898ad 100644 --- a/src/audio_core/audio_out.cpp +++ b/src/audio_core/audio_out.cpp @@ -43,6 +43,10 @@ std::vector AudioOut::GetTagsAndReleaseBuffers(StreamPtr stream, return stream->GetTagsAndReleaseBuffers(max_count); } +std::vector AudioOut::GetTagsAndReleaseBuffers(StreamPtr stream) { + return stream->GetTagsAndReleaseBuffers(); +} + void AudioOut::StartStream(StreamPtr stream) { stream->Play(); } diff --git a/src/audio_core/audio_out.h b/src/audio_core/audio_out.h index b07588287..6ce08cd0d 100644 --- a/src/audio_core/audio_out.h +++ b/src/audio_core/audio_out.h @@ -31,6 +31,9 @@ public: /// Returns a vector of recently released buffers specified by tag for the specified stream std::vector GetTagsAndReleaseBuffers(StreamPtr stream, std::size_t max_count); + /// Returns a vector of all recently released buffers specified by tag for the specified stream + std::vector GetTagsAndReleaseBuffers(StreamPtr stream); + /// Starts an audio stream for playback void StartStream(StreamPtr stream); diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp index a7e851bb8..03a133640 100644 --- a/src/audio_core/audio_renderer.cpp +++ b/src/audio_core/audio_renderer.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include "audio_core/audio_out.h" @@ -14,6 +15,59 @@ #include "core/memory.h" #include "core/settings.h" +namespace { +[[nodiscard]] static constexpr s16 ClampToS16(s32 value) { + return static_cast(std::clamp(value, static_cast(std::numeric_limits::min()), + static_cast(std::numeric_limits::max()))); +} + +[[nodiscard]] static constexpr s16 Mix2To1(s16 l_channel, s16 r_channel) { + // Mix 50% from left and 50% from right channel + constexpr float l_mix_amount = 50.0f / 100.0f; + constexpr float r_mix_amount = 50.0f / 100.0f; + return ClampToS16(static_cast((static_cast(l_channel) * l_mix_amount) + + (static_cast(r_channel) * r_mix_amount))); +} + +[[nodiscard]] static constexpr std::tuple Mix6To2(s16 fl_channel, s16 fr_channel, + s16 fc_channel, + [[maybe_unused]] s16 lf_channel, + s16 bl_channel, s16 br_channel) { + // Front channels are mixed 36.94%, Center channels are mixed to be 26.12% & the back channels + // are mixed to be 36.94% + + constexpr float front_mix_amount = 36.94f / 100.0f; + constexpr float center_mix_amount = 26.12f / 100.0f; + constexpr float back_mix_amount = 36.94f / 100.0f; + + // Mix 50% from left and 50% from right channel + const auto left = front_mix_amount * static_cast(fl_channel) + + center_mix_amount * static_cast(fc_channel) + + back_mix_amount * static_cast(bl_channel); + + const auto right = front_mix_amount * static_cast(fr_channel) + + center_mix_amount * static_cast(fc_channel) + + back_mix_amount * static_cast(br_channel); + + return {ClampToS16(static_cast(left)), ClampToS16(static_cast(right))}; +} + +[[nodiscard]] static constexpr std::tuple Mix6To2WithCoefficients( + s16 fl_channel, s16 fr_channel, s16 fc_channel, s16 lf_channel, s16 bl_channel, s16 br_channel, + const std::array& coeff) { + const auto left = + static_cast(fl_channel) * coeff[0] + static_cast(fc_channel) * coeff[1] + + static_cast(lf_channel) * coeff[2] + static_cast(bl_channel) * coeff[0]; + + const auto right = + static_cast(fr_channel) * coeff[0] + static_cast(fc_channel) * coeff[1] + + static_cast(lf_channel) * coeff[2] + static_cast(br_channel) * coeff[0]; + + return {ClampToS16(static_cast(left)), ClampToS16(static_cast(right))}; +} + +} // namespace + namespace AudioCore { AudioRenderer::AudioRenderer(Core::Timing::CoreTiming& core_timing, Core::Memory::Memory& memory_, AudioCommon::AudioRendererParameter params, @@ -62,10 +116,6 @@ Stream::State AudioRenderer::GetStreamState() const { return stream->GetState(); } -static constexpr s16 ClampToS16(s32 value) { - return static_cast(std::clamp(value, -32768, 32767)); -} - ResultCode AudioRenderer::UpdateAudioRenderer(const std::vector& input_params, std::vector& output_params) { @@ -104,8 +154,8 @@ ResultCode AudioRenderer::UpdateAudioRenderer(const std::vector& input_param } } - auto mix_result = info_updater.UpdateMixes(mix_context, worker_params.mix_buffer_count, - splitter_context, effect_context); + const auto mix_result = info_updater.UpdateMixes(mix_context, worker_params.mix_buffer_count, + splitter_context, effect_context); if (mix_result.IsError()) { LOG_ERROR(Audio, "Failed to update mix parameters"); @@ -194,20 +244,22 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) { for (std::size_t i = 0; i < BUFFER_SIZE; i++) { if (channel_count == 1) { const auto sample = ClampToS16(mix_buffers[0][i]); - buffer[i * stream_channel_count + 0] = sample; - if (stream_channel_count > 1) { - buffer[i * stream_channel_count + 1] = sample; + + // Place sample in all channels + for (u32 channel = 0; channel < stream_channel_count; channel++) { + buffer[i * stream_channel_count + channel] = sample; } + if (stream_channel_count == 6) { - buffer[i * stream_channel_count + 2] = sample; - buffer[i * stream_channel_count + 4] = sample; - buffer[i * stream_channel_count + 5] = sample; + // Output stream has a LF channel, mute it! + buffer[i * stream_channel_count + 3] = 0; } + } else if (channel_count == 2) { const auto l_sample = ClampToS16(mix_buffers[0][i]); const auto r_sample = ClampToS16(mix_buffers[1][i]); if (stream_channel_count == 1) { - buffer[i * stream_channel_count + 0] = l_sample; + buffer[i * stream_channel_count + 0] = Mix2To1(l_sample, r_sample); } else if (stream_channel_count == 2) { buffer[i * stream_channel_count + 0] = l_sample; buffer[i * stream_channel_count + 1] = r_sample; @@ -215,8 +267,8 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) { buffer[i * stream_channel_count + 0] = l_sample; buffer[i * stream_channel_count + 1] = r_sample; - buffer[i * stream_channel_count + 2] = - ClampToS16((static_cast(l_sample) + static_cast(r_sample)) / 2); + // Combine both left and right channels to the center channel + buffer[i * stream_channel_count + 2] = Mix2To1(l_sample, r_sample); buffer[i * stream_channel_count + 4] = l_sample; buffer[i * stream_channel_count + 5] = r_sample; @@ -231,17 +283,25 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) { const auto br_sample = ClampToS16(mix_buffers[5][i]); if (stream_channel_count == 1) { - buffer[i * stream_channel_count + 0] = fc_sample; + // Games seem to ignore the center channel half the time, we use the front left + // and right channel for mixing as that's where majority of the audio goes + buffer[i * stream_channel_count + 0] = Mix2To1(fl_sample, fr_sample); } else if (stream_channel_count == 2) { - buffer[i * stream_channel_count + 0] = - static_cast(0.3694f * static_cast(fl_sample) + - 0.2612f * static_cast(fc_sample) + - 0.3694f * static_cast(bl_sample)); - buffer[i * stream_channel_count + 1] = - static_cast(0.3694f * static_cast(fr_sample) + - 0.2612f * static_cast(fc_sample) + - 0.3694f * static_cast(br_sample)); + // Mix all channels into 2 channels + if (sink_context.HasDownMixingCoefficients()) { + const auto [left, right] = Mix6To2WithCoefficients( + fl_sample, fr_sample, fc_sample, lf_sample, bl_sample, br_sample, + sink_context.GetDownmixCoefficients()); + buffer[i * stream_channel_count + 0] = left; + buffer[i * stream_channel_count + 1] = right; + } else { + const auto [left, right] = Mix6To2(fl_sample, fr_sample, fc_sample, + lf_sample, bl_sample, br_sample); + buffer[i * stream_channel_count + 0] = left; + buffer[i * stream_channel_count + 1] = right; + } } else if (stream_channel_count == 6) { + // Pass through buffer[i * stream_channel_count + 0] = fl_sample; buffer[i * stream_channel_count + 1] = fr_sample; buffer[i * stream_channel_count + 2] = fc_sample; @@ -259,7 +319,7 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) { } void AudioRenderer::ReleaseAndQueueBuffers() { - const auto released_buffers{audio_out->GetTagsAndReleaseBuffers(stream, 2)}; + const auto released_buffers{audio_out->GetTagsAndReleaseBuffers(stream)}; for (const auto& tag : released_buffers) { QueueMixedBuffer(tag); } diff --git a/src/audio_core/audio_renderer.h b/src/audio_core/audio_renderer.h index 2fd93e058..a85219045 100644 --- a/src/audio_core/audio_renderer.h +++ b/src/audio_core/audio_renderer.h @@ -36,16 +36,10 @@ class Memory; } namespace AudioCore { -using DSPStateHolder = std::array; +using DSPStateHolder = std::array; class AudioOut; -struct RendererInfo { - u64_le elasped_frame_count{}; - INSERT_PADDING_WORDS(2); -}; -static_assert(sizeof(RendererInfo) == 0x10, "RendererInfo is an invalid size"); - class AudioRenderer { public: AudioRenderer(Core::Timing::CoreTiming& core_timing, Core::Memory::Memory& memory_, @@ -53,14 +47,14 @@ public: std::shared_ptr buffer_event, std::size_t instance_number); ~AudioRenderer(); - ResultCode UpdateAudioRenderer(const std::vector& input_params, - std::vector& output_params); + [[nodiscard]] ResultCode UpdateAudioRenderer(const std::vector& input_params, + std::vector& output_params); void QueueMixedBuffer(Buffer::Tag tag); void ReleaseAndQueueBuffers(); - u32 GetSampleRate() const; - u32 GetSampleCount() const; - u32 GetMixBufferCount() const; - Stream::State GetStreamState() const; + [[nodiscard]] u32 GetSampleRate() const; + [[nodiscard]] u32 GetSampleCount() const; + [[nodiscard]] u32 GetMixBufferCount() const; + [[nodiscard]] Stream::State GetStreamState() const; private: BehaviorInfo behavior_info{}; diff --git a/src/audio_core/behavior_info.h b/src/audio_core/behavior_info.h index 512a4ebe3..5a96bf75e 100644 --- a/src/audio_core/behavior_info.h +++ b/src/audio_core/behavior_info.h @@ -43,22 +43,22 @@ public: void ClearError(); void UpdateFlags(u64_le dest_flags); void SetUserRevision(u32_le revision); - u32_le GetUserRevision() const; - u32_le GetProcessRevision() const; + [[nodiscard]] u32_le GetUserRevision() const; + [[nodiscard]] u32_le GetProcessRevision() const; - bool IsAdpcmLoopContextBugFixed() const; - bool IsSplitterSupported() const; - bool IsLongSizePreDelaySupported() const; - bool IsAudioRendererProcessingTimeLimit80PercentSupported() const; - bool IsAudioRendererProcessingTimeLimit75PercentSupported() const; - bool IsAudioRendererProcessingTimeLimit70PercentSupported() const; - bool IsElapsedFrameCountSupported() const; - bool IsMemoryPoolForceMappingEnabled() const; - bool IsFlushVoiceWaveBuffersSupported() const; - bool IsVoicePlayedSampleCountResetAtLoopPointSupported() const; - bool IsVoicePitchAndSrcSkippedSupported() const; - bool IsMixInParameterDirtyOnlyUpdateSupported() const; - bool IsSplitterBugFixed() const; + [[nodiscard]] bool IsAdpcmLoopContextBugFixed() const; + [[nodiscard]] bool IsSplitterSupported() const; + [[nodiscard]] bool IsLongSizePreDelaySupported() const; + [[nodiscard]] bool IsAudioRendererProcessingTimeLimit80PercentSupported() const; + [[nodiscard]] bool IsAudioRendererProcessingTimeLimit75PercentSupported() const; + [[nodiscard]] bool IsAudioRendererProcessingTimeLimit70PercentSupported() const; + [[nodiscard]] bool IsElapsedFrameCountSupported() const; + [[nodiscard]] bool IsMemoryPoolForceMappingEnabled() const; + [[nodiscard]] bool IsFlushVoiceWaveBuffersSupported() const; + [[nodiscard]] bool IsVoicePlayedSampleCountResetAtLoopPointSupported() const; + [[nodiscard]] bool IsVoicePitchAndSrcSkippedSupported() const; + [[nodiscard]] bool IsMixInParameterDirtyOnlyUpdateSupported() const; + [[nodiscard]] bool IsSplitterBugFixed() const; void CopyErrorInfo(OutParams& dst); private: diff --git a/src/audio_core/command_generator.h b/src/audio_core/command_generator.h index 53e57748b..87ece00c4 100644 --- a/src/audio_core/command_generator.h +++ b/src/audio_core/command_generator.h @@ -39,13 +39,13 @@ public: void PreCommand(); void PostCommand(); - s32* GetChannelMixBuffer(s32 channel); - const s32* GetChannelMixBuffer(s32 channel) const; - s32* GetMixBuffer(std::size_t index); - const s32* GetMixBuffer(std::size_t index) const; - std::size_t GetMixChannelBufferOffset(s32 channel) const; + [[nodiscard]] s32* GetChannelMixBuffer(s32 channel); + [[nodiscard]] const s32* GetChannelMixBuffer(s32 channel) const; + [[nodiscard]] s32* GetMixBuffer(std::size_t index); + [[nodiscard]] const s32* GetMixBuffer(std::size_t index) const; + [[nodiscard]] std::size_t GetMixChannelBufferOffset(s32 channel) const; - std::size_t GetTotalMixBufferCount() const; + [[nodiscard]] std::size_t GetTotalMixBufferCount() const; private: void GenerateDataSourceCommand(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 channel); @@ -73,7 +73,7 @@ private: void GenerateI3dl2ReverbEffectCommand(s32 mix_buffer_offset, EffectBase* info, bool enabled); void GenerateBiquadFilterEffectCommand(s32 mix_buffer_offset, EffectBase* info, bool enabled); void GenerateAuxCommand(s32 mix_buffer_offset, EffectBase* info, bool enabled); - ServerSplitterDestinationData* GetDestinationData(s32 splitter_id, s32 index); + [[nodiscard]] ServerSplitterDestinationData* GetDestinationData(s32 splitter_id, s32 index); s32 WriteAuxBuffer(AuxInfoDSP& dsp_info, VAddr send_buffer, u32 max_samples, const s32* data, u32 sample_count, u32 write_offset, u32 write_count); diff --git a/src/audio_core/common.h b/src/audio_core/common.h index 7b4a1e9e8..ec59a3ba9 100644 --- a/src/audio_core/common.h +++ b/src/audio_core/common.h @@ -22,7 +22,7 @@ constexpr std::size_t MAX_CHANNEL_COUNT = 6; constexpr std::size_t MAX_WAVE_BUFFERS = 4; constexpr std::size_t MAX_SAMPLE_HISTORY = 4; constexpr u32 STREAM_SAMPLE_RATE = 48000; -constexpr u32 STREAM_NUM_CHANNELS = 6; +constexpr u32 STREAM_NUM_CHANNELS = 2; constexpr s32 NO_SPLITTER = -1; constexpr s32 NO_MIX = 0x7fffffff; constexpr s32 NO_FINAL_MIX = std::numeric_limits::min(); diff --git a/src/audio_core/effect_context.h b/src/audio_core/effect_context.h index 2c4ce53ef..03c5a0f04 100644 --- a/src/audio_core/effect_context.h +++ b/src/audio_core/effect_context.h @@ -189,11 +189,11 @@ public: virtual void Update(EffectInfo::InParams& in_params) = 0; virtual void UpdateForCommandGeneration() = 0; - UsageState GetUsage() const; - EffectType GetType() const; - bool IsEnabled() const; - s32 GetMixID() const; - s32 GetProcessingOrder() const; + [[nodiscard]] UsageState GetUsage() const; + [[nodiscard]] EffectType GetType() const; + [[nodiscard]] bool IsEnabled() const; + [[nodiscard]] s32 GetMixID() const; + [[nodiscard]] s32 GetProcessingOrder() const; protected: UsageState usage{UsageState::Invalid}; @@ -257,10 +257,10 @@ public: void Update(EffectInfo::InParams& in_params) override; void UpdateForCommandGeneration() override; - VAddr GetSendInfo() const; - VAddr GetSendBuffer() const; - VAddr GetRecvInfo() const; - VAddr GetRecvBuffer() const; + [[nodiscard]] VAddr GetSendInfo() const; + [[nodiscard]] VAddr GetSendBuffer() const; + [[nodiscard]] VAddr GetRecvInfo() const; + [[nodiscard]] VAddr GetRecvBuffer() const; private: VAddr send_info{}; @@ -309,10 +309,10 @@ public: explicit EffectContext(std::size_t effect_count); ~EffectContext(); - std::size_t GetCount() const; - EffectBase* GetInfo(std::size_t i); - EffectBase* RetargetEffect(std::size_t i, EffectType effect); - const EffectBase* GetInfo(std::size_t i) const; + [[nodiscard]] std::size_t GetCount() const; + [[nodiscard]] EffectBase* GetInfo(std::size_t i); + [[nodiscard]] EffectBase* RetargetEffect(std::size_t i, EffectType effect); + [[nodiscard]] const EffectBase* GetInfo(std::size_t i) const; private: std::size_t effect_count{}; diff --git a/src/audio_core/mix_context.h b/src/audio_core/mix_context.h index 6a588eeb4..68bc673c6 100644 --- a/src/audio_core/mix_context.h +++ b/src/audio_core/mix_context.h @@ -62,17 +62,17 @@ public: ServerMixInfo(); ~ServerMixInfo(); - const ServerMixInfo::InParams& GetInParams() const; - ServerMixInfo::InParams& GetInParams(); + [[nodiscard]] const ServerMixInfo::InParams& GetInParams() const; + [[nodiscard]] ServerMixInfo::InParams& GetInParams(); bool Update(EdgeMatrix& edge_matrix, const MixInfo::InParams& mix_in, BehaviorInfo& behavior_info, SplitterContext& splitter_context, EffectContext& effect_context); - bool HasAnyConnection() const; + [[nodiscard]] bool HasAnyConnection() const; void Cleanup(); void SetEffectCount(std::size_t count); void ResetEffectProcessingOrder(); - s32 GetEffectOrder(std::size_t i) const; + [[nodiscard]] s32 GetEffectOrder(std::size_t i) const; private: std::vector effect_processing_order; @@ -91,15 +91,15 @@ public: void SortInfo(); bool TsortInfo(SplitterContext& splitter_context); - std::size_t GetCount() const; - ServerMixInfo& GetInfo(std::size_t i); - const ServerMixInfo& GetInfo(std::size_t i) const; - ServerMixInfo& GetSortedInfo(std::size_t i); - const ServerMixInfo& GetSortedInfo(std::size_t i) const; - ServerMixInfo& GetFinalMixInfo(); - const ServerMixInfo& GetFinalMixInfo() const; - EdgeMatrix& GetEdgeMatrix(); - const EdgeMatrix& GetEdgeMatrix() const; + [[nodiscard]] std::size_t GetCount() const; + [[nodiscard]] ServerMixInfo& GetInfo(std::size_t i); + [[nodiscard]] const ServerMixInfo& GetInfo(std::size_t i) const; + [[nodiscard]] ServerMixInfo& GetSortedInfo(std::size_t i); + [[nodiscard]] const ServerMixInfo& GetSortedInfo(std::size_t i) const; + [[nodiscard]] ServerMixInfo& GetFinalMixInfo(); + [[nodiscard]] const ServerMixInfo& GetFinalMixInfo() const; + [[nodiscard]] EdgeMatrix& GetEdgeMatrix(); + [[nodiscard]] const EdgeMatrix& GetEdgeMatrix() const; private: void CalcMixBufferOffset(); diff --git a/src/audio_core/sink_context.cpp b/src/audio_core/sink_context.cpp index 0882b411a..cdb47ba81 100644 --- a/src/audio_core/sink_context.cpp +++ b/src/audio_core/sink_context.cpp @@ -12,10 +12,16 @@ std::size_t SinkContext::GetCount() const { return sink_count; } -void SinkContext::UpdateMainSink(SinkInfo::InParams& in) { +void SinkContext::UpdateMainSink(const SinkInfo::InParams& in) { + ASSERT(in.type == SinkTypes::Device); + + downmix = in.device.down_matrix_enabled; + if (downmix) { + downmix_coefficients = in.device.down_matrix_coef; + } in_use = in.in_use; use_count = in.device.input_count; - std::memcpy(buffers.data(), in.device.input.data(), AudioCommon::MAX_CHANNEL_COUNT); + buffers = in.device.input; } bool SinkContext::InUse() const { @@ -28,4 +34,12 @@ std::vector SinkContext::OutputBuffers() const { return buffer_ret; } +bool SinkContext::HasDownMixingCoefficients() const { + return downmix; +} + +const std::array& SinkContext::GetDownmixCoefficients() const { + return downmix_coefficients; +} + } // namespace AudioCore diff --git a/src/audio_core/sink_context.h b/src/audio_core/sink_context.h index d7aa72ba7..5a757a4ef 100644 --- a/src/audio_core/sink_context.h +++ b/src/audio_core/sink_context.h @@ -74,16 +74,21 @@ public: explicit SinkContext(std::size_t sink_count); ~SinkContext(); - std::size_t GetCount() const; + [[nodiscard]] std::size_t GetCount() const; - void UpdateMainSink(SinkInfo::InParams& in); - bool InUse() const; - std::vector OutputBuffers() const; + void UpdateMainSink(const SinkInfo::InParams& in); + [[nodiscard]] bool InUse() const; + [[nodiscard]] std::vector OutputBuffers() const; + + [[nodiscard]] bool HasDownMixingCoefficients() const; + [[nodiscard]] const std::array& GetDownmixCoefficients() const; private: bool in_use{false}; s32 use_count{}; std::array buffers{}; std::size_t sink_count{}; + bool downmix{false}; + std::array downmix_coefficients{}; }; } // namespace AudioCore diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index 4bbb1e0c4..3f11b84ae 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp @@ -136,4 +136,13 @@ std::vector Stream::GetTagsAndReleaseBuffers(std::size_t max_count) return tags; } +std::vector Stream::GetTagsAndReleaseBuffers() { + std::vector tags; + while (!released_buffers.empty()) { + tags.push_back(released_buffers.front()->GetTag()); + released_buffers.pop(); + } + return tags; +} + } // namespace AudioCore diff --git a/src/audio_core/stream.h b/src/audio_core/stream.h index 6437b8591..71c2d0b4f 100644 --- a/src/audio_core/stream.h +++ b/src/audio_core/stream.h @@ -57,37 +57,40 @@ public: bool QueueBuffer(BufferPtr&& buffer); /// Returns true if the audio stream contains a buffer with the specified tag - bool ContainsBuffer(Buffer::Tag tag) const; + [[nodiscard]] bool ContainsBuffer(Buffer::Tag tag) const; /// Returns a vector of recently released buffers specified by tag - std::vector GetTagsAndReleaseBuffers(std::size_t max_count); + [[nodiscard]] std::vector GetTagsAndReleaseBuffers(std::size_t max_count); + + /// Returns a vector of all recently released buffers specified by tag + [[nodiscard]] std::vector GetTagsAndReleaseBuffers(); void SetVolume(float volume); - float GetVolume() const { + [[nodiscard]] float GetVolume() const { return game_volume; } /// Returns true if the stream is currently playing - bool IsPlaying() const { + [[nodiscard]] bool IsPlaying() const { return state == State::Playing; } /// Returns the number of queued buffers - std::size_t GetQueueSize() const { + [[nodiscard]] std::size_t GetQueueSize() const { return queued_buffers.size(); } /// Gets the sample rate - u32 GetSampleRate() const { + [[nodiscard]] u32 GetSampleRate() const { return sample_rate; } /// Gets the number of channels - u32 GetNumChannels() const; + [[nodiscard]] u32 GetNumChannels() const; /// Get the state - State GetState() const; + [[nodiscard]] State GetState() const; private: /// Plays the next queued buffer in the audio stream, starting playback if necessary @@ -97,7 +100,7 @@ private: void ReleaseActiveBuffer(std::chrono::nanoseconds ns_late = {}); /// Gets the number of core cycles when the specified buffer will be released - std::chrono::nanoseconds GetBufferReleaseNS(const Buffer& buffer) const; + [[nodiscard]] std::chrono::nanoseconds GetBufferReleaseNS(const Buffer& buffer) const; u32 sample_rate; ///< Sample rate of the stream Format format; ///< Format of the stream -- cgit v1.2.3 From 908d3c56793ee67dccd0d370b175c4937420053f Mon Sep 17 00:00:00 2001 From: Chloe Marcec Date: Tue, 17 Nov 2020 15:40:19 +1100 Subject: Addressed changes --- src/audio_core/audio_renderer.cpp | 4 ++-- src/audio_core/sink_context.cpp | 8 ++++---- src/audio_core/sink_context.h | 10 ++++++---- src/audio_core/stream.cpp | 1 + 4 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp index 03a133640..e1ded84e0 100644 --- a/src/audio_core/audio_renderer.cpp +++ b/src/audio_core/audio_renderer.cpp @@ -17,8 +17,8 @@ namespace { [[nodiscard]] static constexpr s16 ClampToS16(s32 value) { - return static_cast(std::clamp(value, static_cast(std::numeric_limits::min()), - static_cast(std::numeric_limits::max()))); + return static_cast(std::clamp(value, s32{std::numeric_limits::min()}, + s32{std::numeric_limits::max()})); } [[nodiscard]] static constexpr s16 Mix2To1(s16 l_channel, s16 r_channel) { diff --git a/src/audio_core/sink_context.cpp b/src/audio_core/sink_context.cpp index cdb47ba81..b29b47890 100644 --- a/src/audio_core/sink_context.cpp +++ b/src/audio_core/sink_context.cpp @@ -15,8 +15,8 @@ std::size_t SinkContext::GetCount() const { void SinkContext::UpdateMainSink(const SinkInfo::InParams& in) { ASSERT(in.type == SinkTypes::Device); - downmix = in.device.down_matrix_enabled; - if (downmix) { + has_downmix_coefs = in.device.down_matrix_enabled; + if (has_downmix_coefs) { downmix_coefficients = in.device.down_matrix_coef; } in_use = in.in_use; @@ -35,10 +35,10 @@ std::vector SinkContext::OutputBuffers() const { } bool SinkContext::HasDownMixingCoefficients() const { - return downmix; + return has_downmix_coefs; } -const std::array& SinkContext::GetDownmixCoefficients() const { +const DownmixCoefficients& SinkContext::GetDownmixCoefficients() const { return downmix_coefficients; } diff --git a/src/audio_core/sink_context.h b/src/audio_core/sink_context.h index 5a757a4ef..e2e7880b7 100644 --- a/src/audio_core/sink_context.h +++ b/src/audio_core/sink_context.h @@ -11,6 +11,8 @@ namespace AudioCore { +using DownmixCoefficients = std::array; + enum class SinkTypes : u8 { Invalid = 0, Device = 1, @@ -50,7 +52,7 @@ public: std::array input; INSERT_UNION_PADDING_BYTES(1); bool down_matrix_enabled; - std::array down_matrix_coef; + DownmixCoefficients down_matrix_coef; }; static_assert(sizeof(SinkInfo::DeviceIn) == 0x11c, "SinkInfo::DeviceIn is an invalid size"); @@ -81,14 +83,14 @@ public: [[nodiscard]] std::vector OutputBuffers() const; [[nodiscard]] bool HasDownMixingCoefficients() const; - [[nodiscard]] const std::array& GetDownmixCoefficients() const; + [[nodiscard]] const DownmixCoefficients& GetDownmixCoefficients() const; private: bool in_use{false}; s32 use_count{}; std::array buffers{}; std::size_t sink_count{}; - bool downmix{false}; - std::array downmix_coefficients{}; + bool has_downmix_coefs{false}; + DownmixCoefficients downmix_coefficients{}; }; } // namespace AudioCore diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index 3f11b84ae..41bc2f4d6 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp @@ -138,6 +138,7 @@ std::vector Stream::GetTagsAndReleaseBuffers(std::size_t max_count) std::vector Stream::GetTagsAndReleaseBuffers() { std::vector tags; + tags.reserve(released_buffers.size()); while (!released_buffers.empty()) { tags.push_back(released_buffers.front()->GetTag()); released_buffers.pop(); -- cgit v1.2.3 From d7019d8307bf8db1d985e3a537bd83289cf1a3de Mon Sep 17 00:00:00 2001 From: Chloe Marcec Date: Sat, 28 Nov 2020 23:25:28 +1100 Subject: audio_core: Remove temp_mix_buffer It's unused and doesn't need to be initialized --- src/audio_core/audio_renderer.cpp | 3 +-- src/audio_core/audio_renderer.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp index e1ded84e0..5f532ed31 100644 --- a/src/audio_core/audio_renderer.cpp +++ b/src/audio_core/audio_renderer.cpp @@ -79,8 +79,7 @@ AudioRenderer::AudioRenderer(Core::Timing::CoreTiming& core_timing, Core::Memory sink_context(params.sink_count), splitter_context(), voices(params.voice_count), memory{memory_}, command_generator(worker_params, voice_context, mix_context, splitter_context, effect_context, - memory), - temp_mix_buffer(AudioCommon::TOTAL_TEMP_MIX_SIZE) { + memory) { behavior_info.SetUserRevision(params.revision); splitter_context.Initialize(behavior_info, params.splitter_count, params.num_splitter_send_channels); diff --git a/src/audio_core/audio_renderer.h b/src/audio_core/audio_renderer.h index a85219045..54ac68b80 100644 --- a/src/audio_core/audio_renderer.h +++ b/src/audio_core/audio_renderer.h @@ -73,7 +73,6 @@ private: Core::Memory::Memory& memory; CommandGenerator command_generator; std::size_t elapsed_frame_count{}; - std::vector temp_mix_buffer{}; }; } // namespace AudioCore -- cgit v1.2.3 From 1ea6bdef058a789e2771511f741bffcca73c3525 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 25 Nov 2020 15:21:03 -0500 Subject: audio_core: Make shadowing and unused parameters errors Moves the audio code closer to enabling warnings as errors in general. --- src/audio_core/CMakeLists.txt | 2 ++ src/audio_core/algorithm/filter.cpp | 6 ++-- src/audio_core/algorithm/filter.h | 4 +-- src/audio_core/audio_renderer.cpp | 6 ++-- src/audio_core/audio_renderer.h | 3 +- src/audio_core/buffer.h | 2 +- src/audio_core/command_generator.cpp | 27 +++++++++------- src/audio_core/command_generator.h | 8 ++--- src/audio_core/cubeb_sink.cpp | 15 +++++---- src/audio_core/effect_context.cpp | 60 ++++++++++++++++++------------------ src/audio_core/effect_context.h | 6 ++-- src/audio_core/info_updater.cpp | 32 +++++++++---------- src/audio_core/info_updater.h | 4 +-- src/audio_core/memory_pool.cpp | 13 ++++---- src/audio_core/memory_pool.h | 11 +++---- src/audio_core/sink_context.cpp | 2 +- src/audio_core/sink_context.h | 12 ++++---- src/audio_core/splitter_context.cpp | 22 ++++++------- src/audio_core/splitter_context.h | 20 ++++++------ src/audio_core/stream.cpp | 10 +++--- src/audio_core/stream.h | 4 +-- src/audio_core/voice_context.cpp | 7 +++-- src/audio_core/voice_context.h | 10 +++--- 23 files changed, 147 insertions(+), 139 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index 68c67507b..d1d177b51 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt @@ -51,6 +51,8 @@ if (NOT MSVC) -Werror=implicit-fallthrough -Werror=reorder -Werror=sign-compare + -Werror=shadow + -Werror=unused-parameter -Werror=unused-variable $<$:-Werror=unused-but-set-parameter> diff --git a/src/audio_core/algorithm/filter.cpp b/src/audio_core/algorithm/filter.cpp index f34a5b9f3..01b8dff6b 100644 --- a/src/audio_core/algorithm/filter.cpp +++ b/src/audio_core/algorithm/filter.cpp @@ -31,8 +31,8 @@ Filter Filter::LowPass(double cutoff, double Q) { Filter::Filter() : Filter(1.0, 0.0, 0.0, 1.0, 0.0, 0.0) {} -Filter::Filter(double a0, double a1, double a2, double b0, double b1, double b2) - : a1(a1 / a0), a2(a2 / a0), b0(b0 / a0), b1(b1 / a0), b2(b2 / a0) {} +Filter::Filter(double a0_, double a1_, double a2_, double b0_, double b1_, double b2_) + : a1(a1_ / a0_), a2(a2_ / a0_), b0(b0_ / a0_), b1(b1_ / a0_), b2(b2_ / a0_) {} void Filter::Process(std::vector& signal) { const std::size_t num_frames = signal.size() / 2; @@ -69,7 +69,7 @@ CascadingFilter CascadingFilter::LowPass(double cutoff, std::size_t cascade_size } CascadingFilter::CascadingFilter() = default; -CascadingFilter::CascadingFilter(std::vector filters) : filters(std::move(filters)) {} +CascadingFilter::CascadingFilter(std::vector filters_) : filters(std::move(filters_)) {} void CascadingFilter::Process(std::vector& signal) { for (auto& filter : filters) { diff --git a/src/audio_core/algorithm/filter.h b/src/audio_core/algorithm/filter.h index 3546d149b..a291fe79b 100644 --- a/src/audio_core/algorithm/filter.h +++ b/src/audio_core/algorithm/filter.h @@ -25,7 +25,7 @@ public: /// Passthrough filter. Filter(); - Filter(double a0, double a1, double a2, double b0, double b1, double b2); + Filter(double a0_, double a1_, double a2_, double b0_, double b1_, double b2_); void Process(std::vector& signal); @@ -51,7 +51,7 @@ public: /// Passthrough. CascadingFilter(); - explicit CascadingFilter(std::vector filters); + explicit CascadingFilter(std::vector filters_); void Process(std::vector& signal); diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp index e1ded84e0..75ab9ea0b 100644 --- a/src/audio_core/audio_renderer.cpp +++ b/src/audio_core/audio_renderer.cpp @@ -71,9 +71,9 @@ namespace { namespace AudioCore { AudioRenderer::AudioRenderer(Core::Timing::CoreTiming& core_timing, Core::Memory::Memory& memory_, AudioCommon::AudioRendererParameter params, - std::shared_ptr buffer_event, + std::shared_ptr buffer_event_, std::size_t instance_number) - : worker_params{params}, buffer_event{buffer_event}, + : worker_params{params}, buffer_event{buffer_event_}, memory_pool_info(params.effect_count + params.voice_count * 4), voice_context(params.voice_count), effect_context(params.effect_count), mix_context(), sink_context(params.sink_count), splitter_context(), @@ -89,7 +89,7 @@ AudioRenderer::AudioRenderer(Core::Timing::CoreTiming& core_timing, Core::Memory stream = audio_out->OpenStream(core_timing, params.sample_rate, AudioCommon::STREAM_NUM_CHANNELS, fmt::format("AudioRenderer-Instance{}", instance_number), - [=]() { buffer_event->Signal(); }); + [=]() { buffer_event_->Signal(); }); audio_out->StartStream(stream); QueueMixedBuffer(0); diff --git a/src/audio_core/audio_renderer.h b/src/audio_core/audio_renderer.h index a85219045..1f96013f7 100644 --- a/src/audio_core/audio_renderer.h +++ b/src/audio_core/audio_renderer.h @@ -44,7 +44,8 @@ class AudioRenderer { public: AudioRenderer(Core::Timing::CoreTiming& core_timing, Core::Memory::Memory& memory_, AudioCommon::AudioRendererParameter params, - std::shared_ptr buffer_event, std::size_t instance_number); + std::shared_ptr buffer_event_, + std::size_t instance_number); ~AudioRenderer(); [[nodiscard]] ResultCode UpdateAudioRenderer(const std::vector& input_params, diff --git a/src/audio_core/buffer.h b/src/audio_core/buffer.h index 5ee09e9aa..ccc46ef82 100644 --- a/src/audio_core/buffer.h +++ b/src/audio_core/buffer.h @@ -18,7 +18,7 @@ class Buffer { public: using Tag = u64; - Buffer(Tag tag, std::vector&& samples) : tag{tag}, samples{std::move(samples)} {} + Buffer(Tag tag_, std::vector&& samples_) : tag{tag_}, samples{std::move(samples_)} {} /// Returns the raw audio data for the buffer std::vector& GetSamples() { diff --git a/src/audio_core/command_generator.cpp b/src/audio_core/command_generator.cpp index fb8700ccf..a4a9a757d 100644 --- a/src/audio_core/command_generator.cpp +++ b/src/audio_core/command_generator.cpp @@ -67,12 +67,12 @@ s32 ApplyMixDepop(s32* output, s32 first_sample, s32 delta, s32 sample_count) { } // namespace -CommandGenerator::CommandGenerator(AudioCommon::AudioRendererParameter& worker_params, - VoiceContext& voice_context, MixContext& mix_context, - SplitterContext& splitter_context, EffectContext& effect_context, - Core::Memory::Memory& memory) - : worker_params(worker_params), voice_context(voice_context), mix_context(mix_context), - splitter_context(splitter_context), effect_context(effect_context), memory(memory), +CommandGenerator::CommandGenerator(AudioCommon::AudioRendererParameter& worker_params_, + VoiceContext& voice_context_, MixContext& mix_context_, + SplitterContext& splitter_context_, + EffectContext& effect_context_, Core::Memory::Memory& memory_) + : worker_params(worker_params_), voice_context(voice_context_), mix_context(mix_context_), + splitter_context(splitter_context_), effect_context(effect_context_), memory(memory_), mix_buffer((worker_params.mix_buffer_count + AudioCommon::MAX_CHANNEL_COUNT) * worker_params.sample_count), sample_buffer(MIX_BUFFER_SIZE), @@ -255,7 +255,8 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo void CommandGenerator::GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voice_info, VoiceState& dsp_state, - s32 mix_buffer_count, s32 channel) { + [[maybe_unused]] s32 mix_buffer_count, + [[maybe_unused]] s32 channel) { for (std::size_t i = 0; i < AudioCommon::MAX_BIQUAD_FILTERS; i++) { const auto& in_params = voice_info.GetInParams(); auto& biquad_filter = in_params.biquad_filter[i]; @@ -278,9 +279,12 @@ void CommandGenerator::GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voic } } -void AudioCore::CommandGenerator::GenerateBiquadFilterCommand( - s32 mix_buffer, const BiquadFilterParameter& params, std::array& state, - std::size_t input_offset, std::size_t output_offset, s32 sample_count, s32 node_id) { +void CommandGenerator::GenerateBiquadFilterCommand([[maybe_unused]] s32 mix_buffer_id, + const BiquadFilterParameter& params, + std::array& state, + std::size_t input_offset, + std::size_t output_offset, s32 sample_count, + s32 node_id) { if (dumping_frame) { LOG_DEBUG(Audio, "(DSP_TRACE) GenerateBiquadFilterCommand node_id={}, " @@ -714,7 +718,8 @@ s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_s } s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_state, - s32 sample_count, s32 channel, std::size_t mix_offset) { + s32 sample_count, [[maybe_unused]] s32 channel, + std::size_t mix_offset) { const auto& in_params = voice_info.GetInParams(); const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index]; if (wave_buffer.buffer_address == 0) { diff --git a/src/audio_core/command_generator.h b/src/audio_core/command_generator.h index 87ece00c4..b937350b1 100644 --- a/src/audio_core/command_generator.h +++ b/src/audio_core/command_generator.h @@ -25,10 +25,10 @@ using MixVolumeBuffer = std::array; class CommandGenerator { public: - explicit CommandGenerator(AudioCommon::AudioRendererParameter& worker_params, - VoiceContext& voice_context, MixContext& mix_context, - SplitterContext& splitter_context, EffectContext& effect_context, - Core::Memory::Memory& memory); + explicit CommandGenerator(AudioCommon::AudioRendererParameter& worker_params_, + VoiceContext& voice_context_, MixContext& mix_context_, + SplitterContext& splitter_context_, EffectContext& effect_context_, + Core::Memory::Memory& memory_); ~CommandGenerator(); void ClearMixBuffers(); diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp index 6eaa60815..cf7b186e4 100644 --- a/src/audio_core/cubeb_sink.cpp +++ b/src/audio_core/cubeb_sink.cpp @@ -21,10 +21,10 @@ namespace AudioCore { class CubebSinkStream final : public SinkStream { public: - CubebSinkStream(cubeb* ctx, u32 sample_rate, u32 num_channels_, cubeb_devid output_device, + CubebSinkStream(cubeb* ctx_, u32 sample_rate, u32 num_channels_, cubeb_devid output_device, const std::string& name) - : ctx{ctx}, num_channels{std::min(num_channels_, 6u)}, time_stretch{sample_rate, - num_channels} { + : ctx{ctx_}, num_channels{std::min(num_channels_, 6u)}, time_stretch{sample_rate, + num_channels} { cubeb_stream_params params{}; params.rate = sample_rate; @@ -192,8 +192,9 @@ SinkStream& CubebSink::AcquireSinkStream(u32 sample_rate, u32 num_channels, return *sink_streams.back(); } -long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, - void* output_buffer, long num_frames) { +long CubebSinkStream::DataCallback([[maybe_unused]] cubeb_stream* stream, void* user_data, + [[maybe_unused]] const void* input_buffer, void* output_buffer, + long num_frames) { auto* impl = static_cast(user_data); auto* buffer = static_cast(output_buffer); @@ -236,7 +237,9 @@ long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const return num_frames; } -void CubebSinkStream::StateCallback(cubeb_stream* stream, void* user_data, cubeb_state state) {} +void CubebSinkStream::StateCallback([[maybe_unused]] cubeb_stream* stream, + [[maybe_unused]] void* user_data, + [[maybe_unused]] cubeb_state state) {} std::vector ListCubebSinkDevices() { std::vector device_list; diff --git a/src/audio_core/effect_context.cpp b/src/audio_core/effect_context.cpp index 4d9cdf524..f770b9608 100644 --- a/src/audio_core/effect_context.cpp +++ b/src/audio_core/effect_context.cpp @@ -12,7 +12,7 @@ bool ValidChannelCountForEffect(s32 channel_count) { } } // namespace -EffectContext::EffectContext(std::size_t effect_count) : effect_count(effect_count) { +EffectContext::EffectContext(std::size_t effect_count_) : effect_count(effect_count_) { effects.reserve(effect_count); std::generate_n(std::back_inserter(effects), effect_count, [] { return std::make_unique(); }); @@ -61,13 +61,13 @@ const EffectBase* EffectContext::GetInfo(std::size_t i) const { return effects.at(i).get(); } -EffectStubbed::EffectStubbed() : EffectBase::EffectBase(EffectType::Invalid) {} +EffectStubbed::EffectStubbed() : EffectBase(EffectType::Invalid) {} EffectStubbed::~EffectStubbed() = default; -void EffectStubbed::Update(EffectInfo::InParams& in_params) {} +void EffectStubbed::Update([[maybe_unused]] EffectInfo::InParams& in_params) {} void EffectStubbed::UpdateForCommandGeneration() {} -EffectBase::EffectBase(EffectType effect_type) : effect_type(effect_type) {} +EffectBase::EffectBase(EffectType effect_type_) : effect_type(effect_type_) {} EffectBase::~EffectBase() = default; UsageState EffectBase::GetUsage() const { @@ -90,32 +90,32 @@ s32 EffectBase::GetProcessingOrder() const { return processing_order; } -EffectI3dl2Reverb::EffectI3dl2Reverb() : EffectGeneric::EffectGeneric(EffectType::I3dl2Reverb) {} +EffectI3dl2Reverb::EffectI3dl2Reverb() : EffectGeneric(EffectType::I3dl2Reverb) {} EffectI3dl2Reverb::~EffectI3dl2Reverb() = default; void EffectI3dl2Reverb::Update(EffectInfo::InParams& in_params) { - auto& internal_params = GetParams(); + auto& params = GetParams(); const auto* reverb_params = reinterpret_cast(in_params.raw.data()); if (!ValidChannelCountForEffect(reverb_params->max_channels)) { UNREACHABLE_MSG("Invalid reverb max channel count {}", reverb_params->max_channels); return; } - const auto last_status = internal_params.status; + const auto last_status = params.status; mix_id = in_params.mix_id; processing_order = in_params.processing_order; - internal_params = *reverb_params; + params = *reverb_params; if (!ValidChannelCountForEffect(reverb_params->channel_count)) { - internal_params.channel_count = internal_params.max_channels; + params.channel_count = params.max_channels; } enabled = in_params.is_enabled; if (last_status != ParameterStatus::Updated) { - internal_params.status = last_status; + params.status = last_status; } if (in_params.is_new || skipped) { usage = UsageState::Initialized; - internal_params.status = ParameterStatus::Initialized; + params.status = ParameterStatus::Initialized; skipped = in_params.buffer_address == 0 || in_params.buffer_size == 0; } } @@ -129,15 +129,15 @@ void EffectI3dl2Reverb::UpdateForCommandGeneration() { GetParams().status = ParameterStatus::Updated; } -EffectBiquadFilter::EffectBiquadFilter() : EffectGeneric::EffectGeneric(EffectType::BiquadFilter) {} +EffectBiquadFilter::EffectBiquadFilter() : EffectGeneric(EffectType::BiquadFilter) {} EffectBiquadFilter::~EffectBiquadFilter() = default; void EffectBiquadFilter::Update(EffectInfo::InParams& in_params) { - auto& internal_params = GetParams(); + auto& params = GetParams(); const auto* biquad_params = reinterpret_cast(in_params.raw.data()); mix_id = in_params.mix_id; processing_order = in_params.processing_order; - internal_params = *biquad_params; + params = *biquad_params; enabled = in_params.is_enabled; } @@ -150,7 +150,7 @@ void EffectBiquadFilter::UpdateForCommandGeneration() { GetParams().status = ParameterStatus::Updated; } -EffectAuxInfo::EffectAuxInfo() : EffectGeneric::EffectGeneric(EffectType::Aux) {} +EffectAuxInfo::EffectAuxInfo() : EffectGeneric(EffectType::Aux) {} EffectAuxInfo::~EffectAuxInfo() = default; void EffectAuxInfo::Update(EffectInfo::InParams& in_params) { @@ -200,32 +200,32 @@ VAddr EffectAuxInfo::GetRecvBuffer() const { return recv_buffer; } -EffectDelay::EffectDelay() : EffectGeneric::EffectGeneric(EffectType::Delay) {} +EffectDelay::EffectDelay() : EffectGeneric(EffectType::Delay) {} EffectDelay::~EffectDelay() = default; void EffectDelay::Update(EffectInfo::InParams& in_params) { const auto* delay_params = reinterpret_cast(in_params.raw.data()); - auto& internal_params = GetParams(); + auto& params = GetParams(); if (!ValidChannelCountForEffect(delay_params->max_channels)) { return; } - const auto last_status = internal_params.status; + const auto last_status = params.status; mix_id = in_params.mix_id; processing_order = in_params.processing_order; - internal_params = *delay_params; + params = *delay_params; if (!ValidChannelCountForEffect(delay_params->channels)) { - internal_params.channels = internal_params.max_channels; + params.channels = params.max_channels; } enabled = in_params.is_enabled; if (last_status != ParameterStatus::Updated) { - internal_params.status = last_status; + params.status = last_status; } if (in_params.is_new || skipped) { usage = UsageState::Initialized; - internal_params.status = ParameterStatus::Initialized; + params.status = ParameterStatus::Initialized; skipped = in_params.buffer_address == 0 || in_params.buffer_size == 0; } } @@ -239,7 +239,7 @@ void EffectDelay::UpdateForCommandGeneration() { GetParams().status = ParameterStatus::Updated; } -EffectBufferMixer::EffectBufferMixer() : EffectGeneric::EffectGeneric(EffectType::BufferMixer) {} +EffectBufferMixer::EffectBufferMixer() : EffectGeneric(EffectType::BufferMixer) {} EffectBufferMixer::~EffectBufferMixer() = default; void EffectBufferMixer::Update(EffectInfo::InParams& in_params) { @@ -257,32 +257,32 @@ void EffectBufferMixer::UpdateForCommandGeneration() { } } -EffectReverb::EffectReverb() : EffectGeneric::EffectGeneric(EffectType::Reverb) {} +EffectReverb::EffectReverb() : EffectGeneric(EffectType::Reverb) {} EffectReverb::~EffectReverb() = default; void EffectReverb::Update(EffectInfo::InParams& in_params) { const auto* reverb_params = reinterpret_cast(in_params.raw.data()); - auto& internal_params = GetParams(); + auto& params = GetParams(); if (!ValidChannelCountForEffect(reverb_params->max_channels)) { return; } - const auto last_status = internal_params.status; + const auto last_status = params.status; mix_id = in_params.mix_id; processing_order = in_params.processing_order; - internal_params = *reverb_params; + params = *reverb_params; if (!ValidChannelCountForEffect(reverb_params->channels)) { - internal_params.channels = internal_params.max_channels; + params.channels = params.max_channels; } enabled = in_params.is_enabled; if (last_status != ParameterStatus::Updated) { - internal_params.status = last_status; + params.status = last_status; } if (in_params.is_new || skipped) { usage = UsageState::Initialized; - internal_params.status = ParameterStatus::Initialized; + params.status = ParameterStatus::Initialized; skipped = in_params.buffer_address == 0 || in_params.buffer_size == 0; } } diff --git a/src/audio_core/effect_context.h b/src/audio_core/effect_context.h index 03c5a0f04..c5e0b398c 100644 --- a/src/audio_core/effect_context.h +++ b/src/audio_core/effect_context.h @@ -184,7 +184,7 @@ struct AuxAddress { class EffectBase { public: - explicit EffectBase(EffectType effect_type); + explicit EffectBase(EffectType effect_type_); virtual ~EffectBase(); virtual void Update(EffectInfo::InParams& in_params) = 0; @@ -206,7 +206,7 @@ protected: template class EffectGeneric : public EffectBase { public: - explicit EffectGeneric(EffectType effect_type) : EffectBase(effect_type) {} + explicit EffectGeneric(EffectType effect_type_) : EffectBase(effect_type_) {} T& GetParams() { return internal_params; @@ -306,7 +306,7 @@ private: class EffectContext { public: - explicit EffectContext(std::size_t effect_count); + explicit EffectContext(std::size_t effect_count_); ~EffectContext(); [[nodiscard]] std::size_t GetCount() const; diff --git a/src/audio_core/info_updater.cpp b/src/audio_core/info_updater.cpp index 2940e53a9..d3ac90827 100644 --- a/src/audio_core/info_updater.cpp +++ b/src/audio_core/info_updater.cpp @@ -14,9 +14,9 @@ namespace AudioCore { -InfoUpdater::InfoUpdater(const std::vector& in_params, std::vector& out_params, - BehaviorInfo& behavior_info) - : in_params(in_params), out_params(out_params), behavior_info(behavior_info) { +InfoUpdater::InfoUpdater(const std::vector& in_params_, std::vector& out_params_, + BehaviorInfo& behavior_info_) + : in_params(in_params_), out_params(out_params_), behavior_info(behavior_info_) { ASSERT( AudioCommon::CanConsumeBuffer(in_params.size(), 0, sizeof(AudioCommon::UpdateDataHeader))); std::memcpy(&input_header, in_params.data(), sizeof(AudioCommon::UpdateDataHeader)); @@ -135,8 +135,8 @@ bool InfoUpdater::UpdateVoiceChannelResources(VoiceContext& voice_context) { } bool InfoUpdater::UpdateVoices(VoiceContext& voice_context, - std::vector& memory_pool_info, - VAddr audio_codec_dsp_addr) { + [[maybe_unused]] std::vector& memory_pool_info, + [[maybe_unused]] VAddr audio_codec_dsp_addr) { const auto voice_count = voice_context.GetVoiceCount(); std::vector voice_in(voice_count); std::vector voice_out(voice_count); @@ -165,28 +165,28 @@ bool InfoUpdater::UpdateVoices(VoiceContext& voice_context, // Update our voices for (std::size_t i = 0; i < voice_count; i++) { - auto& in_params = voice_in[i]; - const auto channel_count = static_cast(in_params.channel_count); + auto& voice_in_params = voice_in[i]; + const auto channel_count = static_cast(voice_in_params.channel_count); // Skip if it's not currently in use - if (!in_params.is_in_use) { + if (!voice_in_params.is_in_use) { continue; } // Voice states for each channel std::array voice_states{}; - ASSERT(static_cast(in_params.id) < voice_count); + ASSERT(static_cast(voice_in_params.id) < voice_count); // Grab our current voice info - auto& voice_info = voice_context.GetInfo(static_cast(in_params.id)); + auto& voice_info = voice_context.GetInfo(static_cast(voice_in_params.id)); ASSERT(channel_count <= AudioCommon::MAX_CHANNEL_COUNT); // Get all our channel voice states for (std::size_t channel = 0; channel < channel_count; channel++) { voice_states[channel] = - &voice_context.GetState(in_params.voice_channel_resource_ids[channel]); + &voice_context.GetState(voice_in_params.voice_channel_resource_ids[channel]); } - if (in_params.is_new) { + if (voice_in_params.is_new) { // Default our values for our voice voice_info.Initialize(); if (channel_count == 0 || channel_count > AudioCommon::MAX_CHANNEL_COUNT) { @@ -200,12 +200,12 @@ bool InfoUpdater::UpdateVoices(VoiceContext& voice_context, } // Update our voice - voice_info.UpdateParameters(in_params, behavior_info); + voice_info.UpdateParameters(voice_in_params, behavior_info); // TODO(ogniK): Handle mapping errors with behavior info based on in params response // Update our wave buffers - voice_info.UpdateWaveBuffers(in_params, voice_states, behavior_info); - voice_info.WriteOutStatus(voice_out[i], in_params, voice_states); + voice_info.UpdateWaveBuffers(voice_in_params, voice_states, behavior_info); + voice_info.WriteOutStatus(voice_out[i], voice_in_params, voice_states); } if (!AudioCommon::CanConsumeBuffer(out_params.size(), output_offset, voice_out_size)) { @@ -445,7 +445,7 @@ bool InfoUpdater::UpdatePerformanceBuffer() { return true; } -bool InfoUpdater::UpdateErrorInfo(BehaviorInfo& in_behavior_info) { +bool InfoUpdater::UpdateErrorInfo([[maybe_unused]] BehaviorInfo& in_behavior_info) { const auto total_beahvior_info_out = sizeof(BehaviorInfo::OutParams); if (!AudioCommon::CanConsumeBuffer(out_params.size(), output_offset, total_beahvior_info_out)) { diff --git a/src/audio_core/info_updater.h b/src/audio_core/info_updater.h index 06f9d770f..d315c91ed 100644 --- a/src/audio_core/info_updater.h +++ b/src/audio_core/info_updater.h @@ -21,8 +21,8 @@ class SplitterContext; class InfoUpdater { public: // TODO(ogniK): Pass process handle when we support it - InfoUpdater(const std::vector& in_params, std::vector& out_params, - BehaviorInfo& behavior_info); + InfoUpdater(const std::vector& in_params_, std::vector& out_params_, + BehaviorInfo& behavior_info_); ~InfoUpdater(); bool UpdateBehaviorInfo(BehaviorInfo& in_behavior_info); diff --git a/src/audio_core/memory_pool.cpp b/src/audio_core/memory_pool.cpp index 5a3453063..6b6908d26 100644 --- a/src/audio_core/memory_pool.cpp +++ b/src/audio_core/memory_pool.cpp @@ -10,11 +10,10 @@ namespace AudioCore { ServerMemoryPoolInfo::ServerMemoryPoolInfo() = default; ServerMemoryPoolInfo::~ServerMemoryPoolInfo() = default; -bool ServerMemoryPoolInfo::Update(const ServerMemoryPoolInfo::InParams& in_params, - ServerMemoryPoolInfo::OutParams& out_params) { + +bool ServerMemoryPoolInfo::Update(const InParams& in_params, OutParams& out_params) { // Our state does not need to be changed - if (in_params.state != ServerMemoryPoolInfo::State::RequestAttach && - in_params.state != ServerMemoryPoolInfo::State::RequestDetach) { + if (in_params.state != State::RequestAttach && in_params.state != State::RequestDetach) { return true; } @@ -32,11 +31,11 @@ bool ServerMemoryPoolInfo::Update(const ServerMemoryPoolInfo::InParams& in_param return false; } - if (in_params.state == ServerMemoryPoolInfo::State::RequestAttach) { + if (in_params.state == State::RequestAttach) { cpu_address = in_params.address; size = in_params.size; used = true; - out_params.state = ServerMemoryPoolInfo::State::Attached; + out_params.state = State::Attached; } else { // Unexpected address if (cpu_address != in_params.address) { @@ -54,7 +53,7 @@ bool ServerMemoryPoolInfo::Update(const ServerMemoryPoolInfo::InParams& in_param cpu_address = 0; size = 0; used = false; - out_params.state = ServerMemoryPoolInfo::State::Detached; + out_params.state = State::Detached; } return true; } diff --git a/src/audio_core/memory_pool.h b/src/audio_core/memory_pool.h index 8ac503f1c..3e9e777ae 100644 --- a/src/audio_core/memory_pool.h +++ b/src/audio_core/memory_pool.h @@ -28,19 +28,18 @@ public: struct InParams { u64_le address{}; u64_le size{}; - ServerMemoryPoolInfo::State state{}; + State state{}; INSERT_PADDING_WORDS(3); }; - static_assert(sizeof(ServerMemoryPoolInfo::InParams) == 0x20, "InParams are an invalid size"); + static_assert(sizeof(InParams) == 0x20, "InParams are an invalid size"); struct OutParams { - ServerMemoryPoolInfo::State state{}; + State state{}; INSERT_PADDING_WORDS(3); }; - static_assert(sizeof(ServerMemoryPoolInfo::OutParams) == 0x10, "OutParams are an invalid size"); + static_assert(sizeof(OutParams) == 0x10, "OutParams are an invalid size"); - bool Update(const ServerMemoryPoolInfo::InParams& in_params, - ServerMemoryPoolInfo::OutParams& out_params); + bool Update(const InParams& in_params, OutParams& out_params); private: // There's another entry here which is the DSP address, however since we're not talking to the diff --git a/src/audio_core/sink_context.cpp b/src/audio_core/sink_context.cpp index b29b47890..a69543696 100644 --- a/src/audio_core/sink_context.cpp +++ b/src/audio_core/sink_context.cpp @@ -5,7 +5,7 @@ #include "audio_core/sink_context.h" namespace AudioCore { -SinkContext::SinkContext(std::size_t sink_count) : sink_count(sink_count) {} +SinkContext::SinkContext(std::size_t sink_count_) : sink_count{sink_count_} {} SinkContext::~SinkContext() = default; std::size_t SinkContext::GetCount() const { diff --git a/src/audio_core/sink_context.h b/src/audio_core/sink_context.h index e2e7880b7..05541becb 100644 --- a/src/audio_core/sink_context.h +++ b/src/audio_core/sink_context.h @@ -42,7 +42,7 @@ public: bool in_use; INSERT_UNION_PADDING_BYTES(5); }; - static_assert(sizeof(SinkInfo::CircularBufferIn) == 0x28, + static_assert(sizeof(CircularBufferIn) == 0x28, "SinkInfo::CircularBufferIn is in invalid size"); struct DeviceIn { @@ -54,7 +54,7 @@ public: bool down_matrix_enabled; DownmixCoefficients down_matrix_coef; }; - static_assert(sizeof(SinkInfo::DeviceIn) == 0x11c, "SinkInfo::DeviceIn is an invalid size"); + static_assert(sizeof(DeviceIn) == 0x11c, "SinkInfo::DeviceIn is an invalid size"); struct InParams { SinkTypes type{}; @@ -64,16 +64,16 @@ public: INSERT_PADDING_WORDS(6); union { // std::array raw{}; - SinkInfo::DeviceIn device; - SinkInfo::CircularBufferIn circular_buffer; + DeviceIn device; + CircularBufferIn circular_buffer; }; }; - static_assert(sizeof(SinkInfo::InParams) == 0x140, "SinkInfo::InParams are an invalid size!"); + static_assert(sizeof(InParams) == 0x140, "SinkInfo::InParams are an invalid size!"); }; class SinkContext { public: - explicit SinkContext(std::size_t sink_count); + explicit SinkContext(std::size_t sink_count_); ~SinkContext(); [[nodiscard]] std::size_t GetCount() const; diff --git a/src/audio_core/splitter_context.cpp b/src/audio_core/splitter_context.cpp index f21b53147..f4bcd0391 100644 --- a/src/audio_core/splitter_context.cpp +++ b/src/audio_core/splitter_context.cpp @@ -10,7 +10,7 @@ namespace AudioCore { -ServerSplitterDestinationData::ServerSplitterDestinationData(s32 id) : id(id) {} +ServerSplitterDestinationData::ServerSplitterDestinationData(s32 id_) : id{id_} {} ServerSplitterDestinationData::~ServerSplitterDestinationData() = default; void ServerSplitterDestinationData::Update(SplitterInfo::InDestinationParams& header) { @@ -87,7 +87,7 @@ void ServerSplitterDestinationData::UpdateInternalState() { needs_update = false; } -ServerSplitterInfo::ServerSplitterInfo(s32 id) : id(id) {} +ServerSplitterInfo::ServerSplitterInfo(s32 id_) : id(id_) {} ServerSplitterInfo::~ServerSplitterInfo() = default; void ServerSplitterInfo::InitializeInfos() { @@ -121,7 +121,7 @@ const ServerSplitterDestinationData* ServerSplitterInfo::GetHead() const { } ServerSplitterDestinationData* ServerSplitterInfo::GetData(std::size_t depth) { - auto current_head = head; + auto* current_head = head; for (std::size_t i = 0; i < depth; i++) { if (current_head == nullptr) { return nullptr; @@ -132,7 +132,7 @@ ServerSplitterDestinationData* ServerSplitterInfo::GetData(std::size_t depth) { } const ServerSplitterDestinationData* ServerSplitterInfo::GetData(std::size_t depth) const { - auto current_head = head; + auto* current_head = head; for (std::size_t i = 0; i < depth; i++) { if (current_head == nullptr) { return nullptr; @@ -245,7 +245,7 @@ ServerSplitterDestinationData* SplitterContext::GetDestinationData(std::size_t i const ServerSplitterDestinationData* SplitterContext::GetDestinationData(std::size_t info, std::size_t data) const { ASSERT(info < info_count); - auto& cur_info = GetInfo(info); + const auto& cur_info = GetInfo(info); return cur_info.GetData(data); } @@ -267,11 +267,11 @@ std::size_t SplitterContext::GetDataCount() const { return data_count; } -void SplitterContext::Setup(std::size_t _info_count, std::size_t _data_count, +void SplitterContext::Setup(std::size_t info_count_, std::size_t data_count_, bool is_splitter_bug_fixed) { - info_count = _info_count; - data_count = _data_count; + info_count = info_count_; + data_count = data_count_; for (std::size_t i = 0; i < info_count; i++) { auto& splitter = infos.emplace_back(static_cast(i)); @@ -364,7 +364,7 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info, // Clear our current destinations auto* current_head = info.GetHead(); while (current_head != nullptr) { - auto next_head = current_head->GetNextDestination(); + auto* next_head = current_head->GetNextDestination(); current_head->SetNextDestination(nullptr); current_head = next_head; } @@ -471,8 +471,8 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) { continue; } - const auto node_count = edge_matrix.GetNodeCount(); - for (s32 j = 0; j < static_cast(node_count); j++) { + const auto edge_node_count = edge_matrix.GetNodeCount(); + for (s32 j = 0; j < static_cast(edge_node_count); j++) { // Check if our node is connected to our edge matrix if (!edge_matrix.Connected(current_stack_index, j)) { continue; diff --git a/src/audio_core/splitter_context.h b/src/audio_core/splitter_context.h index ea6239fdb..b490627f5 100644 --- a/src/audio_core/splitter_context.h +++ b/src/audio_core/splitter_context.h @@ -63,7 +63,7 @@ public: NodeStates(); ~NodeStates(); - void Initialize(std::size_t _node_count); + void Initialize(std::size_t node_count_); bool Tsort(EdgeMatrix& edge_matrix); std::size_t GetIndexPos() const; const std::vector& GetIndexList() const; @@ -72,15 +72,15 @@ private: void PushTsortResult(s32 index); bool DepthFirstSearch(EdgeMatrix& edge_matrix); void ResetState(); - void UpdateState(NodeStates::State state, std::size_t i); - NodeStates::State GetState(std::size_t i); + void UpdateState(State state, std::size_t i); + State GetState(std::size_t i); std::size_t node_count{}; std::vector was_node_found{}; std::vector was_node_completed{}; std::size_t index_pos{}; std::vector index_list{}; - NodeStates::Stack index_stack{}; + Stack index_stack{}; }; enum class SplitterMagic : u32_le { @@ -97,8 +97,7 @@ public: s32_le data_count{}; INSERT_PADDING_WORDS(5); }; - static_assert(sizeof(SplitterInfo::InHeader) == 0x20, - "SplitterInfo::InHeader is an invalid size"); + static_assert(sizeof(InHeader) == 0x20, "SplitterInfo::InHeader is an invalid size"); struct InInfoPrams { SplitterMagic magic{}; @@ -107,8 +106,7 @@ public: s32_le length{}; s32_le resource_id_base{}; }; - static_assert(sizeof(SplitterInfo::InInfoPrams) == 0x14, - "SplitterInfo::InInfoPrams is an invalid size"); + static_assert(sizeof(InInfoPrams) == 0x14, "SplitterInfo::InInfoPrams is an invalid size"); struct InDestinationParams { SplitterMagic magic{}; @@ -118,13 +116,13 @@ public: bool in_use{}; INSERT_PADDING_BYTES(3); }; - static_assert(sizeof(SplitterInfo::InDestinationParams) == 0x70, + static_assert(sizeof(InDestinationParams) == 0x70, "SplitterInfo::InDestinationParams is an invalid size"); }; class ServerSplitterDestinationData { public: - explicit ServerSplitterDestinationData(s32 id); + explicit ServerSplitterDestinationData(s32 id_); ~ServerSplitterDestinationData(); void Update(SplitterInfo::InDestinationParams& header); @@ -153,7 +151,7 @@ private: class ServerSplitterInfo { public: - explicit ServerSplitterInfo(s32 id); + explicit ServerSplitterInfo(s32 id_); ~ServerSplitterInfo(); void InitializeInfos(); diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index 41bc2f4d6..eca296589 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp @@ -31,10 +31,10 @@ u32 Stream::GetNumChannels() const { return {}; } -Stream::Stream(Core::Timing::CoreTiming& core_timing, u32 sample_rate, Format format, - ReleaseCallback&& release_callback, SinkStream& sink_stream, std::string&& name_) - : sample_rate{sample_rate}, format{format}, release_callback{std::move(release_callback)}, - sink_stream{sink_stream}, core_timing{core_timing}, name{std::move(name_)} { +Stream::Stream(Core::Timing::CoreTiming& core_timing_, u32 sample_rate_, Format format_, + ReleaseCallback&& release_callback_, SinkStream& sink_stream_, std::string&& name_) + : sample_rate{sample_rate_}, format{format_}, release_callback{std::move(release_callback_)}, + sink_stream{sink_stream_}, core_timing{core_timing_}, name{std::move(name_)} { release_event = Core::Timing::CreateEvent(name, [this](std::uintptr_t, std::chrono::nanoseconds ns_late) { ReleaseActiveBuffer(ns_late); @@ -122,7 +122,7 @@ bool Stream::QueueBuffer(BufferPtr&& buffer) { return false; } -bool Stream::ContainsBuffer(Buffer::Tag tag) const { +bool Stream::ContainsBuffer([[maybe_unused]] Buffer::Tag tag) const { UNIMPLEMENTED(); return {}; } diff --git a/src/audio_core/stream.h b/src/audio_core/stream.h index 71c2d0b4f..506ac536b 100644 --- a/src/audio_core/stream.h +++ b/src/audio_core/stream.h @@ -44,8 +44,8 @@ public: /// Callback function type, used to change guest state on a buffer being released using ReleaseCallback = std::function; - Stream(Core::Timing::CoreTiming& core_timing, u32 sample_rate, Format format, - ReleaseCallback&& release_callback, SinkStream& sink_stream, std::string&& name_); + Stream(Core::Timing::CoreTiming& core_timing_, u32 sample_rate_, Format format_, + ReleaseCallback&& release_callback_, SinkStream& sink_stream_, std::string&& name_); /// Plays the audio stream void Play(); diff --git a/src/audio_core/voice_context.cpp b/src/audio_core/voice_context.cpp index c46ee55f1..867b8fc6b 100644 --- a/src/audio_core/voice_context.cpp +++ b/src/audio_core/voice_context.cpp @@ -8,7 +8,7 @@ namespace AudioCore { -ServerVoiceChannelResource::ServerVoiceChannelResource(s32 id) : id(id) {} +ServerVoiceChannelResource::ServerVoiceChannelResource(s32 id_) : id(id_) {} ServerVoiceChannelResource::~ServerVoiceChannelResource() = default; bool ServerVoiceChannelResource::InUse() const { @@ -209,7 +209,8 @@ void ServerVoiceInfo::UpdateWaveBuffers( void ServerVoiceInfo::UpdateWaveBuffer(ServerWaveBuffer& out_wavebuffer, const WaveBuffer& in_wave_buffer, SampleFormat sample_format, - bool is_buffer_valid, BehaviorInfo& behavior_info) { + bool is_buffer_valid, + [[maybe_unused]] BehaviorInfo& behavior_info) { if (!is_buffer_valid && out_wavebuffer.sent_to_dsp) { out_wavebuffer.buffer_address = 0; out_wavebuffer.buffer_size = 0; @@ -400,7 +401,7 @@ bool ServerVoiceInfo::HasValidWaveBuffer(const VoiceState* state) const { return std::find(valid_wb.begin(), valid_wb.end(), true) != valid_wb.end(); } -VoiceContext::VoiceContext(std::size_t voice_count) : voice_count(voice_count) { +VoiceContext::VoiceContext(std::size_t voice_count_) : voice_count{voice_count_} { for (std::size_t i = 0; i < voice_count; i++) { voice_channel_resources.emplace_back(static_cast(i)); sorted_voice_info.push_back(&voice_info.emplace_back()); diff --git a/src/audio_core/voice_context.h b/src/audio_core/voice_context.h index 59d3d7dfb..863248761 100644 --- a/src/audio_core/voice_context.h +++ b/src/audio_core/voice_context.h @@ -118,12 +118,12 @@ public: bool in_use{}; INSERT_PADDING_BYTES(11); }; - static_assert(sizeof(VoiceChannelResource::InParams) == 0x70, "InParams is an invalid size"); + static_assert(sizeof(InParams) == 0x70, "InParams is an invalid size"); }; class ServerVoiceChannelResource { public: - explicit ServerVoiceChannelResource(s32 id); + explicit ServerVoiceChannelResource(s32 id_); ~ServerVoiceChannelResource(); bool InUse() const; @@ -174,7 +174,7 @@ public: BehaviorFlags behavior_flags{}; INSERT_PADDING_BYTES(16); }; - static_assert(sizeof(VoiceInfo::InParams) == 0x170, "InParams is an invalid size"); + static_assert(sizeof(InParams) == 0x170, "InParams is an invalid size"); struct OutParams { u64_le played_sample_count{}; @@ -182,7 +182,7 @@ public: u8 voice_dropped{}; INSERT_PADDING_BYTES(3); }; - static_assert(sizeof(VoiceInfo::OutParams) == 0x10, "OutParams is an invalid size"); + static_assert(sizeof(OutParams) == 0x10, "OutParams is an invalid size"); }; class ServerVoiceInfo { @@ -263,7 +263,7 @@ private: class VoiceContext { public: - VoiceContext(std::size_t voice_count); + explicit VoiceContext(std::size_t voice_count_); ~VoiceContext(); std::size_t GetVoiceCount() const; -- cgit v1.2.3 From a1e73602737f1ece64908efd2ebf274ec559ffc1 Mon Sep 17 00:00:00 2001 From: Vitor Kiguchi Date: Fri, 9 Oct 2020 14:15:02 -0300 Subject: Update cubeb and request a persistent stream session --- src/audio_core/cubeb_sink.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/audio_core') diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp index cf7b186e4..043447eaa 100644 --- a/src/audio_core/cubeb_sink.cpp +++ b/src/audio_core/cubeb_sink.cpp @@ -30,6 +30,7 @@ public: params.rate = sample_rate; params.channels = num_channels; params.format = CUBEB_SAMPLE_S16NE; + params.prefs = CUBEB_STREAM_PREF_PERSIST; switch (num_channels) { case 1: params.layout = CUBEB_LAYOUT_MONO; -- cgit v1.2.3 From c7a06908ae1a1c0893876800944e494a0fa03918 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 26 Dec 2020 16:05:56 -0800 Subject: audio_core: stream: Ensure buffer is valid before release. --- src/audio_core/stream.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index eca296589..afe68c9ed 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp @@ -130,7 +130,11 @@ bool Stream::ContainsBuffer([[maybe_unused]] Buffer::Tag tag) const { std::vector Stream::GetTagsAndReleaseBuffers(std::size_t max_count) { std::vector tags; for (std::size_t count = 0; count < max_count && !released_buffers.empty(); ++count) { - tags.push_back(released_buffers.front()->GetTag()); + if (released_buffers.front()) { + tags.push_back(released_buffers.front()->GetTag()); + } else { + ASSERT_MSG(false, "Invalid tag in released_buffers!"); + } released_buffers.pop(); } return tags; @@ -140,7 +144,11 @@ std::vector Stream::GetTagsAndReleaseBuffers() { std::vector tags; tags.reserve(released_buffers.size()); while (!released_buffers.empty()) { - tags.push_back(released_buffers.front()->GetTag()); + if (released_buffers.front()) { + tags.push_back(released_buffers.front()->GetTag()); + } else { + ASSERT_MSG(false, "Invalid tag in released_buffers!"); + } released_buffers.pop(); } return tags; -- cgit v1.2.3 From 7d77a3f88f7a1e68d9846ca7c69cce051d1a33d2 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 28 Dec 2020 18:23:42 -0800 Subject: hle: service: Acquire and release a lock on requests. - This makes it such that we can safely access service members from CoreTiming thread. --- src/audio_core/audio_renderer.cpp | 13 +++++-------- src/audio_core/audio_renderer.h | 8 +------- 2 files changed, 6 insertions(+), 15 deletions(-) (limited to 'src/audio_core') diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp index 179560cd7..d2ce8c814 100644 --- a/src/audio_core/audio_renderer.cpp +++ b/src/audio_core/audio_renderer.cpp @@ -11,7 +11,6 @@ #include "audio_core/info_updater.h" #include "audio_core/voice_context.h" #include "common/logging/log.h" -#include "core/hle/kernel/writable_event.h" #include "core/memory.h" #include "core/settings.h" @@ -71,10 +70,9 @@ namespace { namespace AudioCore { AudioRenderer::AudioRenderer(Core::Timing::CoreTiming& core_timing, Core::Memory::Memory& memory_, AudioCommon::AudioRendererParameter params, - std::shared_ptr buffer_event_, + Stream::ReleaseCallback&& release_callback, std::size_t instance_number) - : worker_params{params}, buffer_event{buffer_event_}, - memory_pool_info(params.effect_count + params.voice_count * 4), + : worker_params{params}, memory_pool_info(params.effect_count + params.voice_count * 4), voice_context(params.voice_count), effect_context(params.effect_count), mix_context(), sink_context(params.sink_count), splitter_context(), voices(params.voice_count), memory{memory_}, @@ -85,10 +83,9 @@ AudioRenderer::AudioRenderer(Core::Timing::CoreTiming& core_timing, Core::Memory params.num_splitter_send_channels); mix_context.Initialize(behavior_info, params.submix_count + 1, params.effect_count); audio_out = std::make_unique(); - stream = - audio_out->OpenStream(core_timing, params.sample_rate, AudioCommon::STREAM_NUM_CHANNELS, - fmt::format("AudioRenderer-Instance{}", instance_number), - [=]() { buffer_event_->Signal(); }); + stream = audio_out->OpenStream( + core_timing, params.sample_rate, AudioCommon::STREAM_NUM_CHANNELS, + fmt::format("AudioRenderer-Instance{}", instance_number), std::move(release_callback)); audio_out->StartStream(stream); QueueMixedBuffer(0); diff --git a/src/audio_core/audio_renderer.h b/src/audio_core/audio_renderer.h index 90f7eafa4..18567f618 100644 --- a/src/audio_core/audio_renderer.h +++ b/src/audio_core/audio_renderer.h @@ -27,10 +27,6 @@ namespace Core::Timing { class CoreTiming; } -namespace Kernel { -class WritableEvent; -} - namespace Core::Memory { class Memory; } @@ -44,8 +40,7 @@ class AudioRenderer { public: AudioRenderer(Core::Timing::CoreTiming& core_timing, Core::Memory::Memory& memory_, AudioCommon::AudioRendererParameter params, - std::shared_ptr buffer_event_, - std::size_t instance_number); + Stream::ReleaseCallback&& release_callback, std::size_t instance_number); ~AudioRenderer(); [[nodiscard]] ResultCode UpdateAudioRenderer(const std::vector& input_params, @@ -61,7 +56,6 @@ private: BehaviorInfo behavior_info{}; AudioCommon::AudioRendererParameter worker_params; - std::shared_ptr buffer_event; std::vector memory_pool_info; VoiceContext voice_context; EffectContext effect_context; -- cgit v1.2.3 From fa5a1a4bfd4b2ba85a9f9644035edfe9a8fd8b68 Mon Sep 17 00:00:00 2001 From: 16-Bit-Dog <67922228+16-Bit-Dog@users.noreply.github.com> Date: Wed, 30 Dec 2020 19:03:26 -0500 Subject: Make the coding conventions more consistant lut_index had 0 added when nothing was supposed to be added despite this, index was not added to 0 when nothing was supposed to be added... --- src/audio_core/algorithm/interpolate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/audio_core') diff --git a/src/audio_core/algorithm/interpolate.cpp b/src/audio_core/algorithm/interpolate.cpp index 699fcb84c..3b4144e21 100644 --- a/src/audio_core/algorithm/interpolate.cpp +++ b/src/audio_core/algorithm/interpolate.cpp @@ -218,7 +218,7 @@ void Resample(s32* output, const s32* input, s32 pitch, s32& fraction, std::size const auto l2 = lut[lut_index + 2]; const auto l3 = lut[lut_index + 3]; - const auto s0 = static_cast(input[index]); + const auto s0 = static_cast(input[index + 0]); const auto s1 = static_cast(input[index + 1]); const auto s2 = static_cast(input[index + 2]); const auto s3 = static_cast(input[index + 3]); -- cgit v1.2.3