mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-16 11:03:45 +01:00
sceAudio: Check sceAudioInput's arguments and routing modes like the PSP
pspautotests audio/sceaudio/input and audio/sceaudio/routing. - sceAudioInput fails until sceAudioInputInit, then checks that the sample count is a nonzero multiple of 64 before checking the rate (11025, 22050 or 44100 only). A rate of 0 now gets the PSP's error instead of the USB mic's. Init takes about 3ms. - A blocking mic input woke with the byte count rather than the sample count that the non-blocking call returns. - The routing functions are exported by both sceAudio and sceAudioRouting, and the latter had its own copy that ignored the stored modes. Both now share the one in sceAudio, with the ranges checked. SetVolumeMode returns 0, not the previous mode, and both modes start at 0. sceAudio's savestate section goes to version 5 for the input init flag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3880999ada
commit
561badca05
8 files changed
+89
-61
No files matched your search
@@ -4,6 +4,7 @@
|
||||
|
||||
enum PSPErrorCode : u32 {
|
||||
SCE_KERNEL_ERROR_OK = 0,
|
||||
SCE_KERNEL_ERROR_NOT_INITIALIZED = 0x80000001, // Name guessed, from sceAudioInput before init.
|
||||
SCE_KERNEL_ERROR_BAD_ARGUMENT = 0x80000004, // Maybe
|
||||
SCE_KERNEL_ERROR_ALREADY = 0x80000020,
|
||||
SCE_KERNEL_ERROR_BUSY = 0x80000021,
|
||||
@@ -373,6 +374,7 @@ enum PSPErrorCode : u32 {
|
||||
SCE_ERROR_AUDIO_INVALID_FREQUENCY = 0x8026000A,
|
||||
SCE_ERROR_AUDIO_INVALID_VOLUME = 0x8026000B,
|
||||
SCE_ERROR_AUDIO_CHANNEL_ALREADY_RESERVED = 0x80268002,
|
||||
SCE_ERROR_AUDIO_ROUTING_INVALID_MODE = 0x802C01FE,
|
||||
|
||||
SCE_ERROR_USBMIC_INVALID_MAX_SAMPLES = 0x80243806,
|
||||
SCE_ERROR_USBMIC_INVALID_SAMPLERATE = 0x8024380A,
|
||||
|
||||
@@ -112,6 +112,8 @@ void __AudioInit() {
|
||||
g_audioChans[i].clear();
|
||||
}
|
||||
g_audioSRC.clear();
|
||||
__AudioRoutingInit();
|
||||
audioInputInited = false;
|
||||
|
||||
mixBuffer = new s32[hwBlockSize * 2];
|
||||
clampedMixBuffer = new s16[hwBlockSize * 2];
|
||||
@@ -121,7 +123,7 @@ void __AudioInit() {
|
||||
}
|
||||
|
||||
void __AudioDoState(PointerWrap &p) {
|
||||
auto s = p.Section("sceAudio", 1, 4);
|
||||
auto s = p.Section("sceAudio", 1, 5);
|
||||
if (!s)
|
||||
return;
|
||||
|
||||
@@ -197,6 +199,12 @@ void __AudioDoState(PointerWrap &p) {
|
||||
} else {
|
||||
mixerDMABusy = false;
|
||||
}
|
||||
if (s >= 5) {
|
||||
Do(p, audioInputInited);
|
||||
} else {
|
||||
// A game that was already capturing had initialized it.
|
||||
audioInputInited = true;
|
||||
}
|
||||
// For older states the routing modes were read back once per channel, above.
|
||||
|
||||
__AudioCPUMHzChange();
|
||||
|
||||
+59
-22
@@ -33,10 +33,11 @@
|
||||
|
||||
const u32 PSP_AUDIO_SAMPLE_MAX = 65536 - 64;
|
||||
const int PSP_AUDIO_ERROR_SRC_FORMAT_4 = 0x80000003;
|
||||
const int AUDIO_ROUTING_SPEAKER_OFF = 0;
|
||||
const int AUDIO_ROUTING_SPEAKER_ON = 1;
|
||||
int defaultRoutingMode = AUDIO_ROUTING_SPEAKER_ON;
|
||||
int defaultRoutingVolMode = AUDIO_ROUTING_SPEAKER_ON;
|
||||
// Both read 0 at boot on a PSP.
|
||||
int defaultRoutingMode = 0;
|
||||
int defaultRoutingVolMode = 0;
|
||||
// sceAudioInput fails until sceAudioInputInit.
|
||||
bool audioInputInited = false;
|
||||
|
||||
// Only still here to read savestates written before the channels held buffer pointers.
|
||||
struct AudioChannelWaitInfo {
|
||||
@@ -157,6 +158,11 @@ void AudioSRCChannel::DoState(PointerWrap &p) {
|
||||
Do(p, waitingThreads);
|
||||
}
|
||||
|
||||
void __AudioRoutingInit() {
|
||||
defaultRoutingMode = 0;
|
||||
defaultRoutingVolMode = 0;
|
||||
}
|
||||
|
||||
void __AudioRoutingDoState(PointerWrap &p) {
|
||||
auto s = p.Section("sceAudioRouting", 1);
|
||||
if (!s)
|
||||
@@ -543,7 +549,25 @@ static u32 sceAudioSRCOutputBlocking(u32 vol, u32 buf) {
|
||||
return hleLogDebug(Log::sceAudio, __AudioSRCEnqueueBlocking(g_audioSRC, buf, vol));
|
||||
}
|
||||
|
||||
// From pspautotests audio/sceaudio/input. The size is checked first.
|
||||
static int AudioInputCheck(u32 maxSamples, u32 sampleRate) {
|
||||
if (!audioInputInited) {
|
||||
return SCE_KERNEL_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
if (maxSamples == 0 || (maxSamples & 63) != 0 || maxSamples >= 0x80000000) {
|
||||
return SCE_ERROR_AUDIO_OUTPUT_SAMPLE_DATA_SIZE_NOT_ALIGNED;
|
||||
}
|
||||
if (sampleRate != 44100 && sampleRate != 22050 && sampleRate != 11025) {
|
||||
return SCE_ERROR_AUDIO_INVALID_FREQUENCY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sceAudioInputBlocking(u32 maxSamples, u32 sampleRate, u32 bufAddr) {
|
||||
int error = AudioInputCheck(maxSamples, sampleRate);
|
||||
if (error != 0) {
|
||||
return hleLogError(Log::HLE, error);
|
||||
}
|
||||
if (!Memory::IsValidAddress(bufAddr)) {
|
||||
return hleLogError(Log::HLE, -1, "invalid address");
|
||||
}
|
||||
@@ -551,6 +575,13 @@ static int sceAudioInputBlocking(u32 maxSamples, u32 sampleRate, u32 bufAddr) {
|
||||
}
|
||||
|
||||
static int sceAudioInput(u32 maxSamples, u32 sampleRate, u32 bufAddr) {
|
||||
int error = AudioInputCheck(maxSamples, sampleRate);
|
||||
if (error != 0) {
|
||||
return hleLogError(Log::HLE, error);
|
||||
}
|
||||
if (bufAddr == 0) {
|
||||
return hleLogWarning(Log::HLE, 0, "NULL buffer");
|
||||
}
|
||||
if (!Memory::IsValidAddress(bufAddr)) {
|
||||
return hleLogError(Log::HLE, -1, "invalid address");
|
||||
}
|
||||
@@ -561,11 +592,14 @@ static int sceAudioInput(u32 maxSamples, u32 sampleRate, u32 bufAddr) {
|
||||
|
||||
static int sceAudioInputInit(int unknown1, int gain, int unknown2) {
|
||||
ERROR_LOG(Log::HLE, "UNIMPL sceAudioInputInit: unknown1: %d, gain: %d, unknown2: %d", unknown1, gain, unknown2);
|
||||
return 0;
|
||||
audioInputInited = true;
|
||||
// Takes about 3ms on a PSP.
|
||||
return hleDelayResult(0, "audio input init", 3000);
|
||||
}
|
||||
|
||||
static int sceAudioInputInitEx(u32 paramAddr) {
|
||||
ERROR_LOG(Log::HLE, "UNIMPL sceAudioInputInitEx: paramAddr: %08x", paramAddr);
|
||||
audioInputInited = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -583,28 +617,31 @@ static int sceAudioGetInputLength() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static u32 sceAudioRoutingSetMode(u32 mode) {
|
||||
ERROR_LOG(Log::sceAudio, "sceAudioRoutingSetMode(%08x)", mode);
|
||||
// Ranges and return values from pspautotests audio/sceaudio/routing. Also exported as sceAudioRouting.
|
||||
int sceAudioRoutingSetMode(int mode) {
|
||||
if (mode < 0 || mode > 3) {
|
||||
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_ROUTING_INVALID_MODE, "invalid mode");
|
||||
}
|
||||
int previousMode = defaultRoutingMode;
|
||||
defaultRoutingMode = mode;
|
||||
return previousMode;
|
||||
return hleLogInfo(Log::sceAudio, previousMode);
|
||||
}
|
||||
|
||||
static u32 sceAudioRoutingGetMode() {
|
||||
ERROR_LOG(Log::sceAudio, "sceAudioRoutingGetMode()");
|
||||
return defaultRoutingMode;
|
||||
int sceAudioRoutingGetMode() {
|
||||
return hleLogDebug(Log::sceAudio, defaultRoutingMode);
|
||||
}
|
||||
|
||||
static u32 sceAudioRoutingSetVolumeMode(u32 mode) {
|
||||
ERROR_LOG(Log::sceAudio, "sceAudioRoutingSetVolumeMode(%08x)", mode);
|
||||
int previousMode = defaultRoutingVolMode;
|
||||
// Unlike SetMode, this returns 0 rather than the previous mode.
|
||||
int sceAudioRoutingSetVolumeMode(int mode) {
|
||||
if (mode < 0 || mode > 1) {
|
||||
return hleLogError(Log::sceAudio, SCE_ERROR_AUDIO_ROUTING_INVALID_MODE, "invalid mode");
|
||||
}
|
||||
defaultRoutingVolMode = mode;
|
||||
return previousMode;
|
||||
return hleLogInfo(Log::sceAudio, 0);
|
||||
}
|
||||
|
||||
static u32 sceAudioRoutingGetVolumeMode() {
|
||||
ERROR_LOG(Log::sceAudio, "sceAudioRoutingGetVolumeMode()");
|
||||
return defaultRoutingVolMode;
|
||||
int sceAudioRoutingGetVolumeMode() {
|
||||
return hleLogDebug(Log::sceAudio, defaultRoutingVolMode);
|
||||
}
|
||||
|
||||
const HLEFunction sceAudio[] =
|
||||
@@ -653,10 +690,10 @@ const HLEFunction sceAudio[] =
|
||||
{0XA633048E, &WrapI_V<sceAudioPollInputEnd>, "sceAudioPollInputEnd", 'i', "" },
|
||||
{0X87B2E651, &WrapI_V<sceAudioWaitInputEnd>, "sceAudioWaitInputEnd", 'i', "" },
|
||||
|
||||
{0X36FD8AA9, &WrapU_U<sceAudioRoutingSetMode>, "sceAudioRoutingSetMode", 'x', "x" },
|
||||
{0X39240E7D, &WrapU_V<sceAudioRoutingGetMode>, "sceAudioRoutingGetMode", 'x', "" },
|
||||
{0XBB548475, &WrapU_U<sceAudioRoutingSetVolumeMode>, "sceAudioRoutingSetVolumeMode", 'x', "x" },
|
||||
{0X28235C56, &WrapU_V<sceAudioRoutingGetVolumeMode>, "sceAudioRoutingGetVolumeMode", 'x', "" },
|
||||
{0X36FD8AA9, &WrapI_I<sceAudioRoutingSetMode>, "sceAudioRoutingSetMode", 'i', "i" },
|
||||
{0X39240E7D, &WrapI_V<sceAudioRoutingGetMode>, "sceAudioRoutingGetMode", 'i', "" },
|
||||
{0XBB548475, &WrapI_I<sceAudioRoutingSetVolumeMode>, "sceAudioRoutingSetVolumeMode", 'i', "i" },
|
||||
{0X28235C56, &WrapI_V<sceAudioRoutingGetVolumeMode>, "sceAudioRoutingGetVolumeMode", 'i', "" },
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -114,7 +114,16 @@ extern AudioSRCChannel g_audioSRC;
|
||||
bool SRCFrequencyAllowed(int freq);
|
||||
|
||||
// The two routing modes are globals rather than per-channel; they get their own little block.
|
||||
void __AudioRoutingInit();
|
||||
|
||||
extern bool audioInputInited;
|
||||
void __AudioRoutingDoState(PointerWrap &p);
|
||||
|
||||
// sceAudioRouting exports the same four functions.
|
||||
int sceAudioRoutingSetMode(int mode);
|
||||
int sceAudioRoutingGetMode();
|
||||
int sceAudioRoutingSetVolumeMode(int mode);
|
||||
int sceAudioRoutingGetVolumeMode();
|
||||
|
||||
void Register_sceAudio();
|
||||
|
||||
@@ -17,39 +17,7 @@
|
||||
|
||||
#include "Core/HLE/HLE.h"
|
||||
#include "Core/HLE/FunctionWrappers.h"
|
||||
#include "Core/HLE/sceAudiocodec.h"
|
||||
|
||||
enum {
|
||||
AUDIO_ROUTING_SPEAKER_OFF = 0,
|
||||
AUDIO_ROUTING_SPEAKER_ON = 1,
|
||||
};
|
||||
|
||||
u32 audioRoutingMode = AUDIO_ROUTING_SPEAKER_ON;
|
||||
u32 audioRoutineVolumeMode = AUDIO_ROUTING_SPEAKER_ON;
|
||||
|
||||
static int sceAudioRoutingGetMode() {
|
||||
INFO_LOG(Log::sceAudio, "sceAudioRoutingGetMode");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sceAudioRoutingSetVolumeMode(int mode) {
|
||||
INFO_LOG(Log::sceAudio, "sceAudioRoutingSetVolumeMode %d", mode);
|
||||
int previousMode = audioRoutineVolumeMode;
|
||||
audioRoutineVolumeMode = mode;
|
||||
return previousMode;
|
||||
}
|
||||
|
||||
static int sceAudioRoutingGetVolumeMode() {
|
||||
INFO_LOG(Log::sceAudio, "sceAudioRoutingGetMode");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sceAudioRoutingSetMode(int mode) {
|
||||
INFO_LOG(Log::sceAudio, "sceAudioRoutingSetMode %d", mode);
|
||||
int previousMode = audioRoutingMode;
|
||||
audioRoutingMode = mode;
|
||||
return previousMode;
|
||||
}
|
||||
#include "Core/HLE/sceAudio.h"
|
||||
|
||||
const HLEFunction sceAudioRouting[] =
|
||||
{
|
||||
|
||||
@@ -437,8 +437,8 @@ void Microphone::onMicDeviceChange() {
|
||||
}
|
||||
|
||||
u32 __MicInput(u32 maxSamples, u32 sampleRate, u32 bufAddr, MICTYPE type, bool block) {
|
||||
// sceAudioInput and the camera mic pass these straight through. The wait below divides by the
|
||||
// rate, and the size sizes a host buffer. Not tested on the PSP.
|
||||
// The camera mic passes these straight through (sceAudioInput checks them first). The wait below
|
||||
// divides by the rate, and the size sizes a host buffer.
|
||||
if (sampleRate == 0) {
|
||||
return SCE_ERROR_USBMIC_INVALID_SAMPLERATE;
|
||||
}
|
||||
@@ -484,9 +484,11 @@ u32 __MicInput(u32 maxSamples, u32 sampleRate, u32 bufAddr, MICTYPE type, bool b
|
||||
MicWaitInfo waitInfo = { __KernelGetCurThread(), bufAddr, size, sampleRate };
|
||||
waitingThreads.push_back(waitInfo);
|
||||
DEBUG_LOG(Log::HLE, "MicInputBlocking: blocking thread(%d)", (int)__KernelGetCurThread());
|
||||
__KernelWaitCurThread(WAITTYPE_MICINPUT, 1, size, 0, false, "blocking microphone");
|
||||
// The wait value is what the thread gets back when it's woken.
|
||||
const u32 result = type == CAMERAMIC ? size : maxSamples;
|
||||
__KernelWaitCurThread(WAITTYPE_MICINPUT, 1, result, 0, false, "blocking microphone");
|
||||
|
||||
return type == CAMERAMIC ? size : maxSamples;
|
||||
return result;
|
||||
}
|
||||
|
||||
// A non-blocking input keeps filling its buffer from addAudioData() after it returns.
|
||||
|
||||
+1
-1
Submodule pspautotests updated: fab33ea469...e2d098fcf3.
Reference in new issue
Block a user