HLE DSP: Stub AAC

This commit is contained in:
wheremyfoodat 2024-05-01 01:56:17 +03:00
parent fb8130a868
commit 0490c6753f
4 changed files with 119 additions and 3 deletions

View file

@ -241,7 +241,7 @@ set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/termcolor.hpp
include/PICA/dynapica/shader_rec_emitter_arm64.hpp include/scheduler.hpp include/applets/error_applet.hpp
include/audio/dsp_core.hpp include/audio/null_core.hpp include/audio/teakra_core.hpp
include/audio/miniaudio_device.hpp include/ring_buffer.hpp include/bitfield.hpp include/audio/dsp_shared_mem.hpp
include/audio/hle_core.hpp include/capstone.hpp
include/audio/hle_core.hpp include/capstone.hpp include/audio/aac.hpp
)
cmrc_add_resource_library(

71
include/audio/aac.hpp Normal file
View file

@ -0,0 +1,71 @@
#pragma once
#include <array>
#include <type_traits>
#include "helpers.hpp"
#include "swap.hpp"
namespace Audio::AAC {
namespace ResultCode {
enum : u32 {
Success = 0,
};
}
// Enum values from Citra and struct definitions based off Citra
namespace Command {
enum : u16 {
Init = 0, // Initialize encoder/decoder
EncodeDecode = 1, // Encode/Decode AAC
Shutdown = 2, // Shutdown encoder/decoder
LoadState = 3,
SaveState = 4,
};
}
namespace SampleRate {
enum : u32 {
Rate48000 = 0,
Rate44100 = 1,
Rate32000 = 2,
Rate24000 = 3,
Rate22050 = 4,
Rate16000 = 5,
Rate12000 = 6,
Rate11025 = 7,
Rate8000 = 8,
};
}
namespace Mode {
enum : u16 {
None = 0,
Decode = 1,
Encode = 2,
};
}
struct DecodeResponse {
u32_le sampleRate = SampleRate::Rate48000;
u32_le channelCount = 0;
u32_le size = 0;
u32_le unknown1 = 0;
u32_le unknown2 = 0;
u32_le sampleCount = 0;
};
struct Message {
u16_le mode = Mode::None; // Encode or decode AAC?
u16_le command = Command::Init;
u32_le resultCode = ResultCode::Success;
// Info on the AAC request
union {
std::array<u8, 24> commandData = {};
DecodeResponse decodeResponse;
};
};
static_assert(sizeof(Message) == 32);
static_assert(std::is_trivially_copyable<Message>());
} // namespace Audio::AAC

View file

@ -5,6 +5,7 @@
#include <queue>
#include <vector>
#include "audio/aac.hpp"
#include "audio/dsp_core.hpp"
#include "audio/dsp_shared_mem.hpp"
#include "memory.hpp"
@ -166,6 +167,7 @@ namespace Audio {
}
}
void handleAACRequest(const AAC::Message& request);
void updateSourceConfig(Source& source, HLE::SourceConfiguration::Configuration& config, s16_le* adpcmCoefficients);
void generateFrame(StereoFrame<s16>& frame);
void generateFrame(DSPSource& source);

View file

@ -149,12 +149,24 @@ namespace Audio {
break;
}
case DSPPipeType::Binary:
Helpers::warn("Unimplemented write to binary pipe! Size: %d\n", size);
case DSPPipeType::Binary: {
log("Unimplemented write to binary pipe! Size: %d\n", size);
AAC::Message request;
if (size == sizeof(request)) {
std::array<u8, sizeof(request)> raw;
for (uint i = 0; i < size; i++) {
raw[i] = mem.read32(buffer + i);
}
std::memcpy(&request, raw.data(), sizeof(request));
handleAACRequest(request);
}
// This pipe and interrupt are normally used for requests like AAC decode
dspService.triggerPipeEvent(DSPPipeType::Binary);
break;
}
default: log("Audio::HLE_DSP: Wrote to unimplemented pipe %d\n", channel); break;
}
@ -488,6 +500,37 @@ namespace Audio {
return decodedSamples;
}
void HLE_DSP::handleAACRequest(const AAC::Message& request) {
AAC::Message response = {};
switch (request.command) {
case AAC::Command::EncodeDecode:
// Dummy response to stop games from hanging
// TODO: Fix this when implementing AAC
response.resultCode = AAC::ResultCode::Success;
response.decodeResponse.channelCount = 2;
response.decodeResponse.sampleCount = 1024;
response.decodeResponse.size = 0;
response.decodeResponse.sampleRate = AAC::SampleRate::Rate48000;
break;
case AAC::Command::Init:
case AAC::Command::Shutdown:
case AAC::Command::LoadState:
case AAC::Command::SaveState:
response = request;
response.resultCode = AAC::ResultCode::Success;
break;
default: Helpers::warn("Unknown AAC command type"); break;
}
// Copy response data to the binary pipe
auto& pipe = pipeData[DSPPipeType::Binary];
pipe.resize(sizeof(response));
std::memcpy(&pipe[0], &response, sizeof(response));
}
void DSPSource::reset() {
enabled = false;
isBufferIDDirty = false;