Skip to content

Commit

Permalink
Added support for output sideband format query
Browse files Browse the repository at this point in the history
  • Loading branch information
roamic committed Nov 6, 2024
1 parent f733ae8 commit 6a069ab
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/core/libraries/ajm/ajm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,31 @@

namespace Libraries::Ajm {

constexpr int ORBIS_AJM_CHANNELMASK_MONO = 0x0004;
constexpr int ORBIS_AJM_CHANNELMASK_STEREO = 0x0003;
constexpr int ORBIS_AJM_CHANNELMASK_QUAD = 0x0033;
constexpr int ORBIS_AJM_CHANNELMASK_5POINT1 = 0x060F;
constexpr int ORBIS_AJM_CHANNELMASK_7POINT1 = 0x063F;

static std::unique_ptr<AjmContext> context{};

u32 GetChannelMask(u32 num_channels) {
switch (num_channels) {
case 1:
return ORBIS_AJM_CHANNELMASK_MONO;
case 2:
return ORBIS_AJM_CHANNELMASK_STEREO;
case 4:
return ORBIS_AJM_CHANNELMASK_QUAD;
case 6:
return ORBIS_AJM_CHANNELMASK_5POINT1;
case 8:
return ORBIS_AJM_CHANNELMASK_7POINT1;
default:
UNREACHABLE();
}
}

int PS4_SYSV_ABI sceAjmBatchCancel(const u32 context_id, const u32 batch_id) {
LOG_INFO(Lib_Ajm, "called context_id = {} batch_id = {}", context_id, batch_id);
return context->BatchCancel(batch_id);
Expand Down
2 changes: 2 additions & 0 deletions src/core/libraries/ajm/ajm.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ static_assert(sizeof(AjmInstanceFlags) == 8);

struct AjmDecMp3ParseFrame;

u32 GetChannelMask(u32 num_channels);

int PS4_SYSV_ABI sceAjmBatchCancel(const u32 context_id, const u32 batch_id);
int PS4_SYSV_ABI sceAjmBatchErrorDump();
void* PS4_SYSV_ABI sceAjmBatchJobControlBufferRa(void* p_buffer, u32 instance_id, u64 flags,
Expand Down
11 changes: 11 additions & 0 deletions src/core/libraries/ajm/ajm_at9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,15 @@ std::tuple<u32, u32> AjmAt9Decoder::ProcessData(std::span<u8>& in_buf, SparseOut
return {1, samples_written / m_codec_info.channels};
}

AjmSidebandFormat AjmAt9Decoder::GetFormat() {
return AjmSidebandFormat{
.num_channels = u32(m_codec_info.channels),
.channel_mask = GetChannelMask(u32(m_codec_info.channels)),
.sampl_freq = u32(m_codec_info.samplingRate),
.sample_encoding = m_format,
.bitrate = u32(m_codec_info.samplingRate * GetPointCodeSize() * 8),
.reserved = 0,
};
}

} // namespace Libraries::Ajm
1 change: 1 addition & 0 deletions src/core/libraries/ajm/ajm_at9.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct AjmAt9Decoder final : AjmCodec {
void Reset() override;
void Initialize(const void* buffer, u32 buffer_size) override;
void GetInfo(void* out_info) override;
AjmSidebandFormat GetFormat() override;
std::tuple<u32, u32> ProcessData(std::span<u8>& input, SparseOutputBuffer& output,
AjmSidebandGaplessDecode& gapless,
std::optional<u32> max_samples) override;
Expand Down
3 changes: 3 additions & 0 deletions src/core/libraries/ajm/ajm_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ void AjmInstance::ExecuteJob(AjmJob& job) {
m_gapless.skipped_samples = 0;
m_codec->Reset();
}
if (job.output.p_format != nullptr) {
*job.output.p_format = m_codec->GetFormat();
}
if (job.output.p_gapless_decode != nullptr) {
*job.output.p_gapless_decode = m_gapless;
}
Expand Down
1 change: 1 addition & 0 deletions src/core/libraries/ajm/ajm_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class AjmCodec {
virtual void Initialize(const void* buffer, u32 buffer_size) = 0;
virtual void Reset() = 0;
virtual void GetInfo(void* out_info) = 0;
virtual AjmSidebandFormat GetFormat() = 0;
virtual std::tuple<u32, u32> ProcessData(std::span<u8>& input, SparseOutputBuffer& output,
AjmSidebandGaplessDecode& gapless,
std::optional<u32> max_samples_per_channel) = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/core/libraries/ajm/ajm_mp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,9 @@ int AjmMp3Decoder::ParseMp3Header(const u8* buf, u32 stream_size, int parse_ofl,
return ORBIS_OK;
}

AjmSidebandFormat AjmMp3Decoder::GetFormat() {
LOG_ERROR(Lib_Ajm, "Unimplemented");
return AjmSidebandFormat{};
};

} // namespace Libraries::Ajm
1 change: 1 addition & 0 deletions src/core/libraries/ajm/ajm_mp3.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class AjmMp3Decoder : public AjmCodec {
void Reset() override;
void Initialize(const void* buffer, u32 buffer_size) override {}
void GetInfo(void* out_info) override;
AjmSidebandFormat GetFormat() override;
std::tuple<u32, u32> ProcessData(std::span<u8>& input, SparseOutputBuffer& output,
AjmSidebandGaplessDecode& gapless,
std::optional<u32> max_samples_per_channel) override;
Expand Down

0 comments on commit 6a069ab

Please sign in to comment.