summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2019-01-29 17:33:25 -0500
committerGravatar Lioncash2019-01-29 22:53:35 -0500
commiteb1a3c1f4a33eac87ac0fd3aa75f4f4e28a799ca (patch)
tree29dff63289f7eba9937d3db32b2b65bbe5ebed6c /src
parenthwopus: Fill in the rest of the unknown service function names (diff)
downloadyuzu-eb1a3c1f4a33eac87ac0fd3aa75f4f4e28a799ca.tar.gz
yuzu-eb1a3c1f4a33eac87ac0fd3aa75f4f4e28a799ca.tar.xz
yuzu-eb1a3c1f4a33eac87ac0fd3aa75f4f4e28a799ca.zip
hwopus: Mark local variables as const where applicable
Makes non-mutable state more explicit.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/audio/hwopus.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp
index abe21b992..67aa9f6ad 100644
--- a/src/core/hle/service/audio/hwopus.cpp
+++ b/src/core/hle/service/audio/hwopus.cpp
@@ -95,12 +95,13 @@ private:
95 std::vector<opus_int16>& output, 95 std::vector<opus_int16>& output,
96 std::optional<std::reference_wrapper<u64>> performance_time = std::nullopt) { 96 std::optional<std::reference_wrapper<u64>> performance_time = std::nullopt) {
97 const auto start_time = std::chrono::high_resolution_clock::now(); 97 const auto start_time = std::chrono::high_resolution_clock::now();
98 std::size_t raw_output_sz = output.size() * sizeof(opus_int16); 98 const std::size_t raw_output_sz = output.size() * sizeof(opus_int16);
99 if (sizeof(OpusHeader) > input.size()) { 99 if (sizeof(OpusHeader) > input.size()) {
100 LOG_ERROR(Audio, "Input is smaller than the header size, header_sz={}, input_sz={}", 100 LOG_ERROR(Audio, "Input is smaller than the header size, header_sz={}, input_sz={}",
101 sizeof(OpusHeader), input.size()); 101 sizeof(OpusHeader), input.size());
102 return false; 102 return false;
103 } 103 }
104
104 OpusHeader hdr{}; 105 OpusHeader hdr{};
105 std::memcpy(&hdr, input.data(), sizeof(OpusHeader)); 106 std::memcpy(&hdr, input.data(), sizeof(OpusHeader));
106 if (sizeof(OpusHeader) + static_cast<u32>(hdr.sz) > input.size()) { 107 if (sizeof(OpusHeader) + static_cast<u32>(hdr.sz) > input.size()) {
@@ -108,8 +109,9 @@ private:
108 sizeof(OpusHeader) + static_cast<u32>(hdr.sz), input.size()); 109 sizeof(OpusHeader) + static_cast<u32>(hdr.sz), input.size());
109 return false; 110 return false;
110 } 111 }
111 auto frame = input.data() + sizeof(OpusHeader); 112
112 auto decoded_sample_count = opus_packet_get_nb_samples( 113 const auto frame = input.data() + sizeof(OpusHeader);
114 const auto decoded_sample_count = opus_packet_get_nb_samples(
113 frame, static_cast<opus_int32>(input.size() - sizeof(OpusHeader)), 115 frame, static_cast<opus_int32>(input.size() - sizeof(OpusHeader)),
114 static_cast<opus_int32>(sample_rate)); 116 static_cast<opus_int32>(sample_rate));
115 if (decoded_sample_count * channel_count * sizeof(u16) > raw_output_sz) { 117 if (decoded_sample_count * channel_count * sizeof(u16) > raw_output_sz) {
@@ -119,8 +121,9 @@ private:
119 decoded_sample_count * channel_count * sizeof(u16), raw_output_sz); 121 decoded_sample_count * channel_count * sizeof(u16), raw_output_sz);
120 return false; 122 return false;
121 } 123 }
124
122 const int frame_size = (static_cast<int>(raw_output_sz / sizeof(s16) / channel_count)); 125 const int frame_size = (static_cast<int>(raw_output_sz / sizeof(s16) / channel_count));
123 auto out_sample_count = 126 const auto out_sample_count =
124 opus_decode(decoder.get(), frame, hdr.sz, output.data(), frame_size, 0); 127 opus_decode(decoder.get(), frame, hdr.sz, output.data(), frame_size, 0);
125 if (out_sample_count < 0) { 128 if (out_sample_count < 0) {
126 LOG_ERROR(Audio, 129 LOG_ERROR(Audio,
@@ -129,6 +132,7 @@ private:
129 out_sample_count, frame_size, static_cast<u32>(hdr.sz)); 132 out_sample_count, frame_size, static_cast<u32>(hdr.sz));
130 return false; 133 return false;
131 } 134 }
135
132 const auto end_time = std::chrono::high_resolution_clock::now() - start_time; 136 const auto end_time = std::chrono::high_resolution_clock::now() - start_time;
133 sample_count = out_sample_count; 137 sample_count = out_sample_count;
134 consumed = static_cast<u32>(sizeof(OpusHeader) + hdr.sz); 138 consumed = static_cast<u32>(sizeof(OpusHeader) + hdr.sz);
@@ -136,6 +140,7 @@ private:
136 performance_time->get() = 140 performance_time->get() =
137 std::chrono::duration_cast<std::chrono::milliseconds>(end_time).count(); 141 std::chrono::duration_cast<std::chrono::milliseconds>(end_time).count();
138 } 142 }
143
139 return true; 144 return true;
140 } 145 }
141 146
@@ -159,6 +164,7 @@ void HwOpus::GetWorkBufferSize(Kernel::HLERequestContext& ctx) {
159 IPC::RequestParser rp{ctx}; 164 IPC::RequestParser rp{ctx};
160 const auto sample_rate = rp.Pop<u32>(); 165 const auto sample_rate = rp.Pop<u32>();
161 const auto channel_count = rp.Pop<u32>(); 166 const auto channel_count = rp.Pop<u32>();
167
162 LOG_DEBUG(Audio, "called with sample_rate={}, channel_count={}", sample_rate, channel_count); 168 LOG_DEBUG(Audio, "called with sample_rate={}, channel_count={}", sample_rate, channel_count);
163 169
164 ASSERT_MSG(sample_rate == 48000 || sample_rate == 24000 || sample_rate == 16000 || 170 ASSERT_MSG(sample_rate == 48000 || sample_rate == 24000 || sample_rate == 16000 ||
@@ -176,9 +182,10 @@ void HwOpus::GetWorkBufferSize(Kernel::HLERequestContext& ctx) {
176 182
177void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) { 183void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) {
178 IPC::RequestParser rp{ctx}; 184 IPC::RequestParser rp{ctx};
179 auto sample_rate = rp.Pop<u32>(); 185 const auto sample_rate = rp.Pop<u32>();
180 auto channel_count = rp.Pop<u32>(); 186 const auto channel_count = rp.Pop<u32>();
181 auto buffer_sz = rp.Pop<u32>(); 187 const auto buffer_sz = rp.Pop<u32>();
188
182 LOG_DEBUG(Audio, "called sample_rate={}, channel_count={}, buffer_size={}", sample_rate, 189 LOG_DEBUG(Audio, "called sample_rate={}, channel_count={}, buffer_size={}", sample_rate,
183 channel_count, buffer_sz); 190 channel_count, buffer_sz);
184 191
@@ -187,8 +194,9 @@ void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) {
187 "Invalid sample rate"); 194 "Invalid sample rate");
188 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count"); 195 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count");
189 196
190 std::size_t worker_sz = WorkerBufferSize(channel_count); 197 const std::size_t worker_sz = WorkerBufferSize(channel_count);
191 ASSERT_MSG(buffer_sz >= worker_sz, "Worker buffer too large"); 198 ASSERT_MSG(buffer_sz >= worker_sz, "Worker buffer too large");
199
192 std::unique_ptr<OpusDecoder, OpusDeleter> decoder{ 200 std::unique_ptr<OpusDecoder, OpusDeleter> decoder{
193 static_cast<OpusDecoder*>(operator new(worker_sz))}; 201 static_cast<OpusDecoder*>(operator new(worker_sz))};
194 if (const int err = opus_decoder_init(decoder.get(), sample_rate, channel_count)) { 202 if (const int err = opus_decoder_init(decoder.get(), sample_rate, channel_count)) {