Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions core/libs/prx/libSceNgs2.native/src/Voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,8 +1306,7 @@ int APS5_VABI sceNgs2VoiceGetState(uintptr_t voice_handle, Ngs2VoiceState* state
case SCE_NGS2_RACK_ID_SAMPLER: {
const bool commonOnly = PS4_LIBRARY && state_size == sizeof(Ngs2VoiceState);
if (!commonOnly && state_size != sizeof(Ngs2SamplerVoiceState)) return SCE_NGS2_ERROR_INVALID_OUT_SIZE;
Ngs2SamplerVoiceState commonResult;
auto& sampler = commonOnly ? commonResult : *reinterpret_cast<Ngs2SamplerVoiceState*>(state);
Ngs2SamplerVoiceState sampler{};
if (voice.pendingPlay) {
sampler = {};
sampler.voice_state.state_flags = SCE_NGS2_VOICE_STATE_FLAG_INUSE;
Expand All @@ -1325,38 +1324,48 @@ int APS5_VABI sceNgs2VoiceGetState(uintptr_t voice_handle, Ngs2VoiceState* state
sampler.waveform_data = voice.WaveformData();
}
}
if (commonOnly) *state = sampler.voice_state;
if (commonOnly) {
if (!WriteGuest(state, sampler.voice_state)) return SCE_NGS2_ERROR_INVALID_OUT_ADDRESS;
return SCE_NGS2_OK;
}
if (!WriteGuestBytes(state, &sampler, sizeof(sampler))) return SCE_NGS2_ERROR_INVALID_OUT_ADDRESS;
return SCE_NGS2_OK;
}
case SCE_NGS2_RACK_ID_REVERB: {
if (state_size != sizeof(Ngs2VoiceState)) return SCE_NGS2_ERROR_INVALID_OUT_SIZE;
*state = {};
state->state_flags = voice.stateFlags;
Ngs2VoiceState reverb{};
reverb.state_flags = voice.stateFlags;
if (!WriteGuest(state, reverb)) return SCE_NGS2_ERROR_INVALID_OUT_ADDRESS;
return SCE_NGS2_OK;
}
case SCE_NGS2_RACK_ID_SUBMIXER: {
if (state_size != sizeof(Ngs2SubmixerVoiceState)) return SCE_NGS2_ERROR_INVALID_OUT_SIZE;
auto& submixer = *reinterpret_cast<Ngs2SubmixerVoiceState*>(state);
submixer = {};
Ngs2SubmixerVoiceState submixer{};
submixer.voice_state.state_flags = voice.stateFlags;
submixer.peak_height = voice.peakHeight;
if (!WriteGuestBytes(state, &submixer, sizeof(submixer))) return SCE_NGS2_ERROR_INVALID_OUT_ADDRESS;
return SCE_NGS2_OK;
}
case SCE_NGS2_RACK_ID_CUSTOM_SAMPLER: {
if (state_size != sizeof(Ngs2CustomSamplerVoiceState)) return SCE_NGS2_ERROR_INVALID_OUT_SIZE;
auto& sampler = *reinterpret_cast<Ngs2CustomSamplerVoiceState*>(state);
if (voice.pendingPlay) { sampler = {}; sampler.voice_state.state_flags = SCE_NGS2_VOICE_STATE_FLAG_INUSE; return SCE_NGS2_OK; }
sampler = {};
sampler.voice_state.state_flags = voice.stateFlags;
if ((voice.rack->system == nullptr || voice.rack->system->renderDepth == 0) && voice.state == Ngs2PlayState::Empty) return SCE_NGS2_OK;
sampler.num_decoded_samples = voice.rack->system != nullptr && voice.rack->system->renderDepth != 0 && voice.rack->system->jobManagers[0].handle != 0
? voice.publishedSampler.num_decoded_samples : voice.decodedSamples;
Ngs2CustomSamplerVoiceState sampler{};
if (voice.pendingPlay) {
sampler.voice_state.state_flags = SCE_NGS2_VOICE_STATE_FLAG_INUSE;
} else {
sampler.voice_state.state_flags = voice.stateFlags;
if (!((voice.rack->system == nullptr || voice.rack->system->renderDepth == 0) && voice.state == Ngs2PlayState::Empty)) {
sampler.num_decoded_samples = voice.rack->system != nullptr && voice.rack->system->renderDepth != 0 && voice.rack->system->jobManagers[0].handle != 0
? voice.publishedSampler.num_decoded_samples : voice.decodedSamples;
}
}
if (!WriteGuestBytes(state, &sampler, sizeof(sampler))) return SCE_NGS2_ERROR_INVALID_OUT_ADDRESS;
return SCE_NGS2_OK;
}
case SCE_NGS2_RACK_ID_CUSTOM_MASTERING: {
if (state_size != sizeof(Ngs2VoiceState)) return SCE_NGS2_ERROR_INVALID_OUT_SIZE;
*state = {};
state->state_flags = voice.stateFlags;
Ngs2VoiceState mastering{};
mastering.state_flags = voice.stateFlags;
if (!WriteGuest(state, mastering)) return SCE_NGS2_ERROR_INVALID_OUT_ADDRESS;
return SCE_NGS2_OK;
}
default: throw std::runtime_error("NGS2: voice state of rack " + Ngs2Hex(voice.rack->rackId) + " is not implemented");
Expand Down
1 change: 1 addition & 0 deletions core/libs/prx/libSceNgs2.native/tests/Ngs2Custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,7 @@ static void TestCustomMastering() {
uintptr_t rack = 0;
Require(sceNgs2RackCreate(system, SCE_NGS2_RACK_ID_CUSTOM_MASTERING, &good.custom_rack_option.rack_option, &info, &rack) == SCE_NGS2_OK);
const auto voice = Voice(rack);
Require(sceNgs2VoiceGetState(voice, reinterpret_cast<Ngs2VoiceState*>(0x10), sizeof(Ngs2VoiceState)) == SCE_NGS2_ERROR_INVALID_OUT_ADDRESS);

Control(voice, SCE_NGS2_CUSTOM_MASTERING_VOICE_PARAM_SETUP, Ngs2MasteringVoiceSetupParam{{}, 2, 0});
Control(voice, SCE_NGS2_CUSTOM_MASTERING_VOICE_PARAM_GAIN, Ngs2MasteringVoiceGainParam{{}, 1.0f, 1.0f});
Expand Down
4 changes: 3 additions & 1 deletion core/libs/prx/libSceNgs2.native/tests/Ngs2Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,9 @@ static uintptr_t CustomFilterVoice(uintptr_t system, std::uint32_t modules = 1)
const auto info = Buffer(query);
uintptr_t rack = 0;
Require(sceNgs2RackCreate(system, SCE_NGS2_RACK_ID_CUSTOM_SAMPLER, &option.custom_rack_option.rack_option, &info, &rack) == SCE_NGS2_OK);
return Voice(rack);
const auto voice = Voice(rack);
Require(sceNgs2VoiceGetState(voice, reinterpret_cast<Ngs2VoiceState*>(0x10), sizeof(Ngs2CustomSamplerVoiceState)) == SCE_NGS2_ERROR_INVALID_OUT_ADDRESS);
return voice;
}

static std::vector<std::int16_t> OraclePcm() {
Expand Down
6 changes: 6 additions & 0 deletions core/libs/prx/libSceNgs2.native/tests/Ngs2VoiceHandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ int main(int argc, char** argv) {
Status(sceNgs2VoiceGetOwner(voice, &owner, nullptr), SCE_NGS2_ERROR_INVALID_OUT_ADDRESS, "GetOwner lost null-index validation");
Require(owner == 0x5a5a && index == 0x5a5a);
errno = 71;
Status(sceNgs2VoiceGetState(voice, reinterpret_cast<Ngs2VoiceState*>(0x10), sizeof(Ngs2SamplerVoiceState)), SCE_NGS2_ERROR_INVALID_OUT_ADDRESS, "GetState accepted an unwritable sampler output");
const auto reverbVoice = Voice(CreateRack(system, SCE_NGS2_RACK_ID_REVERB));
Status(sceNgs2VoiceGetState(reverbVoice, reinterpret_cast<Ngs2VoiceState*>(0x10), sizeof(Ngs2VoiceState)), SCE_NGS2_ERROR_INVALID_OUT_ADDRESS, "GetState accepted an unwritable reverb output");
const auto submixerVoice = Voice(CreateRack(system, SCE_NGS2_RACK_ID_SUBMIXER));
Status(sceNgs2VoiceGetState(submixerVoice, reinterpret_cast<Ngs2VoiceState*>(0x10), sizeof(Ngs2SubmixerVoiceState)), SCE_NGS2_ERROR_INVALID_OUT_ADDRESS, "GetState accepted an unwritable submixer output");
Require(errno == 71);
Status(sceNgs2VoiceGetStateFlags(voice, reinterpret_cast<std::uint32_t*>(0x10)), SCE_NGS2_ERROR_INVALID_OUT_ADDRESS, "GetStateFlags accepted an unwritable output");
Status(sceNgs2VoiceGetOwner(voice, reinterpret_cast<uintptr_t*>(0x10), &index), SCE_NGS2_ERROR_INVALID_OUT_ADDRESS, "GetOwner accepted an unwritable rack output");
Status(sceNgs2VoiceGetOwner(voice, &owner, reinterpret_cast<std::uint32_t*>(0x10)), SCE_NGS2_ERROR_INVALID_OUT_ADDRESS, "GetOwner accepted an unwritable index output");
Expand Down
Loading