mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-27 00:28:14 +00:00
63 lines
2.9 KiB
C++
63 lines
2.9 KiB
C++
#include "prx/libSceAudioOut/include/AudioOut2.hpp"
|
|
#include "prx/libSceAudio3d/include/Audio3d.hpp"
|
|
#include "SceTypes.hpp"
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <exception>
|
|
|
|
namespace {
|
|
|
|
constexpr int INVALID_PARAMETER = static_cast<int>(0x80EA0004);
|
|
|
|
void Require(bool value, const char* message) {
|
|
if (value) return;
|
|
std::fprintf(stderr, "%s\n", message);
|
|
std::abort();
|
|
}
|
|
|
|
template <typename F>
|
|
void RequireThrows(F f, const char* message) {
|
|
bool threw = false;
|
|
try {
|
|
f();
|
|
} catch (const std::exception&) {
|
|
threw = true;
|
|
}
|
|
Require(threw, message);
|
|
}
|
|
|
|
}
|
|
|
|
int main() {
|
|
Require(sceAudio3dGetSpeakerArrayMemorySize(4, 1) == sceAudioOut2GetSpeakerArrayMemorySize(4, 1, 0), "memory size forwards to AudioOut2 without ambisonics");
|
|
RequireThrows([] { sceAudio3dGetSpeakerArrayMemorySize(0, 0); }, "zero speakers throws invalid_argument");
|
|
|
|
const AudioOut2Position positions[4] = {{1, 1, 0}, {1, -1, 0}, {-1, 1, 0}, {-1, -1, 0}};
|
|
alignas(16) unsigned char memory[1024] = {};
|
|
const std::size_t size = sceAudio3dGetSpeakerArrayMemorySize(4, 0);
|
|
Require(size <= sizeof(memory), "speaker array fits the test buffer");
|
|
const Audio3dSpeakerArrayParameters parameters{positions, 4, 0, memory, size};
|
|
|
|
AudioOut2SpeakerArrayHandle handle = nullptr;
|
|
Require(sceAudio3dCreateSpeakerArray(nullptr, ¶meters) == INVALID_PARAMETER, "null handle is an invalid parameter");
|
|
Require(sceAudio3dCreateSpeakerArray(&handle, nullptr) == INVALID_PARAMETER, "null parameters are an invalid parameter");
|
|
Require(handle == nullptr, "a rejected create leaves the handle");
|
|
Require(sceAudio3dCreateSpeakerArray(&handle, ¶meters) == 0, "create succeeds without ambisonics parameters");
|
|
Require(handle != nullptr, "create stores the handle");
|
|
|
|
float coefficients[4] = {-1, -1, -1, -1};
|
|
Require(sceAudio3dGetSpeakerArrayMixCoefficients(handle, AudioOut2Position{1, 0, 0}, 0.0f, coefficients, 4) == 0, "mix coefficients succeed");
|
|
Require(coefficients[2] == 0.0f && coefficients[3] == 0.0f, "mix coefficients are written");
|
|
float coefficients2[4] = {-1, -1, -1, -1};
|
|
Require(sceAudio3dGetSpeakerArrayMixCoefficients2(handle, AudioOut2Position{1, 0, 0}, 0.0f, coefficients2, 4, 1, 0.5f) == 0, "mix coefficients 2 succeed");
|
|
Require(coefficients2[3] == 0.0f, "mix coefficients 2 are written");
|
|
RequireThrows([&] { sceAudio3dGetSpeakerArrayMixCoefficients(handle, AudioOut2Position{1, 0, 0}, 0.0f, coefficients, 3); }, "a coefficient count that differs from the array is rejected");
|
|
RequireThrows([&] { sceAudio3dGetSpeakerArrayMixCoefficients(handle, AudioOut2Position{1, 0, 0}, 0.0f, nullptr, 4); }, "null coefficients pointer throws invalid_argument");
|
|
|
|
Require(sceAudio3dDeleteSpeakerArray(handle) == 0, "delete succeeds");
|
|
RequireThrows([&] { sceAudio3dDeleteSpeakerArray(handle); }, "a deleted array is no longer valid");
|
|
return 0;
|
|
}
|