1
0
Fork 0
This repository has been archived on 2024-03-23. You can view files and clone it, but cannot push or open issues or pull requests.
citra-nightly/src/audio_core/hle/decoder.h

91 lines
2.4 KiB
C++
Raw Normal View History

2018-12-09 21:25:45 +00:00
// Copyright 2018 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <optional>
#include <vector>
#include "common/common_types.h"
#include "common/swap.h"
#include "core/core.h"
namespace AudioCore::HLE {
enum class DecoderCommand : u16 {
Init,
Decode,
Unknown,
};
enum class DecoderCodec : u16 {
None,
AAC,
};
// TODO(xperia64): I'm guessing that this is a u32 (from when it was an unknown)
// but it could be a u16 or u8 I suppose
enum class DecoderSampleRate : u32 {
Rate48000 = 0,
Rate44100 = 1,
Rate32000 = 2,
Rate24000 = 3,
Rate22050 = 4,
Rate16000 = 5,
Rate12000 = 6,
Rate11025 = 7,
Rate8000 = 8
};
2018-12-09 21:25:45 +00:00
struct BinaryRequest {
enum_le<DecoderCodec> codec =
DecoderCodec::None; // this is a guess. until now only 0x1 was observed here
enum_le<DecoderCommand> cmd = DecoderCommand::Init;
u32_le fixed = 0;
u32_le src_addr = 0;
u32_le size = 0;
u32_le dst_addr_ch0 = 0;
u32_le dst_addr_ch1 = 0;
u32_le unknown1 = 0;
u32_le unknown2 = 0;
};
static_assert(sizeof(BinaryRequest) == 32, "Unexpected struct size for BinaryRequest");
struct BinaryResponse {
enum_le<DecoderCodec> codec =
DecoderCodec::None; // this could be something else. until now only 0x1 was observed here
enum_le<DecoderCommand> cmd = DecoderCommand::Init;
u32_le unknown1 = 0;
enum_le<DecoderSampleRate> sample_rate;
2018-12-09 21:25:45 +00:00
u32_le num_channels = 0; // this is a guess, so far I only observed 2 here
u32_le size = 0;
u32_le unknown3 = 0;
u32_le unknown4 = 0;
u32_le num_samples = 0; // this is a guess, so far I only observed 1024 here
};
static_assert(sizeof(BinaryResponse) == 32, "Unexpected struct size for BinaryResponse");
enum_le<DecoderSampleRate> GetSampleRateEnum(u32 sample_rate);
2018-12-09 21:25:45 +00:00
class DecoderBase {
public:
2018-12-16 14:03:23 +00:00
virtual ~DecoderBase();
2018-12-09 21:25:45 +00:00
virtual std::optional<BinaryResponse> ProcessRequest(const BinaryRequest& request) = 0;
2019-12-08 21:19:19 +00:00
/// Return true if this Decoder can be loaded. Return false if the system cannot create the
/// decoder
virtual bool IsValid() const = 0;
2018-12-09 21:25:45 +00:00
};
class NullDecoder final : public DecoderBase {
public:
NullDecoder();
~NullDecoder() override;
std::optional<BinaryResponse> ProcessRequest(const BinaryRequest& request) override;
2019-12-08 21:19:19 +00:00
bool IsValid() const override {
return true;
}
2018-12-09 21:25:45 +00:00
};
} // namespace AudioCore::HLE