Pushing audio samples through.

This commit is contained in:
Ben Vanik 2014-01-12 02:39:47 -08:00
parent dbf1aa182e
commit ecbd2c7e89
5 changed files with 36 additions and 15 deletions

View File

@ -22,7 +22,8 @@ using namespace xe::cpu;
AudioSystem::AudioSystem(Emulator* emulator) : AudioSystem::AudioSystem(Emulator* emulator) :
emulator_(emulator), memory_(emulator->memory()), emulator_(emulator), memory_(emulator->memory()),
thread_(0), running_(false), driver_(0) { thread_(0), running_(false), driver_(0),
client_({ 0 }) {
// Create the run loop used for any windows/etc. // Create the run loop used for any windows/etc.
// This must be done on the thread we create the driver. // This must be done on the thread we create the driver.
run_loop_ = xe_run_loop_create(); run_loop_ = xe_run_loop_create();
@ -86,16 +87,16 @@ void AudioSystem::ThreadStart() {
} }
// Pump worker. // Pump worker.
// mehhh
xe_mutex_lock(lock_); xe_mutex_lock(lock_);
auto clients = clients_; uint32_t client_callback = client_.callback;
uint32_t client_callback_arg = client_.wrapped_callback_arg;
xe_mutex_unlock(lock_); xe_mutex_unlock(lock_);
for (auto it = clients.begin(); it != clients.end(); ++it) { if (client_callback) {
processor->Execute( processor->Execute(
thread_state_, it->callback, it->wrapped_callback_arg, 0); thread_state_, client_callback, client_callback_arg, 0);
} else {
Sleep(500);
} }
//worker_->Pump();
Sleep(1000);
if (!running_) { if (!running_) {
break; break;
@ -127,11 +128,21 @@ void AudioSystem::Shutdown() {
void AudioSystem::RegisterClient( void AudioSystem::RegisterClient(
uint32_t callback, uint32_t callback_arg) { uint32_t callback, uint32_t callback_arg) {
// Only support one client for now.
XEASSERTZERO(client_.callback);
uint32_t ptr = (uint32_t)memory()->HeapAlloc(0, 0x4, 0); uint32_t ptr = (uint32_t)memory()->HeapAlloc(0, 0x4, 0);
auto mem = memory()->membase(); auto mem = memory()->membase();
XESETUINT32BE(mem + ptr, callback_arg); XESETUINT32BE(mem + ptr, callback_arg);
xe_mutex_lock(lock_); xe_mutex_lock(lock_);
clients_.push_back({ callback, callback_arg, ptr }); client_ = { callback, callback_arg, ptr };
xe_mutex_unlock(lock_);
}
void AudioSystem::UnregisterClient() {
xe_mutex_lock(lock_);
client_ = { 0 };
xe_mutex_unlock(lock_); xe_mutex_unlock(lock_);
} }

View File

@ -37,7 +37,8 @@ public:
virtual void Shutdown(); virtual void Shutdown();
void RegisterClient(uint32_t callback, uint32_t callback_arg); void RegisterClient(uint32_t callback, uint32_t callback_arg);
//void UnregisterClient(); void UnregisterClient();
virtual void SubmitFrame(uint32_t samples_ptr) = 0;
bool HandlesRegister(uint64_t addr); bool HandlesRegister(uint64_t addr);
virtual uint64_t ReadRegister(uint64_t addr); virtual uint64_t ReadRegister(uint64_t addr);
@ -76,14 +77,13 @@ protected:
cpu::XenonThreadState* thread_state_; cpu::XenonThreadState* thread_state_;
uint32_t thread_block_; uint32_t thread_block_;
bool running_; bool running_;
xe_mutex_t* lock_;
typedef struct { xe_mutex_t* lock_;
struct {
uint32_t callback; uint32_t callback;
uint32_t callback_arg; uint32_t callback_arg;
uint32_t wrapped_callback_arg; uint32_t wrapped_callback_arg;
} RenderDriverClient; } client_;
std::vector<RenderDriverClient> clients_;
AudioDriver* driver_; AudioDriver* driver_;
}; };

View File

@ -36,6 +36,10 @@ void NopAudioSystem::Pump() {
// //
} }
void NopAudioSystem::SubmitFrame(uint32_t samples_ptr) {
// Process samples! They are big-endian floats.
}
void NopAudioSystem::Shutdown() { void NopAudioSystem::Shutdown() {
AudioSystem::Shutdown(); AudioSystem::Shutdown();
} }

View File

@ -28,6 +28,8 @@ public:
virtual void Shutdown(); virtual void Shutdown();
virtual void SubmitFrame(uint32_t samples_ptr);
protected: protected:
virtual void Initialize(); virtual void Initialize();
virtual void Pump(); virtual void Pump();

View File

@ -111,8 +111,10 @@ SHIM_CALL XAudioUnregisterRenderDriverClient_shim(
"XAudioUnregisterRenderDriverClient(%.8X)", "XAudioUnregisterRenderDriverClient(%.8X)",
driver_ptr); driver_ptr);
XEASSERT(driver_ptr == 0xAADD1100);
auto audio_system = state->emulator()->audio_system(); auto audio_system = state->emulator()->audio_system();
//audio_system->UnregisterClient(...); audio_system->UnregisterClient();
SHIM_SET_RETURN(X_ERROR_SUCCESS); SHIM_SET_RETURN(X_ERROR_SUCCESS);
} }
@ -127,8 +129,10 @@ SHIM_CALL XAudioSubmitRenderDriverFrame_shim(
"XAudioSubmitRenderDriverFrame(%.8X, %.8X)", "XAudioSubmitRenderDriverFrame(%.8X, %.8X)",
driver_ptr, samples_ptr); driver_ptr, samples_ptr);
XEASSERT(driver_ptr == 0xAADD1100);
auto audio_system = state->emulator()->audio_system(); auto audio_system = state->emulator()->audio_system();
//audio_system->SubmitFrame(); audio_system->SubmitFrame(samples_ptr);
SHIM_SET_RETURN(X_ERROR_SUCCESS); SHIM_SET_RETURN(X_ERROR_SUCCESS);
} }