Minor refactor

This commit is contained in:
Henrik Rydgård
2025-06-16 18:29:38 +02:00
parent 96bf820c96
commit a721a0b6dd
8 changed files with 27 additions and 16 deletions
+3 -2
View File
@@ -164,16 +164,17 @@ LogManager::LogManager() {
stdioUseColor_ = isatty(fileno(stdout));
#endif
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
#if PPSSPP_PLATFORM(WINDOWS)
if (IsDebuggerPresent()) {
outputs_ |= LogOutput::DebugString;
}
#if !PPSSPP_PLATFORM(UWP)
if (!consoleLog_) {
consoleLog_ = new ConsoleListener();
}
outputs_ |= LogOutput::WinConsole;
#endif
#endif
}
LogManager::~LogManager() {
+1 -1
View File
@@ -344,7 +344,7 @@ static u32 sceSasSetVoice(u32 core, int voiceNum, u32 vagAddr, int size, int loo
u32 prevVagAddr = v.vagAddr;
bool reset = false;
if (v.type != VOICETYPE_VAG || v.vagAddr != vagAddr || v.vagSize != size || v.loop != loop) {
if (v.type != VOICETYPE_VAG || v.vagAddr != vagAddr || v.vagSize != size || v.loop != (loop != 0)) {
v.type = VOICETYPE_VAG;
reset = true;
}
+2 -2
View File
@@ -842,9 +842,9 @@ bool NativeInitGraphics(GraphicsContext *graphicsContext) {
#ifdef _WIN32
winAudioBackend = CreateAudioBackend((AudioBackendType)g_Config.iAudioBackend);
#if PPSSPP_PLATFORM(UWP)
winAudioBackend->Init(0, &NativeMix, 44100);
winAudioBackend->Init(&NativeMix);
#else
winAudioBackend->Init(MainWindow::GetHWND(), &NativeMix, 44100);
winAudioBackend->Init(&NativeMix);
#endif
#endif
+9 -4
View File
@@ -18,8 +18,9 @@ public:
XAudioBackend();
~XAudioBackend() override;
bool Init(HWND window, StreamCallback callback, int sampleRate) override; // If fails, can safely delete the object
bool Init(StreamCallback callback, void *userdata = nullptr) override; // If fails, can safely delete the object
int GetSampleRate() const override { return sampleRate_; }
int PeriodFrames() const override { return 0; }
private:
bool RunSound();
@@ -32,7 +33,10 @@ private:
IXAudio2MasteringVoice *xaudioMaster = nullptr;
IXAudio2SourceVoice *xaudioVoice = nullptr;
int sampleRate_ = 0;
void *userdata_ = nullptr;
int sampleRate_ = 44100;
int periodFrames_ = 0;
char realtimeBuffer_[BUFSIZE]{};
uint32_t cursor_ = 0;
@@ -126,9 +130,9 @@ XAudioBackend::~XAudioBackend() {
xaudioDevice->Release();
}
bool XAudioBackend::Init(HWND window, StreamCallback _callback, int sampleRate) {
bool XAudioBackend::Init(StreamCallback _callback, void *userdata) {
callback_ = _callback;
sampleRate_ = sampleRate;
userdata_ = userdata;
return RunSound();
}
@@ -170,6 +174,7 @@ void XAudioBackend::PollLoop() {
cursor_ = 0;
bytesLeftInBuffer = BUFSIZE;
}
periodFrames_ = stereoSamplesRendered;
}
SetEvent(exitEvent_);
+3 -4
View File
@@ -186,8 +186,7 @@ private:
#define REFTIMES_PER_SEC (10000000/200)
#define REFTIMES_PER_MILLISEC (REFTIMES_PER_SEC / 1000)
WASAPIAudioBackend::WASAPIAudioBackend() : threadData_(0) {
}
WASAPIAudioBackend::WASAPIAudioBackend() : threadData_(0) { }
WASAPIAudioBackend::~WASAPIAudioBackend() {
if (threadData_ == 0) {
@@ -210,10 +209,10 @@ unsigned int WINAPI WASAPIAudioBackend::soundThread(void *param) {
return backend->RunThread();
}
bool WASAPIAudioBackend::Init(HWND window, StreamCallback callback, int sampleRate) {
bool WASAPIAudioBackend::Init(StreamCallback callback, void *userdata) {
threadData_ = 0;
userdata_ = userdata;
callback_ = callback;
sampleRate_ = sampleRate;
hThread_ = (HANDLE)_beginthreadex(0, 0, soundThread, (void *)this, 0, 0);
if (!hThread_)
return false;
+5 -2
View File
@@ -10,8 +10,9 @@ public:
WASAPIAudioBackend();
~WASAPIAudioBackend();
bool Init(HWND window, StreamCallback callback, int sampleRate) override; // If fails, can safely delete the object
bool Init(StreamCallback callback, void *userdata) override; // If fails, can safely delete the object
int GetSampleRate() const override { return sampleRate_; }
int PeriodFrames() const override { return periodFrames_; } // amount of frames normally requested
private:
int RunThread();
@@ -20,5 +21,7 @@ private:
HANDLE hThread_ = nullptr;
StreamCallback callback_ = nullptr;
int sampleRate_ = 0;
std::atomic<int> threadData_;
int periodFrames_ = 0;
void *userdata_ = 0;
std::atomic<int> threadData_{};
};
+2 -1
View File
@@ -11,8 +11,9 @@ typedef int (*StreamCallback)(short *buffer, int numSamples, int rate);
class WindowsAudioBackend {
public:
virtual ~WindowsAudioBackend() {}
virtual bool Init(HWND window, StreamCallback _callback, int sampleRate) = 0;
virtual bool Init(StreamCallback _callback, void *userdata = nullptr) = 0;
virtual int GetSampleRate() const = 0;
virtual int PeriodFrames() const = 0;
};
// Factory
+2
View File
@@ -325,6 +325,8 @@ int64_t System_GetPropertyInt(SystemProperty prop) {
return (int64_t)MainWindow::GetHWND();
case SYSPROP_AUDIO_SAMPLE_RATE:
return winAudioBackend ? winAudioBackend->GetSampleRate() : -1;
case SYSPROP_AUDIO_FRAMES_PER_BUFFER:
return winAudioBackend ? winAudioBackend->PeriodFrames() : -1;
case SYSPROP_DEVICE_TYPE:
return DEVICE_TYPE_DESKTOP;
case SYSPROP_DISPLAY_COUNT: