summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Rodrigo Locatti2020-09-17 21:19:12 +0000
committerGravatar GitHub2020-09-17 21:19:12 +0000
commit131532b57010c743ad06f7776f9bee73846988db (patch)
tree51fae562dffbfc6fcfbdfa09ce41c0b70b33f1fa /src
parentMerge pull request #4672 from lioncash/narrowing (diff)
parentaudio_core/command_generator: Use const references where applicable (diff)
downloadyuzu-131532b57010c743ad06f7776f9bee73846988db.tar.gz
yuzu-131532b57010c743ad06f7776f9bee73846988db.tar.xz
yuzu-131532b57010c743ad06f7776f9bee73846988db.zip
Merge pull request #4671 from lioncash/nfp-copy
command_generator/nfp: Eliminate unnecessary copies
Diffstat (limited to 'src')
-rw-r--r--src/audio_core/command_generator.cpp23
-rw-r--r--src/core/hle/service/nfp/nfp.cpp23
2 files changed, 25 insertions, 21 deletions
diff --git a/src/audio_core/command_generator.cpp b/src/audio_core/command_generator.cpp
index 84782cde6..8f7da49e6 100644
--- a/src/audio_core/command_generator.cpp
+++ b/src/audio_core/command_generator.cpp
@@ -196,7 +196,7 @@ void CommandGenerator::PreCommand() {
196 for (std::size_t i = 0; i < splitter_context.GetInfoCount(); i++) { 196 for (std::size_t i = 0; i < splitter_context.GetInfoCount(); i++) {
197 const auto& base = splitter_context.GetInfo(i); 197 const auto& base = splitter_context.GetInfo(i);
198 std::string graph = fmt::format("b[{}]", i); 198 std::string graph = fmt::format("b[{}]", i);
199 auto* head = base.GetHead(); 199 const auto* head = base.GetHead();
200 while (head != nullptr) { 200 while (head != nullptr) {
201 graph += fmt::format("->{}", head->GetMixId()); 201 graph += fmt::format("->{}", head->GetMixId());
202 head = head->GetNextDestination(); 202 head = head->GetNextDestination();
@@ -214,7 +214,7 @@ void CommandGenerator::PostCommand() {
214 214
215void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, VoiceState& dsp_state, 215void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, VoiceState& dsp_state,
216 s32 channel) { 216 s32 channel) {
217 auto& in_params = voice_info.GetInParams(); 217 const auto& in_params = voice_info.GetInParams();
218 const auto depop = in_params.should_depop; 218 const auto depop = in_params.should_depop;
219 219
220 if (depop) { 220 if (depop) {
@@ -405,7 +405,7 @@ void CommandGenerator::GenerateBiquadFilterEffectCommand(s32 mix_buffer_offset,
405} 405}
406 406
407void CommandGenerator::GenerateAuxCommand(s32 mix_buffer_offset, EffectBase* info, bool enabled) { 407void CommandGenerator::GenerateAuxCommand(s32 mix_buffer_offset, EffectBase* info, bool enabled) {
408 auto aux = dynamic_cast<EffectAuxInfo*>(info); 408 auto* aux = dynamic_cast<EffectAuxInfo*>(info);
409 const auto& params = aux->GetParams(); 409 const auto& params = aux->GetParams();
410 if (aux->GetSendBuffer() != 0 && aux->GetRecvBuffer() != 0) { 410 if (aux->GetSendBuffer() != 0 && aux->GetRecvBuffer() != 0) {
411 const auto max_channels = params.count; 411 const auto max_channels = params.count;
@@ -571,7 +571,7 @@ void CommandGenerator::GenerateSubMixCommand(ServerMixInfo& mix_info) {
571 if (dumping_frame) { 571 if (dumping_frame) {
572 LOG_DEBUG(Audio, "(DSP_TRACE) GenerateSubMixCommand"); 572 LOG_DEBUG(Audio, "(DSP_TRACE) GenerateSubMixCommand");
573 } 573 }
574 auto& in_params = mix_info.GetInParams(); 574 const auto& in_params = mix_info.GetInParams();
575 GenerateDepopForMixBuffersCommand(in_params.buffer_count, in_params.buffer_offset, 575 GenerateDepopForMixBuffersCommand(in_params.buffer_count, in_params.buffer_offset,
576 in_params.sample_rate); 576 in_params.sample_rate);
577 577
@@ -650,7 +650,7 @@ void CommandGenerator::GenerateFinalMixCommand() {
650 LOG_DEBUG(Audio, "(DSP_TRACE) GenerateFinalMixCommand"); 650 LOG_DEBUG(Audio, "(DSP_TRACE) GenerateFinalMixCommand");
651 } 651 }
652 auto& mix_info = mix_context.GetFinalMixInfo(); 652 auto& mix_info = mix_context.GetFinalMixInfo();
653 const auto in_params = mix_info.GetInParams(); 653 const auto& in_params = mix_info.GetInParams();
654 654
655 GenerateDepopForMixBuffersCommand(in_params.buffer_count, in_params.buffer_offset, 655 GenerateDepopForMixBuffersCommand(in_params.buffer_count, in_params.buffer_offset,
656 in_params.sample_rate); 656 in_params.sample_rate);
@@ -674,7 +674,7 @@ void CommandGenerator::GenerateFinalMixCommand() {
674 674
675s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_state, 675s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_state,
676 s32 sample_count, s32 channel, std::size_t mix_offset) { 676 s32 sample_count, s32 channel, std::size_t mix_offset) {
677 auto& in_params = voice_info.GetInParams(); 677 const auto& in_params = voice_info.GetInParams();
678 const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index]; 678 const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index];
679 if (wave_buffer.buffer_address == 0) { 679 if (wave_buffer.buffer_address == 0) {
680 return 0; 680 return 0;
@@ -714,7 +714,7 @@ s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_s
714 714
715s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_state, 715s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_state,
716 s32 sample_count, s32 channel, std::size_t mix_offset) { 716 s32 sample_count, s32 channel, std::size_t mix_offset) {
717 auto& in_params = voice_info.GetInParams(); 717 const auto& in_params = voice_info.GetInParams();
718 const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index]; 718 const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index];
719 if (wave_buffer.buffer_address == 0) { 719 if (wave_buffer.buffer_address == 0) {
720 return 0; 720 return 0;
@@ -766,8 +766,8 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s
766 val = std::clamp<s32>(val, -32768, 32767); 766 val = std::clamp<s32>(val, -32768, 32767);
767 // Advance output feedback. 767 // Advance output feedback.
768 yn2 = yn1; 768 yn2 = yn1;
769 yn1 = val; 769 yn1 = static_cast<s16>(val);
770 return static_cast<s16>(val); 770 return yn1;
771 }; 771 };
772 772
773 std::size_t buffer_offset{}; 773 std::size_t buffer_offset{};
@@ -853,7 +853,7 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o
853 VoiceState& dsp_state, s32 channel, 853 VoiceState& dsp_state, s32 channel,
854 s32 target_sample_rate, s32 sample_count, 854 s32 target_sample_rate, s32 sample_count,
855 s32 node_id) { 855 s32 node_id) {
856 auto& in_params = voice_info.GetInParams(); 856 const auto& in_params = voice_info.GetInParams();
857 if (dumping_frame) { 857 if (dumping_frame) {
858 LOG_DEBUG(Audio, 858 LOG_DEBUG(Audio,
859 "(DSP_TRACE) DecodeFromWaveBuffers, node_id={}, channel={}, " 859 "(DSP_TRACE) DecodeFromWaveBuffers, node_id={}, channel={}, "
@@ -867,7 +867,8 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o
867 static_cast<float>(in_params.sample_rate) / static_cast<float>(target_sample_rate) * 867 static_cast<float>(in_params.sample_rate) / static_cast<float>(target_sample_rate) *
868 static_cast<float>(static_cast<s32>(in_params.pitch * 32768.0f))); 868 static_cast<float>(static_cast<s32>(in_params.pitch * 32768.0f)));
869 auto* output_base = output; 869 auto* output_base = output;
870 if ((dsp_state.fraction + sample_count * resample_rate) > (SCALED_MIX_BUFFER_SIZE - 4ULL)) { 870 if (dsp_state.fraction + sample_count * resample_rate >
871 static_cast<s32>(SCALED_MIX_BUFFER_SIZE - 4ULL)) {
871 return; 872 return;
872 } 873 }
873 874
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp
index 5e2d769a4..a0469ffbd 100644
--- a/src/core/hle/service/nfp/nfp.cpp
+++ b/src/core/hle/service/nfp/nfp.cpp
@@ -2,6 +2,7 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <array>
5#include <atomic> 6#include <atomic>
6 7
7#include "common/logging/log.h" 8#include "common/logging/log.h"
@@ -72,10 +73,10 @@ private:
72 std::array<u8, 10> uuid; 73 std::array<u8, 10> uuid;
73 u8 uuid_length; // TODO(ogniK): Figure out if this is actual the uuid length or does it 74 u8 uuid_length; // TODO(ogniK): Figure out if this is actual the uuid length or does it
74 // mean something else 75 // mean something else
75 INSERT_PADDING_BYTES(0x15); 76 std::array<u8, 0x15> padding_1;
76 u32_le protocol; 77 u32_le protocol;
77 u32_le tag_type; 78 u32_le tag_type;
78 INSERT_PADDING_BYTES(0x2c); 79 std::array<u8, 0x2c> padding_2;
79 }; 80 };
80 static_assert(sizeof(TagInfo) == 0x54, "TagInfo is an invalid size"); 81 static_assert(sizeof(TagInfo) == 0x54, "TagInfo is an invalid size");
81 82
@@ -213,13 +214,15 @@ private:
213 LOG_DEBUG(Service_NFP, "called"); 214 LOG_DEBUG(Service_NFP, "called");
214 215
215 IPC::ResponseBuilder rb{ctx, 2}; 216 IPC::ResponseBuilder rb{ctx, 2};
216 auto amiibo = nfp_interface.GetAmiiboBuffer(); 217 const auto& amiibo = nfp_interface.GetAmiiboBuffer();
217 TagInfo tag_info{}; 218 const TagInfo tag_info{
218 tag_info.uuid = amiibo.uuid; 219 .uuid = amiibo.uuid,
219 tag_info.uuid_length = static_cast<u8>(tag_info.uuid.size()); 220 .uuid_length = static_cast<u8>(tag_info.uuid.size()),
220 221 .padding_1 = {},
221 tag_info.protocol = 1; // TODO(ogniK): Figure out actual values 222 .protocol = 1, // TODO(ogniK): Figure out actual values
222 tag_info.tag_type = 2; 223 .tag_type = 2,
224 .padding_2 = {},
225 };
223 ctx.WriteBuffer(tag_info); 226 ctx.WriteBuffer(tag_info);
224 rb.Push(RESULT_SUCCESS); 227 rb.Push(RESULT_SUCCESS);
225 } 228 }
@@ -236,7 +239,7 @@ private:
236 LOG_DEBUG(Service_NFP, "called"); 239 LOG_DEBUG(Service_NFP, "called");
237 240
238 IPC::ResponseBuilder rb{ctx, 2}; 241 IPC::ResponseBuilder rb{ctx, 2};
239 auto amiibo = nfp_interface.GetAmiiboBuffer(); 242 const auto& amiibo = nfp_interface.GetAmiiboBuffer();
240 ctx.WriteBuffer(amiibo.model_info); 243 ctx.WriteBuffer(amiibo.model_info);
241 rb.Push(RESULT_SUCCESS); 244 rb.Push(RESULT_SUCCESS);
242 } 245 }