diff options
Diffstat (limited to 'src/audio_core/hle/pipe.cpp')
| -rw-r--r-- | src/audio_core/hle/pipe.cpp | 150 |
1 files changed, 127 insertions, 23 deletions
diff --git a/src/audio_core/hle/pipe.cpp b/src/audio_core/hle/pipe.cpp index 6542c760c..9381883b4 100644 --- a/src/audio_core/hle/pipe.cpp +++ b/src/audio_core/hle/pipe.cpp | |||
| @@ -5,50 +5,154 @@ | |||
| 5 | #include <array> | 5 | #include <array> |
| 6 | #include <vector> | 6 | #include <vector> |
| 7 | 7 | ||
| 8 | #include "audio_core/hle/dsp.h" | ||
| 8 | #include "audio_core/hle/pipe.h" | 9 | #include "audio_core/hle/pipe.h" |
| 9 | 10 | ||
| 11 | #include "common/assert.h" | ||
| 10 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 11 | #include "common/logging/log.h" | 13 | #include "common/logging/log.h" |
| 12 | 14 | ||
| 13 | namespace DSP { | 15 | namespace DSP { |
| 14 | namespace HLE { | 16 | namespace HLE { |
| 15 | 17 | ||
| 16 | static size_t pipe2position = 0; | 18 | static DspState dsp_state = DspState::Off; |
| 19 | |||
| 20 | static std::array<std::vector<u8>, static_cast<size_t>(DspPipe::DspPipe_MAX)> pipe_data; | ||
| 17 | 21 | ||
| 18 | void ResetPipes() { | 22 | void ResetPipes() { |
| 19 | pipe2position = 0; | 23 | for (auto& data : pipe_data) { |
| 24 | data.clear(); | ||
| 25 | } | ||
| 26 | dsp_state = DspState::Off; | ||
| 20 | } | 27 | } |
| 21 | 28 | ||
| 22 | std::vector<u8> PipeRead(u32 pipe_number, u32 length) { | 29 | std::vector<u8> PipeRead(DspPipe pipe_number, u32 length) { |
| 23 | if (pipe_number != 2) { | 30 | if (pipe_number >= DspPipe::DspPipe_MAX) { |
| 24 | LOG_WARNING(Audio_DSP, "pipe_number = %u (!= 2), unimplemented", pipe_number); | 31 | LOG_ERROR(Audio_DSP, "pipe_number = %u invalid", pipe_number); |
| 25 | return {}; // We currently don't handle anything other than the audio pipe. | 32 | return {}; |
| 33 | } | ||
| 34 | |||
| 35 | std::vector<u8>& data = pipe_data[static_cast<size_t>(pipe_number)]; | ||
| 36 | |||
| 37 | if (length > data.size()) { | ||
| 38 | LOG_WARNING(Audio_DSP, "pipe_number = %u is out of data, application requested read of %u but %zu remain", | ||
| 39 | pipe_number, length, data.size()); | ||
| 40 | length = data.size(); | ||
| 26 | } | 41 | } |
| 27 | 42 | ||
| 28 | // Canned DSP responses that games expect. These were taken from HW by 3dmoo team. | 43 | if (length == 0) |
| 29 | // TODO: Our implementation will actually use a slightly different response than this one. | ||
| 30 | // TODO: Use offsetof on DSP structures instead for a proper response. | ||
| 31 | static const std::array<u8, 32> canned_response {{ | ||
| 32 | 0x0F, 0x00, 0xFF, 0xBF, 0x8E, 0x9E, 0x80, 0x86, 0x8E, 0xA7, 0x30, 0x94, 0x00, 0x84, 0x40, 0x85, | ||
| 33 | 0x8E, 0x94, 0x10, 0x87, 0x10, 0x84, 0x0E, 0xA9, 0x0E, 0xAA, 0xCE, 0xAA, 0x4E, 0xAC, 0x58, 0xAC | ||
| 34 | }}; | ||
| 35 | |||
| 36 | // TODO: Move this into dsp::DSP service since it happens on the service side. | ||
| 37 | // Hardware observation: No data is returned if requested length reads beyond the end of the data in-pipe. | ||
| 38 | if (pipe2position + length > canned_response.size()) { | ||
| 39 | return {}; | 44 | return {}; |
| 45 | |||
| 46 | std::vector<u8> ret(data.begin(), data.begin() + length); | ||
| 47 | data.erase(data.begin(), data.begin() + length); | ||
| 48 | return ret; | ||
| 49 | } | ||
| 50 | |||
| 51 | size_t GetPipeReadableSize(DspPipe pipe_number) { | ||
| 52 | if (pipe_number >= DspPipe::DspPipe_MAX) { | ||
| 53 | LOG_ERROR(Audio_DSP, "pipe_number = %u invalid", pipe_number); | ||
| 54 | return 0; | ||
| 40 | } | 55 | } |
| 41 | 56 | ||
| 42 | std::vector<u8> ret; | 57 | return pipe_data[static_cast<size_t>(pipe_number)].size(); |
| 43 | for (size_t i = 0; i < length; i++, pipe2position++) { | 58 | } |
| 44 | ret.emplace_back(canned_response[pipe2position]); | 59 | |
| 60 | static void WriteU16(DspPipe pipe_number, u16 value) { | ||
| 61 | std::vector<u8>& data = pipe_data[static_cast<size_t>(pipe_number)]; | ||
| 62 | // Little endian | ||
| 63 | data.emplace_back(value & 0xFF); | ||
| 64 | data.emplace_back(value >> 8); | ||
| 65 | } | ||
| 66 | |||
| 67 | static void AudioPipeWriteStructAddresses() { | ||
| 68 | // These struct addresses are DSP dram addresses. | ||
| 69 | // See also: DSP_DSP::ConvertProcessAddressFromDspDram | ||
| 70 | static const std::array<u16, 15> struct_addresses = { | ||
| 71 | 0x8000 + offsetof(SharedMemory, frame_counter) / 2, | ||
| 72 | 0x8000 + offsetof(SharedMemory, source_configurations) / 2, | ||
| 73 | 0x8000 + offsetof(SharedMemory, source_statuses) / 2, | ||
| 74 | 0x8000 + offsetof(SharedMemory, adpcm_coefficients) / 2, | ||
| 75 | 0x8000 + offsetof(SharedMemory, dsp_configuration) / 2, | ||
| 76 | 0x8000 + offsetof(SharedMemory, dsp_status) / 2, | ||
| 77 | 0x8000 + offsetof(SharedMemory, final_samples) / 2, | ||
| 78 | 0x8000 + offsetof(SharedMemory, intermediate_mix_samples) / 2, | ||
| 79 | 0x8000 + offsetof(SharedMemory, compressor) / 2, | ||
| 80 | 0x8000 + offsetof(SharedMemory, dsp_debug) / 2, | ||
| 81 | 0x8000 + offsetof(SharedMemory, unknown10) / 2, | ||
| 82 | 0x8000 + offsetof(SharedMemory, unknown11) / 2, | ||
| 83 | 0x8000 + offsetof(SharedMemory, unknown12) / 2, | ||
| 84 | 0x8000 + offsetof(SharedMemory, unknown13) / 2, | ||
| 85 | 0x8000 + offsetof(SharedMemory, unknown14) / 2 | ||
| 86 | }; | ||
| 87 | |||
| 88 | // Begin with a u16 denoting the number of structs. | ||
| 89 | WriteU16(DspPipe::Audio, struct_addresses.size()); | ||
| 90 | // Then write the struct addresses. | ||
| 91 | for (u16 addr : struct_addresses) { | ||
| 92 | WriteU16(DspPipe::Audio, addr); | ||
| 45 | } | 93 | } |
| 94 | } | ||
| 46 | 95 | ||
| 47 | return ret; | 96 | void PipeWrite(DspPipe pipe_number, const std::vector<u8>& buffer) { |
| 97 | switch (pipe_number) { | ||
| 98 | case DspPipe::Audio: { | ||
| 99 | if (buffer.size() != 4) { | ||
| 100 | LOG_ERROR(Audio_DSP, "DspPipe::Audio: Unexpected buffer length %zu was written", buffer.size()); | ||
| 101 | return; | ||
| 102 | } | ||
| 103 | |||
| 104 | enum class StateChange { | ||
| 105 | Initalize = 0, | ||
| 106 | Shutdown = 1, | ||
| 107 | Wakeup = 2, | ||
| 108 | Sleep = 3 | ||
| 109 | }; | ||
| 110 | |||
| 111 | // The difference between Initialize and Wakeup is that Input state is maintained | ||
| 112 | // when sleeping but isn't when turning it off and on again. (TODO: Implement this.) | ||
| 113 | // Waking up from sleep garbles some of the structs in the memory region. (TODO: | ||
| 114 | // Implement this.) Applications store away the state of these structs before | ||
| 115 | // sleeping and reset it back after wakeup on behalf of the DSP. | ||
| 116 | |||
| 117 | switch (static_cast<StateChange>(buffer[0])) { | ||
| 118 | case StateChange::Initalize: | ||
| 119 | LOG_INFO(Audio_DSP, "Application has requested initialization of DSP hardware"); | ||
| 120 | ResetPipes(); | ||
| 121 | AudioPipeWriteStructAddresses(); | ||
| 122 | dsp_state = DspState::On; | ||
| 123 | break; | ||
| 124 | case StateChange::Shutdown: | ||
| 125 | LOG_INFO(Audio_DSP, "Application has requested shutdown of DSP hardware"); | ||
| 126 | dsp_state = DspState::Off; | ||
| 127 | break; | ||
| 128 | case StateChange::Wakeup: | ||
| 129 | LOG_INFO(Audio_DSP, "Application has requested wakeup of DSP hardware"); | ||
| 130 | ResetPipes(); | ||
| 131 | AudioPipeWriteStructAddresses(); | ||
| 132 | dsp_state = DspState::On; | ||
| 133 | break; | ||
| 134 | case StateChange::Sleep: | ||
| 135 | LOG_INFO(Audio_DSP, "Application has requested sleep of DSP hardware"); | ||
| 136 | UNIMPLEMENTED(); | ||
| 137 | dsp_state = DspState::Sleeping; | ||
| 138 | break; | ||
| 139 | default: | ||
| 140 | LOG_ERROR(Audio_DSP, "Application has requested unknown state transition of DSP hardware %hhu", buffer[0]); | ||
| 141 | dsp_state = DspState::Off; | ||
| 142 | break; | ||
| 143 | } | ||
| 144 | |||
| 145 | return; | ||
| 146 | } | ||
| 147 | default: | ||
| 148 | LOG_CRITICAL(Audio_DSP, "pipe_number = %u unimplemented", pipe_number); | ||
| 149 | UNIMPLEMENTED(); | ||
| 150 | return; | ||
| 151 | } | ||
| 48 | } | 152 | } |
| 49 | 153 | ||
| 50 | void PipeWrite(u32 pipe_number, const std::vector<u8>& buffer) { | 154 | DspState GetDspState() { |
| 51 | // TODO: proper pipe behaviour | 155 | return dsp_state; |
| 52 | } | 156 | } |
| 53 | 157 | ||
| 54 | } // namespace HLE | 158 | } // namespace HLE |