mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-08-07 05:29:33 -06:00
Refactor NDS
and DSi
to be objects (#1893)
* First crack at refactoring NDS and DSi into objects - Remove all global/`static` variables in `NDS` and related classes - Rely more on virtual dispatch when we need to pick methods at runtime - Pass `NDS&` or `DSi&` to its constituent components where necessary - Introduce some headers or move some definitions to break `#include` cycles * Refactor the frontend to accommodate the core's changes * Move up `SchedList`'s declaration - Move it to before the components are initialized so the `map`s inside are initialized - Fields in C++ are initialized in the order they're declared * Fix a crash when allocating memory * Fix JIT-free builds * Fix GDB-free builds * Fix Linux builds - Explicitly qualify some member types in NDS, since they share the same name as their classes * Remove an unnecessary template argument - This was causing the build to fail on macOS * Fix ARM and Android builds * Rename `Constants.h` to `MemConstants.h` * Add `NDS::IsRunning()` * Use an `#include` guard instead of `#pragma once`
This commit is contained in:

committed by
GitHub

parent
c84cb17462
commit
e973236203
@ -55,8 +55,9 @@ void AudioCallback(void* data, Uint8* stream, int len)
|
||||
s16 buf_in[1024*2];
|
||||
int num_in;
|
||||
|
||||
EmuThread* emuThread = (EmuThread*)data;
|
||||
SDL_LockMutex(audioSyncLock);
|
||||
num_in = NDS::SPU->ReadOutput(buf_in, len_in);
|
||||
num_in = emuThread->NDS->SPU.ReadOutput(buf_in, len_in);
|
||||
SDL_CondSignal(audioSync);
|
||||
SDL_UnlockMutex(audioSyncLock);
|
||||
|
||||
@ -244,7 +245,7 @@ void MicLoadWav(const std::string& name)
|
||||
SDL_FreeWAV(buf);
|
||||
}
|
||||
|
||||
void MicProcess()
|
||||
void MicProcess(melonDS::NDS& nds)
|
||||
{
|
||||
int type = Config::MicInputType;
|
||||
bool cmd = Input::HotkeyDown(HK_Mic);
|
||||
@ -257,16 +258,16 @@ void MicProcess()
|
||||
switch (type)
|
||||
{
|
||||
case micInputType_Silence: // no mic
|
||||
Frontend::Mic_FeedSilence();
|
||||
Frontend::Mic_FeedSilence(nds);
|
||||
break;
|
||||
|
||||
case micInputType_External: // host mic
|
||||
case micInputType_Wav: // WAV
|
||||
Frontend::Mic_FeedExternalBuffer();
|
||||
Frontend::Mic_FeedExternalBuffer(nds);
|
||||
break;
|
||||
|
||||
case micInputType_Noise: // blowing noise
|
||||
Frontend::Mic_FeedNoise();
|
||||
Frontend::Mic_FeedNoise(nds);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -296,7 +297,7 @@ void SetupMicInputData()
|
||||
}
|
||||
}
|
||||
|
||||
void Init()
|
||||
void Init(EmuThread* thread)
|
||||
{
|
||||
audioMuted = false;
|
||||
audioSync = SDL_CreateCond();
|
||||
@ -310,6 +311,7 @@ void Init()
|
||||
whatIwant.channels = 2;
|
||||
whatIwant.samples = 1024;
|
||||
whatIwant.callback = AudioCallback;
|
||||
whatIwant.userdata = thread;
|
||||
audioDevice = SDL_OpenAudioDevice(NULL, 0, &whatIwant, &whatIget, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE);
|
||||
if (!audioDevice)
|
||||
{
|
||||
@ -349,12 +351,12 @@ void DeInit()
|
||||
micWavBuffer = nullptr;
|
||||
}
|
||||
|
||||
void AudioSync()
|
||||
void AudioSync(NDS& nds)
|
||||
{
|
||||
if (audioDevice)
|
||||
{
|
||||
SDL_LockMutex(audioSyncLock);
|
||||
while (NDS::SPU->GetOutputSize() > 1024)
|
||||
while (nds.SPU.GetOutputSize() > 1024)
|
||||
{
|
||||
int ret = SDL_CondWaitTimeout(audioSync, audioSyncLock, 500);
|
||||
if (ret == SDL_MUTEX_TIMEDOUT) break;
|
||||
@ -363,11 +365,11 @@ void AudioSync()
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateSettings()
|
||||
void UpdateSettings(NDS& nds)
|
||||
{
|
||||
MicClose();
|
||||
|
||||
NDS::SPU->SetInterpolation(Config::AudioInterp);
|
||||
nds.SPU.SetInterpolation(Config::AudioInterp);
|
||||
SetupMicInputData();
|
||||
|
||||
MicOpen();
|
||||
|
Reference in New Issue
Block a user