diff options
| -rw-r--r-- | src/audio_core/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/audio_core/audio_out.cpp | 10 | ||||
| -rw-r--r-- | src/audio_core/audio_out.h | 5 | ||||
| -rw-r--r-- | src/audio_core/audio_renderer.cpp | 234 | ||||
| -rw-r--r-- | src/audio_core/audio_renderer.h | 206 | ||||
| -rw-r--r-- | src/audio_core/buffer.h | 13 | ||||
| -rw-r--r-- | src/audio_core/codec.cpp | 77 | ||||
| -rw-r--r-- | src/audio_core/codec.h | 44 | ||||
| -rw-r--r-- | src/audio_core/cubeb_sink.cpp | 54 | ||||
| -rw-r--r-- | src/audio_core/cubeb_sink.h | 3 | ||||
| -rw-r--r-- | src/audio_core/null_sink.h | 6 | ||||
| -rw-r--r-- | src/audio_core/sink.h | 4 | ||||
| -rw-r--r-- | src/audio_core/sink_stream.h | 4 | ||||
| -rw-r--r-- | src/audio_core/stream.cpp | 26 | ||||
| -rw-r--r-- | src/audio_core/stream.h | 7 | ||||
| -rw-r--r-- | src/core/gdbstub/gdbstub.cpp | 164 | ||||
| -rw-r--r-- | src/core/gdbstub/gdbstub.h | 8 | ||||
| -rw-r--r-- | src/core/hle/kernel/address_arbiter.cpp | 30 | ||||
| -rw-r--r-- | src/core/hle/service/audio/audout_u.cpp | 12 | ||||
| -rw-r--r-- | src/core/hle/service/audio/audout_u.h | 10 | ||||
| -rw-r--r-- | src/core/hle/service/audio/audren_u.cpp | 208 | ||||
| -rw-r--r-- | src/core/hle/service/audio/audren_u.h | 19 |
22 files changed, 756 insertions, 392 deletions
diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index 81121167d..827ab0ac7 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt | |||
| @@ -1,9 +1,13 @@ | |||
| 1 | add_library(audio_core STATIC | 1 | add_library(audio_core STATIC |
| 2 | audio_out.cpp | 2 | audio_out.cpp |
| 3 | audio_out.h | 3 | audio_out.h |
| 4 | audio_renderer.cpp | ||
| 5 | audio_renderer.h | ||
| 4 | buffer.h | 6 | buffer.h |
| 5 | cubeb_sink.cpp | 7 | cubeb_sink.cpp |
| 6 | cubeb_sink.h | 8 | cubeb_sink.h |
| 9 | codec.cpp | ||
| 10 | codec.h | ||
| 7 | null_sink.h | 11 | null_sink.h |
| 8 | stream.cpp | 12 | stream.cpp |
| 9 | stream.h | 13 | stream.h |
diff --git a/src/audio_core/audio_out.cpp b/src/audio_core/audio_out.cpp index 3dfdf61f9..12632a95c 100644 --- a/src/audio_core/audio_out.cpp +++ b/src/audio_core/audio_out.cpp | |||
| @@ -27,16 +27,16 @@ static Stream::Format ChannelsToStreamFormat(u32 num_channels) { | |||
| 27 | return {}; | 27 | return {}; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | StreamPtr AudioOut::OpenStream(u32 sample_rate, u32 num_channels, | 30 | StreamPtr AudioOut::OpenStream(u32 sample_rate, u32 num_channels, std::string&& name, |
| 31 | Stream::ReleaseCallback&& release_callback) { | 31 | Stream::ReleaseCallback&& release_callback) { |
| 32 | if (!sink) { | 32 | if (!sink) { |
| 33 | const SinkDetails& sink_details = GetSinkDetails(Settings::values.sink_id); | 33 | const SinkDetails& sink_details = GetSinkDetails(Settings::values.sink_id); |
| 34 | sink = sink_details.factory(Settings::values.audio_device_id); | 34 | sink = sink_details.factory(Settings::values.audio_device_id); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | return std::make_shared<Stream>(sample_rate, ChannelsToStreamFormat(num_channels), | 37 | return std::make_shared<Stream>( |
| 38 | std::move(release_callback), | 38 | sample_rate, ChannelsToStreamFormat(num_channels), std::move(release_callback), |
| 39 | sink->AcquireSinkStream(sample_rate, num_channels)); | 39 | sink->AcquireSinkStream(sample_rate, num_channels, name), std::move(name)); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | std::vector<Buffer::Tag> AudioOut::GetTagsAndReleaseBuffers(StreamPtr stream, size_t max_count) { | 42 | std::vector<Buffer::Tag> AudioOut::GetTagsAndReleaseBuffers(StreamPtr stream, size_t max_count) { |
| @@ -51,7 +51,7 @@ void AudioOut::StopStream(StreamPtr stream) { | |||
| 51 | stream->Stop(); | 51 | stream->Stop(); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | bool AudioOut::QueueBuffer(StreamPtr stream, Buffer::Tag tag, std::vector<u8>&& data) { | 54 | bool AudioOut::QueueBuffer(StreamPtr stream, Buffer::Tag tag, std::vector<s16>&& data) { |
| 55 | return stream->QueueBuffer(std::make_shared<Buffer>(tag, std::move(data))); | 55 | return stream->QueueBuffer(std::make_shared<Buffer>(tag, std::move(data))); |
| 56 | } | 56 | } |
| 57 | 57 | ||
diff --git a/src/audio_core/audio_out.h b/src/audio_core/audio_out.h index 95e9b53fe..39b7e656b 100644 --- a/src/audio_core/audio_out.h +++ b/src/audio_core/audio_out.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <string> | ||
| 8 | #include <vector> | 9 | #include <vector> |
| 9 | 10 | ||
| 10 | #include "audio_core/buffer.h" | 11 | #include "audio_core/buffer.h" |
| @@ -20,7 +21,7 @@ namespace AudioCore { | |||
| 20 | class AudioOut { | 21 | class AudioOut { |
| 21 | public: | 22 | public: |
| 22 | /// Opens a new audio stream | 23 | /// Opens a new audio stream |
| 23 | StreamPtr OpenStream(u32 sample_rate, u32 num_channels, | 24 | StreamPtr OpenStream(u32 sample_rate, u32 num_channels, std::string&& name, |
| 24 | Stream::ReleaseCallback&& release_callback); | 25 | Stream::ReleaseCallback&& release_callback); |
| 25 | 26 | ||
| 26 | /// Returns a vector of recently released buffers specified by tag for the specified stream | 27 | /// Returns a vector of recently released buffers specified by tag for the specified stream |
| @@ -33,7 +34,7 @@ public: | |||
| 33 | void StopStream(StreamPtr stream); | 34 | void StopStream(StreamPtr stream); |
| 34 | 35 | ||
| 35 | /// Queues a buffer into the specified audio stream, returns true on success | 36 | /// Queues a buffer into the specified audio stream, returns true on success |
| 36 | bool QueueBuffer(StreamPtr stream, Buffer::Tag tag, std::vector<u8>&& data); | 37 | bool QueueBuffer(StreamPtr stream, Buffer::Tag tag, std::vector<s16>&& data); |
| 37 | 38 | ||
| 38 | private: | 39 | private: |
| 39 | SinkPtr sink; | 40 | SinkPtr sink; |
diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp new file mode 100644 index 000000000..282f345c5 --- /dev/null +++ b/src/audio_core/audio_renderer.cpp | |||
| @@ -0,0 +1,234 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "audio_core/audio_renderer.h" | ||
| 6 | #include "common/assert.h" | ||
| 7 | #include "common/logging/log.h" | ||
| 8 | #include "core/memory.h" | ||
| 9 | |||
| 10 | namespace AudioCore { | ||
| 11 | |||
| 12 | constexpr u32 STREAM_SAMPLE_RATE{48000}; | ||
| 13 | constexpr u32 STREAM_NUM_CHANNELS{2}; | ||
| 14 | |||
| 15 | AudioRenderer::AudioRenderer(AudioRendererParameter params, | ||
| 16 | Kernel::SharedPtr<Kernel::Event> buffer_event) | ||
| 17 | : worker_params{params}, buffer_event{buffer_event}, voices(params.voice_count) { | ||
| 18 | |||
| 19 | audio_core = std::make_unique<AudioCore::AudioOut>(); | ||
| 20 | stream = audio_core->OpenStream(STREAM_SAMPLE_RATE, STREAM_NUM_CHANNELS, "AudioRenderer", | ||
| 21 | [=]() { buffer_event->Signal(); }); | ||
| 22 | audio_core->StartStream(stream); | ||
| 23 | |||
| 24 | QueueMixedBuffer(0); | ||
| 25 | QueueMixedBuffer(1); | ||
| 26 | QueueMixedBuffer(2); | ||
| 27 | } | ||
| 28 | |||
| 29 | std::vector<u8> AudioRenderer::UpdateAudioRenderer(const std::vector<u8>& input_params) { | ||
| 30 | // Copy UpdateDataHeader struct | ||
| 31 | UpdateDataHeader config{}; | ||
| 32 | std::memcpy(&config, input_params.data(), sizeof(UpdateDataHeader)); | ||
| 33 | u32 memory_pool_count = worker_params.effect_count + (worker_params.voice_count * 4); | ||
| 34 | |||
| 35 | // Copy MemoryPoolInfo structs | ||
| 36 | std::vector<MemoryPoolInfo> mem_pool_info(memory_pool_count); | ||
| 37 | std::memcpy(mem_pool_info.data(), | ||
| 38 | input_params.data() + sizeof(UpdateDataHeader) + config.behavior_size, | ||
| 39 | memory_pool_count * sizeof(MemoryPoolInfo)); | ||
| 40 | |||
| 41 | // Copy VoiceInfo structs | ||
| 42 | size_t offset{sizeof(UpdateDataHeader) + config.behavior_size + config.memory_pools_size + | ||
| 43 | config.voice_resource_size}; | ||
| 44 | for (auto& voice : voices) { | ||
| 45 | std::memcpy(&voice.Info(), input_params.data() + offset, sizeof(VoiceInfo)); | ||
| 46 | offset += sizeof(VoiceInfo); | ||
| 47 | } | ||
| 48 | |||
| 49 | // Update voices | ||
| 50 | for (auto& voice : voices) { | ||
| 51 | voice.UpdateState(); | ||
| 52 | if (!voice.GetInfo().is_in_use) { | ||
| 53 | continue; | ||
| 54 | } | ||
| 55 | if (voice.GetInfo().is_new) { | ||
| 56 | voice.SetWaveIndex(voice.GetInfo().wave_buffer_head); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | // Update memory pool state | ||
| 61 | std::vector<MemoryPoolEntry> memory_pool(memory_pool_count); | ||
| 62 | for (size_t index = 0; index < memory_pool.size(); ++index) { | ||
| 63 | if (mem_pool_info[index].pool_state == MemoryPoolStates::RequestAttach) { | ||
| 64 | memory_pool[index].state = MemoryPoolStates::Attached; | ||
| 65 | } else if (mem_pool_info[index].pool_state == MemoryPoolStates::RequestDetach) { | ||
| 66 | memory_pool[index].state = MemoryPoolStates::Detached; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | // Release previous buffers and queue next ones for playback | ||
| 71 | ReleaseAndQueueBuffers(); | ||
| 72 | |||
| 73 | // Copy output header | ||
| 74 | UpdateDataHeader response_data{worker_params}; | ||
| 75 | std::vector<u8> output_params(response_data.total_size); | ||
| 76 | std::memcpy(output_params.data(), &response_data, sizeof(UpdateDataHeader)); | ||
| 77 | |||
| 78 | // Copy output memory pool entries | ||
| 79 | std::memcpy(output_params.data() + sizeof(UpdateDataHeader), memory_pool.data(), | ||
| 80 | response_data.memory_pools_size); | ||
| 81 | |||
| 82 | // Copy output voice status | ||
| 83 | size_t voice_out_status_offset{sizeof(UpdateDataHeader) + response_data.memory_pools_size}; | ||
| 84 | for (const auto& voice : voices) { | ||
| 85 | std::memcpy(output_params.data() + voice_out_status_offset, &voice.GetOutStatus(), | ||
| 86 | sizeof(VoiceOutStatus)); | ||
| 87 | voice_out_status_offset += sizeof(VoiceOutStatus); | ||
| 88 | } | ||
| 89 | |||
| 90 | return output_params; | ||
| 91 | } | ||
| 92 | |||
| 93 | void AudioRenderer::VoiceState::SetWaveIndex(size_t index) { | ||
| 94 | wave_index = index & 3; | ||
| 95 | is_refresh_pending = true; | ||
| 96 | } | ||
| 97 | |||
| 98 | std::vector<s16> AudioRenderer::VoiceState::DequeueSamples(size_t sample_count) { | ||
| 99 | if (!IsPlaying()) { | ||
| 100 | return {}; | ||
| 101 | } | ||
| 102 | |||
| 103 | if (is_refresh_pending) { | ||
| 104 | RefreshBuffer(); | ||
| 105 | } | ||
| 106 | |||
| 107 | const size_t max_size{samples.size() - offset}; | ||
| 108 | const size_t dequeue_offset{offset}; | ||
| 109 | size_t size{sample_count * STREAM_NUM_CHANNELS}; | ||
| 110 | if (size > max_size) { | ||
| 111 | size = max_size; | ||
| 112 | } | ||
| 113 | |||
| 114 | out_status.played_sample_count += size / STREAM_NUM_CHANNELS; | ||
| 115 | offset += size; | ||
| 116 | |||
| 117 | const auto& wave_buffer{info.wave_buffer[wave_index]}; | ||
| 118 | if (offset == samples.size()) { | ||
| 119 | offset = 0; | ||
| 120 | |||
| 121 | if (!wave_buffer.is_looping) { | ||
| 122 | SetWaveIndex(wave_index + 1); | ||
| 123 | } | ||
| 124 | |||
| 125 | out_status.wave_buffer_consumed++; | ||
| 126 | |||
| 127 | if (wave_buffer.end_of_stream) { | ||
| 128 | info.play_state = PlayState::Paused; | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | return {samples.begin() + dequeue_offset, samples.begin() + dequeue_offset + size}; | ||
| 133 | } | ||
| 134 | |||
| 135 | void AudioRenderer::VoiceState::UpdateState() { | ||
| 136 | if (is_in_use && !info.is_in_use) { | ||
| 137 | // No longer in use, reset state | ||
| 138 | is_refresh_pending = true; | ||
| 139 | wave_index = 0; | ||
| 140 | offset = 0; | ||
| 141 | out_status = {}; | ||
| 142 | } | ||
| 143 | is_in_use = info.is_in_use; | ||
| 144 | } | ||
| 145 | |||
| 146 | void AudioRenderer::VoiceState::RefreshBuffer() { | ||
| 147 | std::vector<s16> new_samples(info.wave_buffer[wave_index].buffer_sz / sizeof(s16)); | ||
| 148 | Memory::ReadBlock(info.wave_buffer[wave_index].buffer_addr, new_samples.data(), | ||
| 149 | info.wave_buffer[wave_index].buffer_sz); | ||
| 150 | |||
| 151 | switch (static_cast<Codec::PcmFormat>(info.sample_format)) { | ||
| 152 | case Codec::PcmFormat::Int16: { | ||
| 153 | // PCM16 is played as-is | ||
| 154 | break; | ||
| 155 | } | ||
| 156 | case Codec::PcmFormat::Adpcm: { | ||
| 157 | // Decode ADPCM to PCM16 | ||
| 158 | Codec::ADPCM_Coeff coeffs; | ||
| 159 | Memory::ReadBlock(info.additional_params_addr, coeffs.data(), sizeof(Codec::ADPCM_Coeff)); | ||
| 160 | new_samples = Codec::DecodeADPCM(reinterpret_cast<u8*>(new_samples.data()), | ||
| 161 | new_samples.size() * sizeof(s16), coeffs, adpcm_state); | ||
| 162 | break; | ||
| 163 | } | ||
| 164 | default: | ||
| 165 | LOG_CRITICAL(Audio, "Unimplemented sample_format={}", info.sample_format); | ||
| 166 | UNREACHABLE(); | ||
| 167 | break; | ||
| 168 | } | ||
| 169 | |||
| 170 | switch (info.channel_count) { | ||
| 171 | case 1: | ||
| 172 | // 1 channel is upsampled to 2 channel | ||
| 173 | samples.resize(new_samples.size() * 2); | ||
| 174 | for (size_t index = 0; index < new_samples.size(); ++index) { | ||
| 175 | samples[index * 2] = new_samples[index]; | ||
| 176 | samples[index * 2 + 1] = new_samples[index]; | ||
| 177 | } | ||
| 178 | break; | ||
| 179 | case 2: { | ||
| 180 | // 2 channel is played as is | ||
| 181 | samples = std::move(new_samples); | ||
| 182 | break; | ||
| 183 | } | ||
| 184 | default: | ||
| 185 | LOG_CRITICAL(Audio, "Unimplemented channel_count={}", info.channel_count); | ||
| 186 | UNREACHABLE(); | ||
| 187 | break; | ||
| 188 | } | ||
| 189 | |||
| 190 | is_refresh_pending = false; | ||
| 191 | } | ||
| 192 | |||
| 193 | static constexpr s16 ClampToS16(s32 value) { | ||
| 194 | return static_cast<s16>(std::clamp(value, -32768, 32767)); | ||
| 195 | } | ||
| 196 | |||
| 197 | void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) { | ||
| 198 | constexpr size_t BUFFER_SIZE{512}; | ||
| 199 | std::vector<s16> buffer(BUFFER_SIZE * stream->GetNumChannels()); | ||
| 200 | |||
| 201 | for (auto& voice : voices) { | ||
| 202 | if (!voice.IsPlaying()) { | ||
| 203 | continue; | ||
| 204 | } | ||
| 205 | |||
| 206 | size_t offset{}; | ||
| 207 | s64 samples_remaining{BUFFER_SIZE}; | ||
| 208 | while (samples_remaining > 0) { | ||
| 209 | const std::vector<s16> samples{voice.DequeueSamples(samples_remaining)}; | ||
| 210 | |||
| 211 | if (samples.empty()) { | ||
| 212 | break; | ||
| 213 | } | ||
| 214 | |||
| 215 | samples_remaining -= samples.size(); | ||
| 216 | |||
| 217 | for (const auto& sample : samples) { | ||
| 218 | const s32 buffer_sample{buffer[offset]}; | ||
| 219 | buffer[offset++] = | ||
| 220 | ClampToS16(buffer_sample + static_cast<s32>(sample * voice.GetInfo().volume)); | ||
| 221 | } | ||
| 222 | } | ||
| 223 | } | ||
| 224 | audio_core->QueueBuffer(stream, tag, std::move(buffer)); | ||
| 225 | } | ||
| 226 | |||
| 227 | void AudioRenderer::ReleaseAndQueueBuffers() { | ||
| 228 | const auto released_buffers{audio_core->GetTagsAndReleaseBuffers(stream, 2)}; | ||
| 229 | for (const auto& tag : released_buffers) { | ||
| 230 | QueueMixedBuffer(tag); | ||
| 231 | } | ||
| 232 | } | ||
| 233 | |||
| 234 | } // namespace AudioCore | ||
diff --git a/src/audio_core/audio_renderer.h b/src/audio_core/audio_renderer.h new file mode 100644 index 000000000..6950a4681 --- /dev/null +++ b/src/audio_core/audio_renderer.h | |||
| @@ -0,0 +1,206 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <memory> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "audio_core/audio_out.h" | ||
| 12 | #include "audio_core/codec.h" | ||
| 13 | #include "audio_core/stream.h" | ||
| 14 | #include "common/common_types.h" | ||
| 15 | #include "common/swap.h" | ||
| 16 | #include "core/hle/kernel/event.h" | ||
| 17 | |||
| 18 | namespace AudioCore { | ||
| 19 | |||
| 20 | enum class PlayState : u8 { | ||
| 21 | Started = 0, | ||
| 22 | Stopped = 1, | ||
| 23 | Paused = 2, | ||
| 24 | }; | ||
| 25 | |||
| 26 | struct AudioRendererParameter { | ||
| 27 | u32_le sample_rate; | ||
| 28 | u32_le sample_count; | ||
| 29 | u32_le unknown_8; | ||
| 30 | u32_le unknown_c; | ||
| 31 | u32_le voice_count; | ||
| 32 | u32_le sink_count; | ||
| 33 | u32_le effect_count; | ||
| 34 | u32_le unknown_1c; | ||
| 35 | u8 unknown_20; | ||
| 36 | INSERT_PADDING_BYTES(3); | ||
| 37 | u32_le splitter_count; | ||
| 38 | u32_le unknown_2c; | ||
| 39 | INSERT_PADDING_WORDS(1); | ||
| 40 | u32_le revision; | ||
| 41 | }; | ||
| 42 | static_assert(sizeof(AudioRendererParameter) == 52, "AudioRendererParameter is an invalid size"); | ||
| 43 | |||
| 44 | enum class MemoryPoolStates : u32 { // Should be LE | ||
| 45 | Invalid = 0x0, | ||
| 46 | Unknown = 0x1, | ||
| 47 | RequestDetach = 0x2, | ||
| 48 | Detached = 0x3, | ||
| 49 | RequestAttach = 0x4, | ||
| 50 | Attached = 0x5, | ||
| 51 | Released = 0x6, | ||
| 52 | }; | ||
| 53 | |||
| 54 | struct MemoryPoolEntry { | ||
| 55 | MemoryPoolStates state; | ||
| 56 | u32_le unknown_4; | ||
| 57 | u32_le unknown_8; | ||
| 58 | u32_le unknown_c; | ||
| 59 | }; | ||
| 60 | static_assert(sizeof(MemoryPoolEntry) == 0x10, "MemoryPoolEntry has wrong size"); | ||
| 61 | |||
| 62 | struct MemoryPoolInfo { | ||
| 63 | u64_le pool_address; | ||
| 64 | u64_le pool_size; | ||
| 65 | MemoryPoolStates pool_state; | ||
| 66 | INSERT_PADDING_WORDS(3); // Unknown | ||
| 67 | }; | ||
| 68 | static_assert(sizeof(MemoryPoolInfo) == 0x20, "MemoryPoolInfo has wrong size"); | ||
| 69 | struct BiquadFilter { | ||
| 70 | u8 enable; | ||
| 71 | INSERT_PADDING_BYTES(1); | ||
| 72 | std::array<s16_le, 3> numerator; | ||
| 73 | std::array<s16_le, 2> denominator; | ||
| 74 | }; | ||
| 75 | static_assert(sizeof(BiquadFilter) == 0xc, "BiquadFilter has wrong size"); | ||
| 76 | |||
| 77 | struct WaveBuffer { | ||
| 78 | u64_le buffer_addr; | ||
| 79 | u64_le buffer_sz; | ||
| 80 | s32_le start_sample_offset; | ||
| 81 | s32_le end_sample_offset; | ||
| 82 | u8 is_looping; | ||
| 83 | u8 end_of_stream; | ||
| 84 | u8 sent_to_server; | ||
| 85 | INSERT_PADDING_BYTES(5); | ||
| 86 | u64 context_addr; | ||
| 87 | u64 context_sz; | ||
| 88 | INSERT_PADDING_BYTES(8); | ||
| 89 | }; | ||
| 90 | static_assert(sizeof(WaveBuffer) == 0x38, "WaveBuffer has wrong size"); | ||
| 91 | |||
| 92 | struct VoiceInfo { | ||
| 93 | u32_le id; | ||
| 94 | u32_le node_id; | ||
| 95 | u8 is_new; | ||
| 96 | u8 is_in_use; | ||
| 97 | PlayState play_state; | ||
| 98 | u8 sample_format; | ||
| 99 | u32_le sample_rate; | ||
| 100 | u32_le priority; | ||
| 101 | u32_le sorting_order; | ||
| 102 | u32_le channel_count; | ||
| 103 | float_le pitch; | ||
| 104 | float_le volume; | ||
| 105 | std::array<BiquadFilter, 2> biquad_filter; | ||
| 106 | u32_le wave_buffer_count; | ||
| 107 | u32_le wave_buffer_head; | ||
| 108 | INSERT_PADDING_WORDS(1); | ||
| 109 | u64_le additional_params_addr; | ||
| 110 | u64_le additional_params_sz; | ||
| 111 | u32_le mix_id; | ||
| 112 | u32_le splitter_info_id; | ||
| 113 | std::array<WaveBuffer, 4> wave_buffer; | ||
| 114 | std::array<u32_le, 6> voice_channel_resource_ids; | ||
| 115 | INSERT_PADDING_BYTES(24); | ||
| 116 | }; | ||
| 117 | static_assert(sizeof(VoiceInfo) == 0x170, "VoiceInfo is wrong size"); | ||
| 118 | |||
| 119 | struct VoiceOutStatus { | ||
| 120 | u64_le played_sample_count; | ||
| 121 | u32_le wave_buffer_consumed; | ||
| 122 | u32_le voice_drops_count; | ||
| 123 | }; | ||
| 124 | static_assert(sizeof(VoiceOutStatus) == 0x10, "VoiceOutStatus has wrong size"); | ||
| 125 | |||
| 126 | struct UpdateDataHeader { | ||
| 127 | UpdateDataHeader() {} | ||
| 128 | |||
| 129 | explicit UpdateDataHeader(const AudioRendererParameter& config) { | ||
| 130 | revision = Common::MakeMagic('R', 'E', 'V', '4'); // 5.1.0 Revision | ||
| 131 | behavior_size = 0xb0; | ||
| 132 | memory_pools_size = (config.effect_count + (config.voice_count * 4)) * 0x10; | ||
| 133 | voices_size = config.voice_count * 0x10; | ||
| 134 | voice_resource_size = 0x0; | ||
| 135 | effects_size = config.effect_count * 0x10; | ||
| 136 | mixes_size = 0x0; | ||
| 137 | sinks_size = config.sink_count * 0x20; | ||
| 138 | performance_manager_size = 0x10; | ||
| 139 | total_size = sizeof(UpdateDataHeader) + behavior_size + memory_pools_size + voices_size + | ||
| 140 | effects_size + sinks_size + performance_manager_size; | ||
| 141 | } | ||
| 142 | |||
| 143 | u32_le revision; | ||
| 144 | u32_le behavior_size; | ||
| 145 | u32_le memory_pools_size; | ||
| 146 | u32_le voices_size; | ||
| 147 | u32_le voice_resource_size; | ||
| 148 | u32_le effects_size; | ||
| 149 | u32_le mixes_size; | ||
| 150 | u32_le sinks_size; | ||
| 151 | u32_le performance_manager_size; | ||
| 152 | INSERT_PADDING_WORDS(6); | ||
| 153 | u32_le total_size; | ||
| 154 | }; | ||
| 155 | static_assert(sizeof(UpdateDataHeader) == 0x40, "UpdateDataHeader has wrong size"); | ||
| 156 | |||
| 157 | class AudioRenderer { | ||
| 158 | public: | ||
| 159 | AudioRenderer(AudioRendererParameter params, Kernel::SharedPtr<Kernel::Event> buffer_event); | ||
| 160 | std::vector<u8> UpdateAudioRenderer(const std::vector<u8>& input_params); | ||
| 161 | void QueueMixedBuffer(Buffer::Tag tag); | ||
| 162 | void ReleaseAndQueueBuffers(); | ||
| 163 | |||
| 164 | private: | ||
| 165 | class VoiceState { | ||
| 166 | public: | ||
| 167 | bool IsPlaying() const { | ||
| 168 | return is_in_use && info.play_state == PlayState::Started; | ||
| 169 | } | ||
| 170 | |||
| 171 | const VoiceOutStatus& GetOutStatus() const { | ||
| 172 | return out_status; | ||
| 173 | } | ||
| 174 | |||
| 175 | const VoiceInfo& GetInfo() const { | ||
| 176 | return info; | ||
| 177 | } | ||
| 178 | |||
| 179 | VoiceInfo& Info() { | ||
| 180 | return info; | ||
| 181 | } | ||
| 182 | |||
| 183 | void SetWaveIndex(size_t index); | ||
| 184 | std::vector<s16> DequeueSamples(size_t sample_count); | ||
| 185 | void UpdateState(); | ||
| 186 | void RefreshBuffer(); | ||
| 187 | |||
| 188 | private: | ||
| 189 | bool is_in_use{}; | ||
| 190 | bool is_refresh_pending{}; | ||
| 191 | size_t wave_index{}; | ||
| 192 | size_t offset{}; | ||
| 193 | Codec::ADPCMState adpcm_state{}; | ||
| 194 | std::vector<s16> samples; | ||
| 195 | VoiceOutStatus out_status{}; | ||
| 196 | VoiceInfo info{}; | ||
| 197 | }; | ||
| 198 | |||
| 199 | AudioRendererParameter worker_params; | ||
| 200 | Kernel::SharedPtr<Kernel::Event> buffer_event; | ||
| 201 | std::vector<VoiceState> voices; | ||
| 202 | std::unique_ptr<AudioCore::AudioOut> audio_core; | ||
| 203 | AudioCore::StreamPtr stream; | ||
| 204 | }; | ||
| 205 | |||
| 206 | } // namespace AudioCore | ||
diff --git a/src/audio_core/buffer.h b/src/audio_core/buffer.h index 4bf5fd58a..a323b23ec 100644 --- a/src/audio_core/buffer.h +++ b/src/audio_core/buffer.h | |||
| @@ -18,11 +18,16 @@ class Buffer { | |||
| 18 | public: | 18 | public: |
| 19 | using Tag = u64; | 19 | using Tag = u64; |
| 20 | 20 | ||
| 21 | Buffer(Tag tag, std::vector<u8>&& data) : tag{tag}, data{std::move(data)} {} | 21 | Buffer(Tag tag, std::vector<s16>&& samples) : tag{tag}, samples{std::move(samples)} {} |
| 22 | 22 | ||
| 23 | /// Returns the raw audio data for the buffer | 23 | /// Returns the raw audio data for the buffer |
| 24 | const std::vector<u8>& GetData() const { | 24 | std::vector<s16>& Samples() { |
| 25 | return data; | 25 | return samples; |
| 26 | } | ||
| 27 | |||
| 28 | /// Returns the raw audio data for the buffer | ||
| 29 | const std::vector<s16>& GetSamples() const { | ||
| 30 | return samples; | ||
| 26 | } | 31 | } |
| 27 | 32 | ||
| 28 | /// Returns the buffer tag, this is provided by the game to the audout service | 33 | /// Returns the buffer tag, this is provided by the game to the audout service |
| @@ -32,7 +37,7 @@ public: | |||
| 32 | 37 | ||
| 33 | private: | 38 | private: |
| 34 | Tag tag; | 39 | Tag tag; |
| 35 | std::vector<u8> data; | 40 | std::vector<s16> samples; |
| 36 | }; | 41 | }; |
| 37 | 42 | ||
| 38 | using BufferPtr = std::shared_ptr<Buffer>; | 43 | using BufferPtr = std::shared_ptr<Buffer>; |
diff --git a/src/audio_core/codec.cpp b/src/audio_core/codec.cpp new file mode 100644 index 000000000..c3021403f --- /dev/null +++ b/src/audio_core/codec.cpp | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | |||
| 7 | #include "audio_core/codec.h" | ||
| 8 | |||
| 9 | namespace AudioCore::Codec { | ||
| 10 | |||
| 11 | std::vector<s16> DecodeADPCM(const u8* const data, size_t size, const ADPCM_Coeff& coeff, | ||
| 12 | ADPCMState& state) { | ||
| 13 | // GC-ADPCM with scale factor and variable coefficients. | ||
| 14 | // Frames are 8 bytes long containing 14 samples each. | ||
| 15 | // Samples are 4 bits (one nibble) long. | ||
| 16 | |||
| 17 | constexpr size_t FRAME_LEN = 8; | ||
| 18 | constexpr size_t SAMPLES_PER_FRAME = 14; | ||
| 19 | constexpr std::array<int, 16> SIGNED_NIBBLES = { | ||
| 20 | {0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1}}; | ||
| 21 | |||
| 22 | const size_t sample_count = (size / FRAME_LEN) * SAMPLES_PER_FRAME; | ||
| 23 | const size_t ret_size = | ||
| 24 | sample_count % 2 == 0 ? sample_count : sample_count + 1; // Ensure multiple of two. | ||
| 25 | std::vector<s16> ret(ret_size); | ||
| 26 | |||
| 27 | int yn1 = state.yn1, yn2 = state.yn2; | ||
| 28 | |||
| 29 | const size_t NUM_FRAMES = | ||
| 30 | (sample_count + (SAMPLES_PER_FRAME - 1)) / SAMPLES_PER_FRAME; // Round up. | ||
| 31 | for (size_t framei = 0; framei < NUM_FRAMES; framei++) { | ||
| 32 | const int frame_header = data[framei * FRAME_LEN]; | ||
| 33 | const int scale = 1 << (frame_header & 0xF); | ||
| 34 | const int idx = (frame_header >> 4) & 0x7; | ||
| 35 | |||
| 36 | // Coefficients are fixed point with 11 bits fractional part. | ||
| 37 | const int coef1 = coeff[idx * 2 + 0]; | ||
| 38 | const int coef2 = coeff[idx * 2 + 1]; | ||
| 39 | |||
| 40 | // Decodes an audio sample. One nibble produces one sample. | ||
| 41 | const auto decode_sample = [&](const int nibble) -> s16 { | ||
| 42 | const int xn = nibble * scale; | ||
| 43 | // We first transform everything into 11 bit fixed point, perform the second order | ||
| 44 | // digital filter, then transform back. | ||
| 45 | // 0x400 == 0.5 in 11 bit fixed point. | ||
| 46 | // Filter: y[n] = x[n] + 0.5 + c1 * y[n-1] + c2 * y[n-2] | ||
| 47 | int val = ((xn << 11) + 0x400 + coef1 * yn1 + coef2 * yn2) >> 11; | ||
| 48 | // Clamp to output range. | ||
| 49 | val = std::clamp<s32>(val, -32768, 32767); | ||
| 50 | // Advance output feedback. | ||
| 51 | yn2 = yn1; | ||
| 52 | yn1 = val; | ||
| 53 | return static_cast<s16>(val); | ||
| 54 | }; | ||
| 55 | |||
| 56 | size_t outputi = framei * SAMPLES_PER_FRAME; | ||
| 57 | size_t datai = framei * FRAME_LEN + 1; | ||
| 58 | for (size_t i = 0; i < SAMPLES_PER_FRAME && outputi < sample_count; i += 2) { | ||
| 59 | const s16 sample1 = decode_sample(SIGNED_NIBBLES[data[datai] >> 4]); | ||
| 60 | ret[outputi] = sample1; | ||
| 61 | outputi++; | ||
| 62 | |||
| 63 | const s16 sample2 = decode_sample(SIGNED_NIBBLES[data[datai] & 0xF]); | ||
| 64 | ret[outputi] = sample2; | ||
| 65 | outputi++; | ||
| 66 | |||
| 67 | datai++; | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | state.yn1 = yn1; | ||
| 72 | state.yn2 = yn2; | ||
| 73 | |||
| 74 | return ret; | ||
| 75 | } | ||
| 76 | |||
| 77 | } // namespace AudioCore::Codec | ||
diff --git a/src/audio_core/codec.h b/src/audio_core/codec.h new file mode 100644 index 000000000..3f845c42c --- /dev/null +++ b/src/audio_core/codec.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "common/common_types.h" | ||
| 11 | |||
| 12 | namespace AudioCore::Codec { | ||
| 13 | |||
| 14 | enum class PcmFormat : u32 { | ||
| 15 | Invalid = 0, | ||
| 16 | Int8 = 1, | ||
| 17 | Int16 = 2, | ||
| 18 | Int24 = 3, | ||
| 19 | Int32 = 4, | ||
| 20 | PcmFloat = 5, | ||
| 21 | Adpcm = 6, | ||
| 22 | }; | ||
| 23 | |||
| 24 | /// See: Codec::DecodeADPCM | ||
| 25 | struct ADPCMState { | ||
| 26 | // Two historical samples from previous processed buffer, | ||
| 27 | // required for ADPCM decoding | ||
| 28 | s16 yn1; ///< y[n-1] | ||
| 29 | s16 yn2; ///< y[n-2] | ||
| 30 | }; | ||
| 31 | |||
| 32 | using ADPCM_Coeff = std::array<s16, 16>; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * @param data Pointer to buffer that contains ADPCM data to decode | ||
| 36 | * @param size Size of buffer in bytes | ||
| 37 | * @param coeff ADPCM coefficients | ||
| 38 | * @param state ADPCM state, this is updated with new state | ||
| 39 | * @return Decoded stereo signed PCM16 data, sample_count in length | ||
| 40 | */ | ||
| 41 | std::vector<s16> DecodeADPCM(const u8* const data, size_t size, const ADPCM_Coeff& coeff, | ||
| 42 | ADPCMState& state); | ||
| 43 | |||
| 44 | }; // namespace AudioCore::Codec | ||
diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp index 34ae5b062..1501ef1f4 100644 --- a/src/audio_core/cubeb_sink.cpp +++ b/src/audio_core/cubeb_sink.cpp | |||
| @@ -13,20 +13,30 @@ namespace AudioCore { | |||
| 13 | 13 | ||
| 14 | class SinkStreamImpl final : public SinkStream { | 14 | class SinkStreamImpl final : public SinkStream { |
| 15 | public: | 15 | public: |
| 16 | SinkStreamImpl(cubeb* ctx, cubeb_devid output_device) : ctx{ctx} { | 16 | SinkStreamImpl(cubeb* ctx, u32 sample_rate, u32 num_channels_, cubeb_devid output_device, |
| 17 | cubeb_stream_params params; | 17 | const std::string& name) |
| 18 | params.rate = 48000; | 18 | : ctx{ctx}, num_channels{num_channels_} { |
| 19 | params.channels = GetNumChannels(); | 19 | |
| 20 | if (num_channels == 6) { | ||
| 21 | // 6-channel audio does not seem to work with cubeb + SDL, so we downsample this to 2 | ||
| 22 | // channel for now | ||
| 23 | is_6_channel = true; | ||
| 24 | num_channels = 2; | ||
| 25 | } | ||
| 26 | |||
| 27 | cubeb_stream_params params{}; | ||
| 28 | params.rate = sample_rate; | ||
| 29 | params.channels = num_channels; | ||
| 20 | params.format = CUBEB_SAMPLE_S16NE; | 30 | params.format = CUBEB_SAMPLE_S16NE; |
| 21 | params.layout = CUBEB_LAYOUT_STEREO; | 31 | params.layout = num_channels == 1 ? CUBEB_LAYOUT_MONO : CUBEB_LAYOUT_STEREO; |
| 22 | 32 | ||
| 23 | u32 minimum_latency = 0; | 33 | u32 minimum_latency{}; |
| 24 | if (cubeb_get_min_latency(ctx, ¶ms, &minimum_latency) != CUBEB_OK) { | 34 | if (cubeb_get_min_latency(ctx, ¶ms, &minimum_latency) != CUBEB_OK) { |
| 25 | LOG_CRITICAL(Audio_Sink, "Error getting minimum latency"); | 35 | LOG_CRITICAL(Audio_Sink, "Error getting minimum latency"); |
| 26 | } | 36 | } |
| 27 | 37 | ||
| 28 | if (cubeb_stream_init(ctx, &stream_backend, "yuzu Audio Output", nullptr, nullptr, | 38 | if (cubeb_stream_init(ctx, &stream_backend, name.c_str(), nullptr, nullptr, output_device, |
| 29 | output_device, ¶ms, std::max(512u, minimum_latency), | 39 | ¶ms, std::max(512u, minimum_latency), |
| 30 | &SinkStreamImpl::DataCallback, &SinkStreamImpl::StateCallback, | 40 | &SinkStreamImpl::DataCallback, &SinkStreamImpl::StateCallback, |
| 31 | this) != CUBEB_OK) { | 41 | this) != CUBEB_OK) { |
| 32 | LOG_CRITICAL(Audio_Sink, "Error initializing cubeb stream"); | 42 | LOG_CRITICAL(Audio_Sink, "Error initializing cubeb stream"); |
| @@ -51,33 +61,29 @@ public: | |||
| 51 | cubeb_stream_destroy(stream_backend); | 61 | cubeb_stream_destroy(stream_backend); |
| 52 | } | 62 | } |
| 53 | 63 | ||
| 54 | void EnqueueSamples(u32 num_channels, const s16* samples, size_t sample_count) override { | 64 | void EnqueueSamples(u32 num_channels, const std::vector<s16>& samples) override { |
| 55 | if (!ctx) { | 65 | if (!ctx) { |
| 56 | return; | 66 | return; |
| 57 | } | 67 | } |
| 58 | 68 | ||
| 59 | queue.reserve(queue.size() + sample_count * GetNumChannels()); | 69 | queue.reserve(queue.size() + samples.size() * GetNumChannels()); |
| 60 | 70 | ||
| 61 | if (num_channels == 2) { | 71 | if (is_6_channel) { |
| 62 | // Copy as-is | ||
| 63 | std::copy(samples, samples + sample_count * GetNumChannels(), | ||
| 64 | std::back_inserter(queue)); | ||
| 65 | } else if (num_channels == 6) { | ||
| 66 | // Downsample 6 channels to 2 | 72 | // Downsample 6 channels to 2 |
| 67 | const size_t sample_count_copy_size = sample_count * num_channels * 2; | 73 | const size_t sample_count_copy_size = samples.size() * 2; |
| 68 | queue.reserve(sample_count_copy_size); | 74 | queue.reserve(sample_count_copy_size); |
| 69 | for (size_t i = 0; i < sample_count * num_channels; i += num_channels) { | 75 | for (size_t i = 0; i < samples.size(); i += num_channels) { |
| 70 | queue.push_back(samples[i]); | 76 | queue.push_back(samples[i]); |
| 71 | queue.push_back(samples[i + 1]); | 77 | queue.push_back(samples[i + 1]); |
| 72 | } | 78 | } |
| 73 | } else { | 79 | } else { |
| 74 | ASSERT_MSG(false, "Unimplemented"); | 80 | // Copy as-is |
| 81 | std::copy(samples.begin(), samples.end(), std::back_inserter(queue)); | ||
| 75 | } | 82 | } |
| 76 | } | 83 | } |
| 77 | 84 | ||
| 78 | u32 GetNumChannels() const { | 85 | u32 GetNumChannels() const { |
| 79 | // Only support 2-channel stereo output for now | 86 | return num_channels; |
| 80 | return 2; | ||
| 81 | } | 87 | } |
| 82 | 88 | ||
| 83 | private: | 89 | private: |
| @@ -85,6 +91,8 @@ private: | |||
| 85 | 91 | ||
| 86 | cubeb* ctx{}; | 92 | cubeb* ctx{}; |
| 87 | cubeb_stream* stream_backend{}; | 93 | cubeb_stream* stream_backend{}; |
| 94 | u32 num_channels{}; | ||
| 95 | bool is_6_channel{}; | ||
| 88 | 96 | ||
| 89 | std::vector<s16> queue; | 97 | std::vector<s16> queue; |
| 90 | 98 | ||
| @@ -129,8 +137,10 @@ CubebSink::~CubebSink() { | |||
| 129 | cubeb_destroy(ctx); | 137 | cubeb_destroy(ctx); |
| 130 | } | 138 | } |
| 131 | 139 | ||
| 132 | SinkStream& CubebSink::AcquireSinkStream(u32 sample_rate, u32 num_channels) { | 140 | SinkStream& CubebSink::AcquireSinkStream(u32 sample_rate, u32 num_channels, |
| 133 | sink_streams.push_back(std::make_unique<SinkStreamImpl>(ctx, output_device)); | 141 | const std::string& name) { |
| 142 | sink_streams.push_back( | ||
| 143 | std::make_unique<SinkStreamImpl>(ctx, sample_rate, num_channels, output_device, name)); | ||
| 134 | return *sink_streams.back(); | 144 | return *sink_streams.back(); |
| 135 | } | 145 | } |
| 136 | 146 | ||
diff --git a/src/audio_core/cubeb_sink.h b/src/audio_core/cubeb_sink.h index d07113f1f..59cbf05e9 100644 --- a/src/audio_core/cubeb_sink.h +++ b/src/audio_core/cubeb_sink.h | |||
| @@ -18,7 +18,8 @@ public: | |||
| 18 | explicit CubebSink(std::string device_id); | 18 | explicit CubebSink(std::string device_id); |
| 19 | ~CubebSink() override; | 19 | ~CubebSink() override; |
| 20 | 20 | ||
| 21 | SinkStream& AcquireSinkStream(u32 sample_rate, u32 num_channels) override; | 21 | SinkStream& AcquireSinkStream(u32 sample_rate, u32 num_channels, |
| 22 | const std::string& name) override; | ||
| 22 | 23 | ||
| 23 | private: | 24 | private: |
| 24 | cubeb* ctx{}; | 25 | cubeb* ctx{}; |
diff --git a/src/audio_core/null_sink.h b/src/audio_core/null_sink.h index 2e04438f7..f235d93e5 100644 --- a/src/audio_core/null_sink.h +++ b/src/audio_core/null_sink.h | |||
| @@ -13,14 +13,14 @@ public: | |||
| 13 | explicit NullSink(std::string){}; | 13 | explicit NullSink(std::string){}; |
| 14 | ~NullSink() override = default; | 14 | ~NullSink() override = default; |
| 15 | 15 | ||
| 16 | SinkStream& AcquireSinkStream(u32 /*sample_rate*/, u32 /*num_channels*/) override { | 16 | SinkStream& AcquireSinkStream(u32 /*sample_rate*/, u32 /*num_channels*/, |
| 17 | const std::string& /*name*/) override { | ||
| 17 | return null_sink_stream; | 18 | return null_sink_stream; |
| 18 | } | 19 | } |
| 19 | 20 | ||
| 20 | private: | 21 | private: |
| 21 | struct NullSinkStreamImpl final : SinkStream { | 22 | struct NullSinkStreamImpl final : SinkStream { |
| 22 | void EnqueueSamples(u32 /*num_channels*/, const s16* /*samples*/, | 23 | void EnqueueSamples(u32 /*num_channels*/, const std::vector<s16>& /*samples*/) override {} |
| 23 | size_t /*sample_count*/) override {} | ||
| 24 | } null_sink_stream; | 24 | } null_sink_stream; |
| 25 | }; | 25 | }; |
| 26 | 26 | ||
diff --git a/src/audio_core/sink.h b/src/audio_core/sink.h index d1bb98c3d..95c7b2b6e 100644 --- a/src/audio_core/sink.h +++ b/src/audio_core/sink.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <string> | ||
| 8 | 9 | ||
| 9 | #include "audio_core/sink_stream.h" | 10 | #include "audio_core/sink_stream.h" |
| 10 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| @@ -21,7 +22,8 @@ constexpr char auto_device_name[] = "auto"; | |||
| 21 | class Sink { | 22 | class Sink { |
| 22 | public: | 23 | public: |
| 23 | virtual ~Sink() = default; | 24 | virtual ~Sink() = default; |
| 24 | virtual SinkStream& AcquireSinkStream(u32 sample_rate, u32 num_channels) = 0; | 25 | virtual SinkStream& AcquireSinkStream(u32 sample_rate, u32 num_channels, |
| 26 | const std::string& name) = 0; | ||
| 25 | }; | 27 | }; |
| 26 | 28 | ||
| 27 | using SinkPtr = std::unique_ptr<Sink>; | 29 | using SinkPtr = std::unique_ptr<Sink>; |
diff --git a/src/audio_core/sink_stream.h b/src/audio_core/sink_stream.h index e7a3f01b0..41b6736d8 100644 --- a/src/audio_core/sink_stream.h +++ b/src/audio_core/sink_stream.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <vector> | ||
| 8 | 9 | ||
| 9 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 10 | 11 | ||
| @@ -22,9 +23,8 @@ public: | |||
| 22 | * Feed stereo samples to sink. | 23 | * Feed stereo samples to sink. |
| 23 | * @param num_channels Number of channels used. | 24 | * @param num_channels Number of channels used. |
| 24 | * @param samples Samples in interleaved stereo PCM16 format. | 25 | * @param samples Samples in interleaved stereo PCM16 format. |
| 25 | * @param sample_count Number of samples. | ||
| 26 | */ | 26 | */ |
| 27 | virtual void EnqueueSamples(u32 num_channels, const s16* samples, size_t sample_count) = 0; | 27 | virtual void EnqueueSamples(u32 num_channels, const std::vector<s16>& samples) = 0; |
| 28 | }; | 28 | }; |
| 29 | 29 | ||
| 30 | using SinkStreamPtr = std::unique_ptr<SinkStream>; | 30 | using SinkStreamPtr = std::unique_ptr<SinkStream>; |
diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index a0045b7a1..ad9e2915c 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp | |||
| @@ -32,17 +32,13 @@ u32 Stream::GetNumChannels() const { | |||
| 32 | return {}; | 32 | return {}; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | u32 Stream::GetSampleSize() const { | ||
| 36 | return GetNumChannels() * 2; | ||
| 37 | } | ||
| 38 | |||
| 39 | Stream::Stream(u32 sample_rate, Format format, ReleaseCallback&& release_callback, | 35 | Stream::Stream(u32 sample_rate, Format format, ReleaseCallback&& release_callback, |
| 40 | SinkStream& sink_stream) | 36 | SinkStream& sink_stream, std::string&& name_) |
| 41 | : sample_rate{sample_rate}, format{format}, release_callback{std::move(release_callback)}, | 37 | : sample_rate{sample_rate}, format{format}, release_callback{std::move(release_callback)}, |
| 42 | sink_stream{sink_stream} { | 38 | sink_stream{sink_stream}, name{std::move(name_)} { |
| 43 | 39 | ||
| 44 | release_event = CoreTiming::RegisterEvent( | 40 | release_event = CoreTiming::RegisterEvent( |
| 45 | "Stream::Release", [this](u64 userdata, int cycles_late) { ReleaseActiveBuffer(); }); | 41 | name, [this](u64 userdata, int cycles_late) { ReleaseActiveBuffer(); }); |
| 46 | } | 42 | } |
| 47 | 43 | ||
| 48 | void Stream::Play() { | 44 | void Stream::Play() { |
| @@ -55,17 +51,15 @@ void Stream::Stop() { | |||
| 55 | } | 51 | } |
| 56 | 52 | ||
| 57 | s64 Stream::GetBufferReleaseCycles(const Buffer& buffer) const { | 53 | s64 Stream::GetBufferReleaseCycles(const Buffer& buffer) const { |
| 58 | const size_t num_samples{buffer.GetData().size() / GetSampleSize()}; | 54 | const size_t num_samples{buffer.GetSamples().size() / GetNumChannels()}; |
| 59 | return CoreTiming::usToCycles((static_cast<u64>(num_samples) * 1000000) / sample_rate); | 55 | return CoreTiming::usToCycles((static_cast<u64>(num_samples) * 1000000) / sample_rate); |
| 60 | } | 56 | } |
| 61 | 57 | ||
| 62 | static std::vector<s16> GetVolumeAdjustedSamples(const std::vector<u8>& data) { | 58 | static void VolumeAdjustSamples(std::vector<s16>& samples) { |
| 63 | std::vector<s16> samples(data.size() / sizeof(s16)); | ||
| 64 | std::memcpy(samples.data(), data.data(), data.size()); | ||
| 65 | const float volume{std::clamp(Settings::values.volume, 0.0f, 1.0f)}; | 59 | const float volume{std::clamp(Settings::values.volume, 0.0f, 1.0f)}; |
| 66 | 60 | ||
| 67 | if (volume == 1.0f) { | 61 | if (volume == 1.0f) { |
| 68 | return samples; | 62 | return; |
| 69 | } | 63 | } |
| 70 | 64 | ||
| 71 | // Implementation of a volume slider with a dynamic range of 60 dB | 65 | // Implementation of a volume slider with a dynamic range of 60 dB |
| @@ -73,8 +67,6 @@ static std::vector<s16> GetVolumeAdjustedSamples(const std::vector<u8>& data) { | |||
| 73 | for (auto& sample : samples) { | 67 | for (auto& sample : samples) { |
| 74 | sample = static_cast<s16>(sample * volume_scale_factor); | 68 | sample = static_cast<s16>(sample * volume_scale_factor); |
| 75 | } | 69 | } |
| 76 | |||
| 77 | return samples; | ||
| 78 | } | 70 | } |
| 79 | 71 | ||
| 80 | void Stream::PlayNextBuffer() { | 72 | void Stream::PlayNextBuffer() { |
| @@ -96,14 +88,14 @@ void Stream::PlayNextBuffer() { | |||
| 96 | active_buffer = queued_buffers.front(); | 88 | active_buffer = queued_buffers.front(); |
| 97 | queued_buffers.pop(); | 89 | queued_buffers.pop(); |
| 98 | 90 | ||
| 99 | const size_t sample_count{active_buffer->GetData().size() / GetSampleSize()}; | 91 | VolumeAdjustSamples(active_buffer->Samples()); |
| 100 | sink_stream.EnqueueSamples( | 92 | sink_stream.EnqueueSamples(GetNumChannels(), active_buffer->GetSamples()); |
| 101 | GetNumChannels(), GetVolumeAdjustedSamples(active_buffer->GetData()).data(), sample_count); | ||
| 102 | 93 | ||
| 103 | CoreTiming::ScheduleEventThreadsafe(GetBufferReleaseCycles(*active_buffer), release_event, {}); | 94 | CoreTiming::ScheduleEventThreadsafe(GetBufferReleaseCycles(*active_buffer), release_event, {}); |
| 104 | } | 95 | } |
| 105 | 96 | ||
| 106 | void Stream::ReleaseActiveBuffer() { | 97 | void Stream::ReleaseActiveBuffer() { |
| 98 | ASSERT(active_buffer); | ||
| 107 | released_buffers.push(std::move(active_buffer)); | 99 | released_buffers.push(std::move(active_buffer)); |
| 108 | release_callback(); | 100 | release_callback(); |
| 109 | PlayNextBuffer(); | 101 | PlayNextBuffer(); |
diff --git a/src/audio_core/stream.h b/src/audio_core/stream.h index 35253920e..049b92ca9 100644 --- a/src/audio_core/stream.h +++ b/src/audio_core/stream.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <functional> | 7 | #include <functional> |
| 8 | #include <memory> | 8 | #include <memory> |
| 9 | #include <string> | ||
| 9 | #include <vector> | 10 | #include <vector> |
| 10 | #include <queue> | 11 | #include <queue> |
| 11 | 12 | ||
| @@ -33,7 +34,7 @@ public: | |||
| 33 | using ReleaseCallback = std::function<void()>; | 34 | using ReleaseCallback = std::function<void()>; |
| 34 | 35 | ||
| 35 | Stream(u32 sample_rate, Format format, ReleaseCallback&& release_callback, | 36 | Stream(u32 sample_rate, Format format, ReleaseCallback&& release_callback, |
| 36 | SinkStream& sink_stream); | 37 | SinkStream& sink_stream, std::string&& name_); |
| 37 | 38 | ||
| 38 | /// Plays the audio stream | 39 | /// Plays the audio stream |
| 39 | void Play(); | 40 | void Play(); |
| @@ -68,9 +69,6 @@ public: | |||
| 68 | /// Gets the number of channels | 69 | /// Gets the number of channels |
| 69 | u32 GetNumChannels() const; | 70 | u32 GetNumChannels() const; |
| 70 | 71 | ||
| 71 | /// Gets the sample size in bytes | ||
| 72 | u32 GetSampleSize() const; | ||
| 73 | |||
| 74 | private: | 72 | private: |
| 75 | /// Current state of the stream | 73 | /// Current state of the stream |
| 76 | enum class State { | 74 | enum class State { |
| @@ -96,6 +94,7 @@ private: | |||
| 96 | std::queue<BufferPtr> queued_buffers; ///< Buffers queued to be played in the stream | 94 | std::queue<BufferPtr> queued_buffers; ///< Buffers queued to be played in the stream |
| 97 | std::queue<BufferPtr> released_buffers; ///< Buffers recently released from the stream | 95 | std::queue<BufferPtr> released_buffers; ///< Buffers recently released from the stream |
| 98 | SinkStream& sink_stream; ///< Output sink for the stream | 96 | SinkStream& sink_stream; ///< Output sink for the stream |
| 97 | std::string name; ///< Name of the stream, must be unique | ||
| 99 | }; | 98 | }; |
| 100 | 99 | ||
| 101 | using StreamPtr = std::shared_ptr<Stream>; | 100 | using StreamPtr = std::shared_ptr<Stream>; |
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 75f6b8235..884e64e99 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp | |||
| @@ -41,40 +41,42 @@ | |||
| 41 | #include "core/loader/loader.h" | 41 | #include "core/loader/loader.h" |
| 42 | #include "core/memory.h" | 42 | #include "core/memory.h" |
| 43 | 43 | ||
| 44 | const int GDB_BUFFER_SIZE = 10000; | 44 | namespace GDBStub { |
| 45 | namespace { | ||
| 46 | constexpr int GDB_BUFFER_SIZE = 10000; | ||
| 45 | 47 | ||
| 46 | const char GDB_STUB_START = '$'; | 48 | constexpr char GDB_STUB_START = '$'; |
| 47 | const char GDB_STUB_END = '#'; | 49 | constexpr char GDB_STUB_END = '#'; |
| 48 | const char GDB_STUB_ACK = '+'; | 50 | constexpr char GDB_STUB_ACK = '+'; |
| 49 | const char GDB_STUB_NACK = '-'; | 51 | constexpr char GDB_STUB_NACK = '-'; |
| 50 | 52 | ||
| 51 | #ifndef SIGTRAP | 53 | #ifndef SIGTRAP |
| 52 | const u32 SIGTRAP = 5; | 54 | constexpr u32 SIGTRAP = 5; |
| 53 | #endif | 55 | #endif |
| 54 | 56 | ||
| 55 | #ifndef SIGTERM | 57 | #ifndef SIGTERM |
| 56 | const u32 SIGTERM = 15; | 58 | constexpr u32 SIGTERM = 15; |
| 57 | #endif | 59 | #endif |
| 58 | 60 | ||
| 59 | #ifndef MSG_WAITALL | 61 | #ifndef MSG_WAITALL |
| 60 | const u32 MSG_WAITALL = 8; | 62 | constexpr u32 MSG_WAITALL = 8; |
| 61 | #endif | 63 | #endif |
| 62 | 64 | ||
| 63 | const u32 LR_REGISTER = 30; | 65 | constexpr u32 LR_REGISTER = 30; |
| 64 | const u32 SP_REGISTER = 31; | 66 | constexpr u32 SP_REGISTER = 31; |
| 65 | const u32 PC_REGISTER = 32; | 67 | constexpr u32 PC_REGISTER = 32; |
| 66 | const u32 CPSR_REGISTER = 33; | 68 | constexpr u32 CPSR_REGISTER = 33; |
| 67 | const u32 UC_ARM64_REG_Q0 = 34; | 69 | constexpr u32 UC_ARM64_REG_Q0 = 34; |
| 68 | const u32 FPSCR_REGISTER = 66; | 70 | constexpr u32 FPSCR_REGISTER = 66; |
| 69 | 71 | ||
| 70 | // TODO/WiP - Used while working on support for FPU | 72 | // TODO/WiP - Used while working on support for FPU |
| 71 | const u32 TODO_DUMMY_REG_997 = 997; | 73 | constexpr u32 TODO_DUMMY_REG_997 = 997; |
| 72 | const u32 TODO_DUMMY_REG_998 = 998; | 74 | constexpr u32 TODO_DUMMY_REG_998 = 998; |
| 73 | 75 | ||
| 74 | // For sample XML files see the GDB source /gdb/features | 76 | // For sample XML files see the GDB source /gdb/features |
| 75 | // GDB also wants the l character at the start | 77 | // GDB also wants the l character at the start |
| 76 | // This XML defines what the registers are for this specific ARM device | 78 | // This XML defines what the registers are for this specific ARM device |
| 77 | static const char* target_xml = | 79 | constexpr char target_xml[] = |
| 78 | R"(l<?xml version="1.0"?> | 80 | R"(l<?xml version="1.0"?> |
| 79 | <!DOCTYPE target SYSTEM "gdb-target.dtd"> | 81 | <!DOCTYPE target SYSTEM "gdb-target.dtd"> |
| 80 | <target version="1.0"> | 82 | <target version="1.0"> |
| @@ -140,30 +142,28 @@ static const char* target_xml = | |||
| 140 | </target> | 142 | </target> |
| 141 | )"; | 143 | )"; |
| 142 | 144 | ||
| 143 | namespace GDBStub { | 145 | int gdbserver_socket = -1; |
| 144 | |||
| 145 | static int gdbserver_socket = -1; | ||
| 146 | 146 | ||
| 147 | static u8 command_buffer[GDB_BUFFER_SIZE]; | 147 | u8 command_buffer[GDB_BUFFER_SIZE]; |
| 148 | static u32 command_length; | 148 | u32 command_length; |
| 149 | 149 | ||
| 150 | static u32 latest_signal = 0; | 150 | u32 latest_signal = 0; |
| 151 | static bool memory_break = false; | 151 | bool memory_break = false; |
| 152 | 152 | ||
| 153 | static Kernel::Thread* current_thread = nullptr; | 153 | Kernel::Thread* current_thread = nullptr; |
| 154 | static u32 current_core = 0; | 154 | u32 current_core = 0; |
| 155 | 155 | ||
| 156 | // Binding to a port within the reserved ports range (0-1023) requires root permissions, | 156 | // Binding to a port within the reserved ports range (0-1023) requires root permissions, |
| 157 | // so default to a port outside of that range. | 157 | // so default to a port outside of that range. |
| 158 | static u16 gdbstub_port = 24689; | 158 | u16 gdbstub_port = 24689; |
| 159 | 159 | ||
| 160 | static bool halt_loop = true; | 160 | bool halt_loop = true; |
| 161 | static bool step_loop = false; | 161 | bool step_loop = false; |
| 162 | static bool send_trap = false; | 162 | bool send_trap = false; |
| 163 | 163 | ||
| 164 | // If set to false, the server will never be started and no | 164 | // If set to false, the server will never be started and no |
| 165 | // gdbstub-related functions will be executed. | 165 | // gdbstub-related functions will be executed. |
| 166 | static std::atomic<bool> server_enabled(false); | 166 | std::atomic<bool> server_enabled(false); |
| 167 | 167 | ||
| 168 | #ifdef _WIN32 | 168 | #ifdef _WIN32 |
| 169 | WSADATA InitData; | 169 | WSADATA InitData; |
| @@ -171,23 +171,25 @@ WSADATA InitData; | |||
| 171 | 171 | ||
| 172 | struct Breakpoint { | 172 | struct Breakpoint { |
| 173 | bool active; | 173 | bool active; |
| 174 | PAddr addr; | 174 | VAddr addr; |
| 175 | u64 len; | 175 | u64 len; |
| 176 | }; | 176 | }; |
| 177 | 177 | ||
| 178 | static std::map<u64, Breakpoint> breakpoints_execute; | 178 | using BreakpointMap = std::map<VAddr, Breakpoint>; |
| 179 | static std::map<u64, Breakpoint> breakpoints_read; | 179 | BreakpointMap breakpoints_execute; |
| 180 | static std::map<u64, Breakpoint> breakpoints_write; | 180 | BreakpointMap breakpoints_read; |
| 181 | BreakpointMap breakpoints_write; | ||
| 181 | 182 | ||
| 182 | struct Module { | 183 | struct Module { |
| 183 | std::string name; | 184 | std::string name; |
| 184 | PAddr beg; | 185 | VAddr beg; |
| 185 | PAddr end; | 186 | VAddr end; |
| 186 | }; | 187 | }; |
| 187 | 188 | ||
| 188 | static std::vector<Module> modules; | 189 | std::vector<Module> modules; |
| 190 | } // Anonymous namespace | ||
| 189 | 191 | ||
| 190 | void RegisterModule(std::string name, PAddr beg, PAddr end, bool add_elf_ext) { | 192 | void RegisterModule(std::string name, VAddr beg, VAddr end, bool add_elf_ext) { |
| 191 | Module module; | 193 | Module module; |
| 192 | if (add_elf_ext) { | 194 | if (add_elf_ext) { |
| 193 | Common::SplitPath(name, nullptr, &module.name, nullptr); | 195 | Common::SplitPath(name, nullptr, &module.name, nullptr); |
| @@ -418,11 +420,11 @@ static u8 CalculateChecksum(const u8* buffer, size_t length) { | |||
| 418 | } | 420 | } |
| 419 | 421 | ||
| 420 | /** | 422 | /** |
| 421 | * Get the list of breakpoints for a given breakpoint type. | 423 | * Get the map of breakpoints for a given breakpoint type. |
| 422 | * | 424 | * |
| 423 | * @param type Type of breakpoint list. | 425 | * @param type Type of breakpoint map. |
| 424 | */ | 426 | */ |
| 425 | static std::map<u64, Breakpoint>& GetBreakpointList(BreakpointType type) { | 427 | static BreakpointMap& GetBreakpointMap(BreakpointType type) { |
| 426 | switch (type) { | 428 | switch (type) { |
| 427 | case BreakpointType::Execute: | 429 | case BreakpointType::Execute: |
| 428 | return breakpoints_execute; | 430 | return breakpoints_execute; |
| @@ -441,20 +443,22 @@ static std::map<u64, Breakpoint>& GetBreakpointList(BreakpointType type) { | |||
| 441 | * @param type Type of breakpoint. | 443 | * @param type Type of breakpoint. |
| 442 | * @param addr Address of breakpoint. | 444 | * @param addr Address of breakpoint. |
| 443 | */ | 445 | */ |
| 444 | static void RemoveBreakpoint(BreakpointType type, PAddr addr) { | 446 | static void RemoveBreakpoint(BreakpointType type, VAddr addr) { |
| 445 | std::map<u64, Breakpoint>& p = GetBreakpointList(type); | 447 | BreakpointMap& p = GetBreakpointMap(type); |
| 446 | 448 | ||
| 447 | auto bp = p.find(static_cast<u64>(addr)); | 449 | const auto bp = p.find(addr); |
| 448 | if (bp != p.end()) { | 450 | if (bp == p.end()) { |
| 449 | LOG_DEBUG(Debug_GDBStub, "gdb: removed a breakpoint: {:016X} bytes at {:016X} of type {}", | 451 | return; |
| 450 | bp->second.len, bp->second.addr, static_cast<int>(type)); | ||
| 451 | p.erase(static_cast<u64>(addr)); | ||
| 452 | } | 452 | } |
| 453 | |||
| 454 | LOG_DEBUG(Debug_GDBStub, "gdb: removed a breakpoint: {:016X} bytes at {:016X} of type {}", | ||
| 455 | bp->second.len, bp->second.addr, static_cast<int>(type)); | ||
| 456 | p.erase(addr); | ||
| 453 | } | 457 | } |
| 454 | 458 | ||
| 455 | BreakpointAddress GetNextBreakpointFromAddress(PAddr addr, BreakpointType type) { | 459 | BreakpointAddress GetNextBreakpointFromAddress(VAddr addr, BreakpointType type) { |
| 456 | std::map<u64, Breakpoint>& p = GetBreakpointList(type); | 460 | const BreakpointMap& p = GetBreakpointMap(type); |
| 457 | auto next_breakpoint = p.lower_bound(static_cast<u64>(addr)); | 461 | const auto next_breakpoint = p.lower_bound(addr); |
| 458 | BreakpointAddress breakpoint; | 462 | BreakpointAddress breakpoint; |
| 459 | 463 | ||
| 460 | if (next_breakpoint != p.end()) { | 464 | if (next_breakpoint != p.end()) { |
| @@ -468,36 +472,38 @@ BreakpointAddress GetNextBreakpointFromAddress(PAddr addr, BreakpointType type) | |||
| 468 | return breakpoint; | 472 | return breakpoint; |
| 469 | } | 473 | } |
| 470 | 474 | ||
| 471 | bool CheckBreakpoint(PAddr addr, BreakpointType type) { | 475 | bool CheckBreakpoint(VAddr addr, BreakpointType type) { |
| 472 | if (!IsConnected()) { | 476 | if (!IsConnected()) { |
| 473 | return false; | 477 | return false; |
| 474 | } | 478 | } |
| 475 | 479 | ||
| 476 | std::map<u64, Breakpoint>& p = GetBreakpointList(type); | 480 | const BreakpointMap& p = GetBreakpointMap(type); |
| 481 | const auto bp = p.find(addr); | ||
| 477 | 482 | ||
| 478 | auto bp = p.find(static_cast<u64>(addr)); | 483 | if (bp == p.end()) { |
| 479 | if (bp != p.end()) { | 484 | return false; |
| 480 | u64 len = bp->second.len; | 485 | } |
| 481 | 486 | ||
| 482 | // IDA Pro defaults to 4-byte breakpoints for all non-hardware breakpoints | 487 | u64 len = bp->second.len; |
| 483 | // no matter if it's a 4-byte or 2-byte instruction. When you execute a | ||
| 484 | // Thumb instruction with a 4-byte breakpoint set, it will set a breakpoint on | ||
| 485 | // two instructions instead of the single instruction you placed the breakpoint | ||
| 486 | // on. So, as a way to make sure that execution breakpoints are only breaking | ||
| 487 | // on the instruction that was specified, set the length of an execution | ||
| 488 | // breakpoint to 1. This should be fine since the CPU should never begin executing | ||
| 489 | // an instruction anywhere except the beginning of the instruction. | ||
| 490 | if (type == BreakpointType::Execute) { | ||
| 491 | len = 1; | ||
| 492 | } | ||
| 493 | 488 | ||
| 494 | if (bp->second.active && (addr >= bp->second.addr && addr < bp->second.addr + len)) { | 489 | // IDA Pro defaults to 4-byte breakpoints for all non-hardware breakpoints |
| 495 | LOG_DEBUG(Debug_GDBStub, | 490 | // no matter if it's a 4-byte or 2-byte instruction. When you execute a |
| 496 | "Found breakpoint type {} @ {:016X}, range: {:016X}" | 491 | // Thumb instruction with a 4-byte breakpoint set, it will set a breakpoint on |
| 497 | " - {:016X} ({:X} bytes)", | 492 | // two instructions instead of the single instruction you placed the breakpoint |
| 498 | static_cast<int>(type), addr, bp->second.addr, bp->second.addr + len, len); | 493 | // on. So, as a way to make sure that execution breakpoints are only breaking |
| 499 | return true; | 494 | // on the instruction that was specified, set the length of an execution |
| 500 | } | 495 | // breakpoint to 1. This should be fine since the CPU should never begin executing |
| 496 | // an instruction anywhere except the beginning of the instruction. | ||
| 497 | if (type == BreakpointType::Execute) { | ||
| 498 | len = 1; | ||
| 499 | } | ||
| 500 | |||
| 501 | if (bp->second.active && (addr >= bp->second.addr && addr < bp->second.addr + len)) { | ||
| 502 | LOG_DEBUG(Debug_GDBStub, | ||
| 503 | "Found breakpoint type {} @ {:016X}, range: {:016X}" | ||
| 504 | " - {:016X} ({:X} bytes)", | ||
| 505 | static_cast<int>(type), addr, bp->second.addr, bp->second.addr + len, len); | ||
| 506 | return true; | ||
| 501 | } | 507 | } |
| 502 | 508 | ||
| 503 | return false; | 509 | return false; |
| @@ -975,8 +981,8 @@ static void Continue() { | |||
| 975 | * @param addr Address of breakpoint. | 981 | * @param addr Address of breakpoint. |
| 976 | * @param len Length of breakpoint. | 982 | * @param len Length of breakpoint. |
| 977 | */ | 983 | */ |
| 978 | static bool CommitBreakpoint(BreakpointType type, PAddr addr, u64 len) { | 984 | static bool CommitBreakpoint(BreakpointType type, VAddr addr, u64 len) { |
| 979 | std::map<u64, Breakpoint>& p = GetBreakpointList(type); | 985 | BreakpointMap& p = GetBreakpointMap(type); |
| 980 | 986 | ||
| 981 | Breakpoint breakpoint; | 987 | Breakpoint breakpoint; |
| 982 | breakpoint.active = true; | 988 | breakpoint.active = true; |
| @@ -1015,7 +1021,7 @@ static void AddBreakpoint() { | |||
| 1015 | 1021 | ||
| 1016 | auto start_offset = command_buffer + 3; | 1022 | auto start_offset = command_buffer + 3; |
| 1017 | auto addr_pos = std::find(start_offset, command_buffer + command_length, ','); | 1023 | auto addr_pos = std::find(start_offset, command_buffer + command_length, ','); |
| 1018 | PAddr addr = HexToLong(start_offset, static_cast<u64>(addr_pos - start_offset)); | 1024 | VAddr addr = HexToLong(start_offset, static_cast<u64>(addr_pos - start_offset)); |
| 1019 | 1025 | ||
| 1020 | start_offset = addr_pos + 1; | 1026 | start_offset = addr_pos + 1; |
| 1021 | u64 len = | 1027 | u64 len = |
| @@ -1064,7 +1070,7 @@ static void RemoveBreakpoint() { | |||
| 1064 | 1070 | ||
| 1065 | auto start_offset = command_buffer + 3; | 1071 | auto start_offset = command_buffer + 3; |
| 1066 | auto addr_pos = std::find(start_offset, command_buffer + command_length, ','); | 1072 | auto addr_pos = std::find(start_offset, command_buffer + command_length, ','); |
| 1067 | PAddr addr = HexToLong(start_offset, static_cast<u64>(addr_pos - start_offset)); | 1073 | VAddr addr = HexToLong(start_offset, static_cast<u64>(addr_pos - start_offset)); |
| 1068 | 1074 | ||
| 1069 | if (type == BreakpointType::Access) { | 1075 | if (type == BreakpointType::Access) { |
| 1070 | // Access is made up of Read and Write types, so add both breakpoints | 1076 | // Access is made up of Read and Write types, so add both breakpoints |
diff --git a/src/core/gdbstub/gdbstub.h b/src/core/gdbstub/gdbstub.h index a6b50c26c..5a36524b2 100644 --- a/src/core/gdbstub/gdbstub.h +++ b/src/core/gdbstub/gdbstub.h | |||
| @@ -22,7 +22,7 @@ enum class BreakpointType { | |||
| 22 | }; | 22 | }; |
| 23 | 23 | ||
| 24 | struct BreakpointAddress { | 24 | struct BreakpointAddress { |
| 25 | PAddr address; | 25 | VAddr address; |
| 26 | BreakpointType type; | 26 | BreakpointType type; |
| 27 | }; | 27 | }; |
| 28 | 28 | ||
| @@ -53,7 +53,7 @@ bool IsServerEnabled(); | |||
| 53 | bool IsConnected(); | 53 | bool IsConnected(); |
| 54 | 54 | ||
| 55 | /// Register module. | 55 | /// Register module. |
| 56 | void RegisterModule(std::string name, PAddr beg, PAddr end, bool add_elf_ext = true); | 56 | void RegisterModule(std::string name, VAddr beg, VAddr end, bool add_elf_ext = true); |
| 57 | 57 | ||
| 58 | /** | 58 | /** |
| 59 | * Signal to the gdbstub server that it should halt CPU execution. | 59 | * Signal to the gdbstub server that it should halt CPU execution. |
| @@ -74,7 +74,7 @@ void HandlePacket(); | |||
| 74 | * @param addr Address to search from. | 74 | * @param addr Address to search from. |
| 75 | * @param type Type of breakpoint. | 75 | * @param type Type of breakpoint. |
| 76 | */ | 76 | */ |
| 77 | BreakpointAddress GetNextBreakpointFromAddress(PAddr addr, GDBStub::BreakpointType type); | 77 | BreakpointAddress GetNextBreakpointFromAddress(VAddr addr, GDBStub::BreakpointType type); |
| 78 | 78 | ||
| 79 | /** | 79 | /** |
| 80 | * Check if a breakpoint of the specified type exists at the given address. | 80 | * Check if a breakpoint of the specified type exists at the given address. |
| @@ -82,7 +82,7 @@ BreakpointAddress GetNextBreakpointFromAddress(PAddr addr, GDBStub::BreakpointTy | |||
| 82 | * @param addr Address of breakpoint. | 82 | * @param addr Address of breakpoint. |
| 83 | * @param type Type of breakpoint. | 83 | * @param type Type of breakpoint. |
| 84 | */ | 84 | */ |
| 85 | bool CheckBreakpoint(PAddr addr, GDBStub::BreakpointType type); | 85 | bool CheckBreakpoint(VAddr addr, GDBStub::BreakpointType type); |
| 86 | 86 | ||
| 87 | /// If set to true, the CPU will halt at the beginning of the next CPU loop. | 87 | /// If set to true, the CPU will halt at the beginning of the next CPU loop. |
| 88 | bool GetCpuHaltFlag(); | 88 | bool GetCpuHaltFlag(); |
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp index 7a17ed162..03a954a9f 100644 --- a/src/core/hle/kernel/address_arbiter.cpp +++ b/src/core/hle/kernel/address_arbiter.cpp | |||
| @@ -32,9 +32,8 @@ static ResultCode WaitForAddress(VAddr address, s64 timeout) { | |||
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | // Gets the threads waiting on an address. | 34 | // Gets the threads waiting on an address. |
| 35 | static void GetThreadsWaitingOnAddress(std::vector<SharedPtr<Thread>>& waiting_threads, | 35 | static std::vector<SharedPtr<Thread>> GetThreadsWaitingOnAddress(VAddr address) { |
| 36 | VAddr address) { | 36 | const auto RetrieveWaitingThreads = |
| 37 | auto RetrieveWaitingThreads = | ||
| 38 | [](size_t core_index, std::vector<SharedPtr<Thread>>& waiting_threads, VAddr arb_addr) { | 37 | [](size_t core_index, std::vector<SharedPtr<Thread>>& waiting_threads, VAddr arb_addr) { |
| 39 | const auto& scheduler = Core::System::GetInstance().Scheduler(core_index); | 38 | const auto& scheduler = Core::System::GetInstance().Scheduler(core_index); |
| 40 | auto& thread_list = scheduler->GetThreadList(); | 39 | auto& thread_list = scheduler->GetThreadList(); |
| @@ -45,16 +44,20 @@ static void GetThreadsWaitingOnAddress(std::vector<SharedPtr<Thread>>& waiting_t | |||
| 45 | } | 44 | } |
| 46 | }; | 45 | }; |
| 47 | 46 | ||
| 48 | // Retrieve a list of all threads that are waiting for this address. | 47 | // Retrieve all threads that are waiting for this address. |
| 49 | RetrieveWaitingThreads(0, waiting_threads, address); | 48 | std::vector<SharedPtr<Thread>> threads; |
| 50 | RetrieveWaitingThreads(1, waiting_threads, address); | 49 | RetrieveWaitingThreads(0, threads, address); |
| 51 | RetrieveWaitingThreads(2, waiting_threads, address); | 50 | RetrieveWaitingThreads(1, threads, address); |
| 52 | RetrieveWaitingThreads(3, waiting_threads, address); | 51 | RetrieveWaitingThreads(2, threads, address); |
| 52 | RetrieveWaitingThreads(3, threads, address); | ||
| 53 | |||
| 53 | // Sort them by priority, such that the highest priority ones come first. | 54 | // Sort them by priority, such that the highest priority ones come first. |
| 54 | std::sort(waiting_threads.begin(), waiting_threads.end(), | 55 | std::sort(threads.begin(), threads.end(), |
| 55 | [](const SharedPtr<Thread>& lhs, const SharedPtr<Thread>& rhs) { | 56 | [](const SharedPtr<Thread>& lhs, const SharedPtr<Thread>& rhs) { |
| 56 | return lhs->current_priority < rhs->current_priority; | 57 | return lhs->current_priority < rhs->current_priority; |
| 57 | }); | 58 | }); |
| 59 | |||
| 60 | return threads; | ||
| 58 | } | 61 | } |
| 59 | 62 | ||
| 60 | // Wake up num_to_wake (or all) threads in a vector. | 63 | // Wake up num_to_wake (or all) threads in a vector. |
| @@ -76,9 +79,7 @@ static void WakeThreads(std::vector<SharedPtr<Thread>>& waiting_threads, s32 num | |||
| 76 | 79 | ||
| 77 | // Signals an address being waited on. | 80 | // Signals an address being waited on. |
| 78 | ResultCode SignalToAddress(VAddr address, s32 num_to_wake) { | 81 | ResultCode SignalToAddress(VAddr address, s32 num_to_wake) { |
| 79 | // Get threads waiting on the address. | 82 | std::vector<SharedPtr<Thread>> waiting_threads = GetThreadsWaitingOnAddress(address); |
| 80 | std::vector<SharedPtr<Thread>> waiting_threads; | ||
| 81 | GetThreadsWaitingOnAddress(waiting_threads, address); | ||
| 82 | 83 | ||
| 83 | WakeThreads(waiting_threads, num_to_wake); | 84 | WakeThreads(waiting_threads, num_to_wake); |
| 84 | return RESULT_SUCCESS; | 85 | return RESULT_SUCCESS; |
| @@ -110,12 +111,11 @@ ResultCode ModifyByWaitingCountAndSignalToAddressIfEqual(VAddr address, s32 valu | |||
| 110 | } | 111 | } |
| 111 | 112 | ||
| 112 | // Get threads waiting on the address. | 113 | // Get threads waiting on the address. |
| 113 | std::vector<SharedPtr<Thread>> waiting_threads; | 114 | std::vector<SharedPtr<Thread>> waiting_threads = GetThreadsWaitingOnAddress(address); |
| 114 | GetThreadsWaitingOnAddress(waiting_threads, address); | ||
| 115 | 115 | ||
| 116 | // Determine the modified value depending on the waiting count. | 116 | // Determine the modified value depending on the waiting count. |
| 117 | s32 updated_value; | 117 | s32 updated_value; |
| 118 | if (waiting_threads.size() == 0) { | 118 | if (waiting_threads.empty()) { |
| 119 | updated_value = value - 1; | 119 | updated_value = value - 1; |
| 120 | } else if (num_to_wake <= 0 || waiting_threads.size() <= static_cast<u32>(num_to_wake)) { | 120 | } else if (num_to_wake <= 0 || waiting_threads.size() <= static_cast<u32>(num_to_wake)) { |
| 121 | updated_value = value + 1; | 121 | updated_value = value + 1; |
diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp index b317027b6..108a7c6eb 100644 --- a/src/core/hle/service/audio/audout_u.cpp +++ b/src/core/hle/service/audio/audout_u.cpp | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #include <array> | 5 | #include <array> |
| 6 | #include <vector> | 6 | #include <vector> |
| 7 | |||
| 8 | #include "audio_core/codec.h" | ||
| 7 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 8 | #include "core/core.h" | 10 | #include "core/core.h" |
| 9 | #include "core/hle/ipc_helpers.h" | 11 | #include "core/hle/ipc_helpers.h" |
| @@ -48,7 +50,7 @@ public: | |||
| 48 | buffer_event = Kernel::Event::Create(Kernel::ResetType::Sticky, "IAudioOutBufferReleased"); | 50 | buffer_event = Kernel::Event::Create(Kernel::ResetType::Sticky, "IAudioOutBufferReleased"); |
| 49 | 51 | ||
| 50 | stream = audio_core.OpenStream(audio_params.sample_rate, audio_params.channel_count, | 52 | stream = audio_core.OpenStream(audio_params.sample_rate, audio_params.channel_count, |
| 51 | [=]() { buffer_event->Signal(); }); | 53 | "IAudioOut", [=]() { buffer_event->Signal(); }); |
| 52 | } | 54 | } |
| 53 | 55 | ||
| 54 | private: | 56 | private: |
| @@ -111,10 +113,10 @@ private: | |||
| 111 | std::memcpy(&audio_buffer, input_buffer.data(), sizeof(AudioBuffer)); | 113 | std::memcpy(&audio_buffer, input_buffer.data(), sizeof(AudioBuffer)); |
| 112 | const u64 tag{rp.Pop<u64>()}; | 114 | const u64 tag{rp.Pop<u64>()}; |
| 113 | 115 | ||
| 114 | std::vector<u8> data(audio_buffer.buffer_size); | 116 | std::vector<s16> samples(audio_buffer.buffer_size / sizeof(s16)); |
| 115 | Memory::ReadBlock(audio_buffer.buffer, data.data(), data.size()); | 117 | Memory::ReadBlock(audio_buffer.buffer, samples.data(), audio_buffer.buffer_size); |
| 116 | 118 | ||
| 117 | if (!audio_core.QueueBuffer(stream, tag, std::move(data))) { | 119 | if (!audio_core.QueueBuffer(stream, tag, std::move(samples))) { |
| 118 | IPC::ResponseBuilder rb{ctx, 2}; | 120 | IPC::ResponseBuilder rb{ctx, 2}; |
| 119 | rb.Push(ResultCode(ErrorModule::Audio, ErrCodes::BufferCountExceeded)); | 121 | rb.Push(ResultCode(ErrorModule::Audio, ErrCodes::BufferCountExceeded)); |
| 120 | } | 122 | } |
| @@ -200,7 +202,7 @@ void AudOutU::OpenAudioOutImpl(Kernel::HLERequestContext& ctx) { | |||
| 200 | rb.Push(RESULT_SUCCESS); | 202 | rb.Push(RESULT_SUCCESS); |
| 201 | rb.Push<u32>(DefaultSampleRate); | 203 | rb.Push<u32>(DefaultSampleRate); |
| 202 | rb.Push<u32>(params.channel_count); | 204 | rb.Push<u32>(params.channel_count); |
| 203 | rb.Push<u32>(static_cast<u32>(PcmFormat::Int16)); | 205 | rb.Push<u32>(static_cast<u32>(AudioCore::Codec::PcmFormat::Int16)); |
| 204 | rb.Push<u32>(static_cast<u32>(AudioState::Stopped)); | 206 | rb.Push<u32>(static_cast<u32>(AudioState::Stopped)); |
| 205 | rb.PushIpcInterface<Audio::IAudioOut>(audio_out_interface); | 207 | rb.PushIpcInterface<Audio::IAudioOut>(audio_out_interface); |
| 206 | } | 208 | } |
diff --git a/src/core/hle/service/audio/audout_u.h b/src/core/hle/service/audio/audout_u.h index e5c2184d5..fd491f65d 100644 --- a/src/core/hle/service/audio/audout_u.h +++ b/src/core/hle/service/audio/audout_u.h | |||
| @@ -38,16 +38,6 @@ private: | |||
| 38 | 38 | ||
| 39 | void ListAudioOutsImpl(Kernel::HLERequestContext& ctx); | 39 | void ListAudioOutsImpl(Kernel::HLERequestContext& ctx); |
| 40 | void OpenAudioOutImpl(Kernel::HLERequestContext& ctx); | 40 | void OpenAudioOutImpl(Kernel::HLERequestContext& ctx); |
| 41 | |||
| 42 | enum class PcmFormat : u32 { | ||
| 43 | Invalid = 0, | ||
| 44 | Int8 = 1, | ||
| 45 | Int16 = 2, | ||
| 46 | Int24 = 3, | ||
| 47 | Int32 = 4, | ||
| 48 | PcmFloat = 5, | ||
| 49 | Adpcm = 6, | ||
| 50 | }; | ||
| 51 | }; | 41 | }; |
| 52 | 42 | ||
| 53 | } // namespace Service::Audio | 43 | } // namespace Service::Audio |
diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index 6aed9e2fa..f99304de5 100644 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp | |||
| @@ -15,13 +15,10 @@ | |||
| 15 | 15 | ||
| 16 | namespace Service::Audio { | 16 | namespace Service::Audio { |
| 17 | 17 | ||
| 18 | /// TODO(bunnei): Find a proper value for the audio_ticks | ||
| 19 | constexpr u64 audio_ticks{static_cast<u64>(CoreTiming::BASE_CLOCK_RATE / 200)}; | ||
| 20 | |||
| 21 | class IAudioRenderer final : public ServiceFramework<IAudioRenderer> { | 18 | class IAudioRenderer final : public ServiceFramework<IAudioRenderer> { |
| 22 | public: | 19 | public: |
| 23 | explicit IAudioRenderer(AudioRendererParameter audren_params) | 20 | explicit IAudioRenderer(AudioCore::AudioRendererParameter audren_params) |
| 24 | : ServiceFramework("IAudioRenderer"), worker_params(audren_params) { | 21 | : ServiceFramework("IAudioRenderer") { |
| 25 | static const FunctionInfo functions[] = { | 22 | static const FunctionInfo functions[] = { |
| 26 | {0, nullptr, "GetAudioRendererSampleRate"}, | 23 | {0, nullptr, "GetAudioRendererSampleRate"}, |
| 27 | {1, nullptr, "GetAudioRendererSampleCount"}, | 24 | {1, nullptr, "GetAudioRendererSampleCount"}, |
| @@ -39,21 +36,8 @@ public: | |||
| 39 | RegisterHandlers(functions); | 36 | RegisterHandlers(functions); |
| 40 | 37 | ||
| 41 | system_event = | 38 | system_event = |
| 42 | Kernel::Event::Create(Kernel::ResetType::OneShot, "IAudioRenderer:SystemEvent"); | 39 | Kernel::Event::Create(Kernel::ResetType::Sticky, "IAudioRenderer:SystemEvent"); |
| 43 | 40 | renderer = std::make_unique<AudioCore::AudioRenderer>(audren_params, system_event); | |
| 44 | // Register event callback to update the Audio Buffer | ||
| 45 | audio_event = CoreTiming::RegisterEvent( | ||
| 46 | "IAudioRenderer::UpdateAudioCallback", [this](u64 userdata, int cycles_late) { | ||
| 47 | UpdateAudioCallback(); | ||
| 48 | CoreTiming::ScheduleEvent(audio_ticks - cycles_late, audio_event); | ||
| 49 | }); | ||
| 50 | |||
| 51 | // Start the audio event | ||
| 52 | CoreTiming::ScheduleEvent(audio_ticks, audio_event); | ||
| 53 | voice_status_list.resize(worker_params.voice_count); | ||
| 54 | } | ||
| 55 | ~IAudioRenderer() { | ||
| 56 | CoreTiming::UnscheduleEvent(audio_event, 0); | ||
| 57 | } | 41 | } |
| 58 | 42 | ||
| 59 | private: | 43 | private: |
| @@ -62,60 +46,9 @@ private: | |||
| 62 | } | 46 | } |
| 63 | 47 | ||
| 64 | void RequestUpdateAudioRenderer(Kernel::HLERequestContext& ctx) { | 48 | void RequestUpdateAudioRenderer(Kernel::HLERequestContext& ctx) { |
| 65 | UpdateDataHeader config{}; | 49 | ctx.WriteBuffer(renderer->UpdateAudioRenderer(ctx.ReadBuffer())); |
| 66 | auto buf = ctx.ReadBuffer(); | ||
| 67 | std::memcpy(&config, buf.data(), sizeof(UpdateDataHeader)); | ||
| 68 | u32 memory_pool_count = worker_params.effect_count + (worker_params.voice_count * 4); | ||
| 69 | |||
| 70 | std::vector<MemoryPoolInfo> mem_pool_info(memory_pool_count); | ||
| 71 | std::memcpy(mem_pool_info.data(), | ||
| 72 | buf.data() + sizeof(UpdateDataHeader) + config.behavior_size, | ||
| 73 | memory_pool_count * sizeof(MemoryPoolInfo)); | ||
| 74 | |||
| 75 | std::vector<VoiceInfo> voice_info(worker_params.voice_count); | ||
| 76 | std::memcpy(voice_info.data(), | ||
| 77 | buf.data() + sizeof(UpdateDataHeader) + config.behavior_size + | ||
| 78 | config.memory_pools_size + config.voice_resource_size, | ||
| 79 | worker_params.voice_count * sizeof(VoiceInfo)); | ||
| 80 | |||
| 81 | UpdateDataHeader response_data{worker_params}; | ||
| 82 | |||
| 83 | ASSERT(ctx.GetWriteBufferSize() == response_data.total_size); | ||
| 84 | |||
| 85 | std::vector<u8> output(response_data.total_size); | ||
| 86 | std::memcpy(output.data(), &response_data, sizeof(UpdateDataHeader)); | ||
| 87 | std::vector<MemoryPoolEntry> memory_pool(memory_pool_count); | ||
| 88 | for (unsigned i = 0; i < memory_pool.size(); i++) { | ||
| 89 | if (mem_pool_info[i].pool_state == MemoryPoolStates::RequestAttach) | ||
| 90 | memory_pool[i].state = MemoryPoolStates::Attached; | ||
| 91 | else if (mem_pool_info[i].pool_state == MemoryPoolStates::RequestDetach) | ||
| 92 | memory_pool[i].state = MemoryPoolStates::Detached; | ||
| 93 | } | ||
| 94 | std::memcpy(output.data() + sizeof(UpdateDataHeader), memory_pool.data(), | ||
| 95 | response_data.memory_pools_size); | ||
| 96 | |||
| 97 | for (unsigned i = 0; i < voice_info.size(); i++) { | ||
| 98 | if (voice_info[i].is_new) { | ||
| 99 | voice_status_list[i].played_sample_count = 0; | ||
| 100 | voice_status_list[i].wave_buffer_consumed = 0; | ||
| 101 | } else if (voice_info[i].play_state == (u8)PlayStates::Started) { | ||
| 102 | for (u32 buff_idx = 0; buff_idx < voice_info[i].wave_buffer_count; buff_idx++) { | ||
| 103 | voice_status_list[i].played_sample_count += | ||
| 104 | (voice_info[i].wave_buffer[buff_idx].end_sample_offset - | ||
| 105 | voice_info[i].wave_buffer[buff_idx].start_sample_offset) / | ||
| 106 | 2; | ||
| 107 | voice_status_list[i].wave_buffer_consumed++; | ||
| 108 | } | ||
| 109 | } | ||
| 110 | } | ||
| 111 | std::memcpy(output.data() + sizeof(UpdateDataHeader) + response_data.memory_pools_size, | ||
| 112 | voice_status_list.data(), response_data.voices_size); | ||
| 113 | |||
| 114 | ctx.WriteBuffer(output); | ||
| 115 | |||
| 116 | IPC::ResponseBuilder rb{ctx, 2}; | 50 | IPC::ResponseBuilder rb{ctx, 2}; |
| 117 | rb.Push(RESULT_SUCCESS); | 51 | rb.Push(RESULT_SUCCESS); |
| 118 | |||
| 119 | LOG_WARNING(Service_Audio, "(STUBBED) called"); | 52 | LOG_WARNING(Service_Audio, "(STUBBED) called"); |
| 120 | } | 53 | } |
| 121 | 54 | ||
| @@ -136,8 +69,6 @@ private: | |||
| 136 | } | 69 | } |
| 137 | 70 | ||
| 138 | void QuerySystemEvent(Kernel::HLERequestContext& ctx) { | 71 | void QuerySystemEvent(Kernel::HLERequestContext& ctx) { |
| 139 | // system_event->Signal(); | ||
| 140 | |||
| 141 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 72 | IPC::ResponseBuilder rb{ctx, 2, 1}; |
| 142 | rb.Push(RESULT_SUCCESS); | 73 | rb.Push(RESULT_SUCCESS); |
| 143 | rb.PushCopyObjects(system_event); | 74 | rb.PushCopyObjects(system_event); |
| @@ -145,131 +76,8 @@ private: | |||
| 145 | LOG_WARNING(Service_Audio, "(STUBBED) called"); | 76 | LOG_WARNING(Service_Audio, "(STUBBED) called"); |
| 146 | } | 77 | } |
| 147 | 78 | ||
| 148 | enum class MemoryPoolStates : u32 { // Should be LE | ||
| 149 | Invalid = 0x0, | ||
| 150 | Unknown = 0x1, | ||
| 151 | RequestDetach = 0x2, | ||
| 152 | Detached = 0x3, | ||
| 153 | RequestAttach = 0x4, | ||
| 154 | Attached = 0x5, | ||
| 155 | Released = 0x6, | ||
| 156 | }; | ||
| 157 | |||
| 158 | enum class PlayStates : u8 { | ||
| 159 | Started = 0, | ||
| 160 | Stopped = 1, | ||
| 161 | }; | ||
| 162 | |||
| 163 | struct MemoryPoolEntry { | ||
| 164 | MemoryPoolStates state; | ||
| 165 | u32_le unknown_4; | ||
| 166 | u32_le unknown_8; | ||
| 167 | u32_le unknown_c; | ||
| 168 | }; | ||
| 169 | static_assert(sizeof(MemoryPoolEntry) == 0x10, "MemoryPoolEntry has wrong size"); | ||
| 170 | |||
| 171 | struct MemoryPoolInfo { | ||
| 172 | u64_le pool_address; | ||
| 173 | u64_le pool_size; | ||
| 174 | MemoryPoolStates pool_state; | ||
| 175 | INSERT_PADDING_WORDS(3); // Unknown | ||
| 176 | }; | ||
| 177 | static_assert(sizeof(MemoryPoolInfo) == 0x20, "MemoryPoolInfo has wrong size"); | ||
| 178 | |||
| 179 | struct UpdateDataHeader { | ||
| 180 | UpdateDataHeader() {} | ||
| 181 | |||
| 182 | explicit UpdateDataHeader(const AudioRendererParameter& config) { | ||
| 183 | revision = Common::MakeMagic('R', 'E', 'V', '4'); // 5.1.0 Revision | ||
| 184 | behavior_size = 0xb0; | ||
| 185 | memory_pools_size = (config.effect_count + (config.voice_count * 4)) * 0x10; | ||
| 186 | voices_size = config.voice_count * 0x10; | ||
| 187 | voice_resource_size = 0x0; | ||
| 188 | effects_size = config.effect_count * 0x10; | ||
| 189 | mixes_size = 0x0; | ||
| 190 | sinks_size = config.sink_count * 0x20; | ||
| 191 | performance_manager_size = 0x10; | ||
| 192 | total_size = sizeof(UpdateDataHeader) + behavior_size + memory_pools_size + | ||
| 193 | voices_size + effects_size + sinks_size + performance_manager_size; | ||
| 194 | } | ||
| 195 | |||
| 196 | u32_le revision; | ||
| 197 | u32_le behavior_size; | ||
| 198 | u32_le memory_pools_size; | ||
| 199 | u32_le voices_size; | ||
| 200 | u32_le voice_resource_size; | ||
| 201 | u32_le effects_size; | ||
| 202 | u32_le mixes_size; | ||
| 203 | u32_le sinks_size; | ||
| 204 | u32_le performance_manager_size; | ||
| 205 | INSERT_PADDING_WORDS(6); | ||
| 206 | u32_le total_size; | ||
| 207 | }; | ||
| 208 | static_assert(sizeof(UpdateDataHeader) == 0x40, "UpdateDataHeader has wrong size"); | ||
| 209 | |||
| 210 | struct BiquadFilter { | ||
| 211 | u8 enable; | ||
| 212 | INSERT_PADDING_BYTES(1); | ||
| 213 | s16_le numerator[3]; | ||
| 214 | s16_le denominator[2]; | ||
| 215 | }; | ||
| 216 | static_assert(sizeof(BiquadFilter) == 0xc, "BiquadFilter has wrong size"); | ||
| 217 | |||
| 218 | struct WaveBuffer { | ||
| 219 | u64_le buffer_addr; | ||
| 220 | u64_le buffer_sz; | ||
| 221 | s32_le start_sample_offset; | ||
| 222 | s32_le end_sample_offset; | ||
| 223 | u8 loop; | ||
| 224 | u8 end_of_stream; | ||
| 225 | u8 sent_to_server; | ||
| 226 | INSERT_PADDING_BYTES(5); | ||
| 227 | u64 context_addr; | ||
| 228 | u64 context_sz; | ||
| 229 | INSERT_PADDING_BYTES(8); | ||
| 230 | }; | ||
| 231 | static_assert(sizeof(WaveBuffer) == 0x38, "WaveBuffer has wrong size"); | ||
| 232 | |||
| 233 | struct VoiceInfo { | ||
| 234 | u32_le id; | ||
| 235 | u32_le node_id; | ||
| 236 | u8 is_new; | ||
| 237 | u8 is_in_use; | ||
| 238 | u8 play_state; | ||
| 239 | u8 sample_format; | ||
| 240 | u32_le sample_rate; | ||
| 241 | u32_le priority; | ||
| 242 | u32_le sorting_order; | ||
| 243 | u32_le channel_count; | ||
| 244 | float_le pitch; | ||
| 245 | float_le volume; | ||
| 246 | BiquadFilter biquad_filter[2]; | ||
| 247 | u32_le wave_buffer_count; | ||
| 248 | u16_le wave_buffer_head; | ||
| 249 | INSERT_PADDING_BYTES(6); | ||
| 250 | u64_le additional_params_addr; | ||
| 251 | u64_le additional_params_sz; | ||
| 252 | u32_le mix_id; | ||
| 253 | u32_le splitter_info_id; | ||
| 254 | WaveBuffer wave_buffer[4]; | ||
| 255 | u32_le voice_channel_resource_ids[6]; | ||
| 256 | INSERT_PADDING_BYTES(24); | ||
| 257 | }; | ||
| 258 | static_assert(sizeof(VoiceInfo) == 0x170, "VoiceInfo is wrong size"); | ||
| 259 | |||
| 260 | struct VoiceOutStatus { | ||
| 261 | u64_le played_sample_count; | ||
| 262 | u32_le wave_buffer_consumed; | ||
| 263 | INSERT_PADDING_WORDS(1); | ||
| 264 | }; | ||
| 265 | static_assert(sizeof(VoiceOutStatus) == 0x10, "VoiceOutStatus has wrong size"); | ||
| 266 | |||
| 267 | /// This is used to trigger the audio event callback. | ||
| 268 | CoreTiming::EventType* audio_event; | ||
| 269 | |||
| 270 | Kernel::SharedPtr<Kernel::Event> system_event; | 79 | Kernel::SharedPtr<Kernel::Event> system_event; |
| 271 | AudioRendererParameter worker_params; | 80 | std::unique_ptr<AudioCore::AudioRenderer> renderer; |
| 272 | std::vector<VoiceOutStatus> voice_status_list; | ||
| 273 | }; | 81 | }; |
| 274 | 82 | ||
| 275 | class IAudioDevice final : public ServiceFramework<IAudioDevice> { | 83 | class IAudioDevice final : public ServiceFramework<IAudioDevice> { |
| @@ -368,7 +176,7 @@ AudRenU::AudRenU() : ServiceFramework("audren:u") { | |||
| 368 | 176 | ||
| 369 | void AudRenU::OpenAudioRenderer(Kernel::HLERequestContext& ctx) { | 177 | void AudRenU::OpenAudioRenderer(Kernel::HLERequestContext& ctx) { |
| 370 | IPC::RequestParser rp{ctx}; | 178 | IPC::RequestParser rp{ctx}; |
| 371 | auto params = rp.PopRaw<AudioRendererParameter>(); | 179 | auto params = rp.PopRaw<AudioCore::AudioRendererParameter>(); |
| 372 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 180 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 373 | 181 | ||
| 374 | rb.Push(RESULT_SUCCESS); | 182 | rb.Push(RESULT_SUCCESS); |
| @@ -379,7 +187,7 @@ void AudRenU::OpenAudioRenderer(Kernel::HLERequestContext& ctx) { | |||
| 379 | 187 | ||
| 380 | void AudRenU::GetAudioRendererWorkBufferSize(Kernel::HLERequestContext& ctx) { | 188 | void AudRenU::GetAudioRendererWorkBufferSize(Kernel::HLERequestContext& ctx) { |
| 381 | IPC::RequestParser rp{ctx}; | 189 | IPC::RequestParser rp{ctx}; |
| 382 | auto params = rp.PopRaw<AudioRendererParameter>(); | 190 | auto params = rp.PopRaw<AudioCore::AudioRendererParameter>(); |
| 383 | 191 | ||
| 384 | u64 buffer_sz = Common::AlignUp(4 * params.unknown_8, 0x40); | 192 | u64 buffer_sz = Common::AlignUp(4 * params.unknown_8, 0x40); |
| 385 | buffer_sz += params.unknown_c * 1024; | 193 | buffer_sz += params.unknown_c * 1024; |
diff --git a/src/core/hle/service/audio/audren_u.h b/src/core/hle/service/audio/audren_u.h index b9b81db4f..14907f8ae 100644 --- a/src/core/hle/service/audio/audren_u.h +++ b/src/core/hle/service/audio/audren_u.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "audio_core/audio_renderer.h" | ||
| 7 | #include "core/hle/service/service.h" | 8 | #include "core/hle/service/service.h" |
| 8 | 9 | ||
| 9 | namespace Kernel { | 10 | namespace Kernel { |
| @@ -12,24 +13,6 @@ class HLERequestContext; | |||
| 12 | 13 | ||
| 13 | namespace Service::Audio { | 14 | namespace Service::Audio { |
| 14 | 15 | ||
| 15 | struct AudioRendererParameter { | ||
| 16 | u32_le sample_rate; | ||
| 17 | u32_le sample_count; | ||
| 18 | u32_le unknown_8; | ||
| 19 | u32_le unknown_c; | ||
| 20 | u32_le voice_count; | ||
| 21 | u32_le sink_count; | ||
| 22 | u32_le effect_count; | ||
| 23 | u32_le unknown_1c; | ||
| 24 | u8 unknown_20; | ||
| 25 | INSERT_PADDING_BYTES(3); | ||
| 26 | u32_le splitter_count; | ||
| 27 | u32_le unknown_2c; | ||
| 28 | INSERT_PADDING_WORDS(1); | ||
| 29 | u32_le revision; | ||
| 30 | }; | ||
| 31 | static_assert(sizeof(AudioRendererParameter) == 52, "AudioRendererParameter is an invalid size"); | ||
| 32 | |||
| 33 | class AudRenU final : public ServiceFramework<AudRenU> { | 16 | class AudRenU final : public ServiceFramework<AudRenU> { |
| 34 | public: | 17 | public: |
| 35 | explicit AudRenU(); | 18 | explicit AudRenU(); |