Add Controller::PlayAudio for Emulator

This commit is contained in:
scawful
2024-04-20 07:40:44 -04:00
parent 2de3b283cd
commit 7072c18a92
3 changed files with 16 additions and 1 deletions

View File

@@ -168,6 +168,15 @@ void Controller::OnInput() {
void Controller::OnLoad() { PRINT_IF_ERROR(master_editor_.Update()); }
void Controller::PlayAudio() {
if (master_editor_.emulator().running()) {
master_editor_.emulator().snes().SetSamples(audio_buffer_, wanted_samples_);
if (SDL_GetQueuedAudioSize(audio_device_) <= wanted_samples_ * 4 * 6) {
SDL_QueueAudio(audio_device_, audio_buffer_, wanted_samples_ * 4);
}
}
}
void Controller::DoRender() const {
ImGui::Render();
SDL_RenderClear(renderer_.get());

View File

@@ -34,6 +34,7 @@ class Controller : public ExperimentFlags {
absl::Status OnEntry();
void OnInput();
void OnLoad();
void PlayAudio();
void DoRender() const;
void OnExit();
@@ -61,7 +62,10 @@ class Controller : public ExperimentFlags {
friend int ::main(int argc, char **argv);
bool active_;
int wanted_samples_;
int16_t *audio_buffer_;
editor::MasterEditor master_editor_;
SDL_AudioDeviceID audio_device_;
std::shared_ptr<SDL_Window> window_;
std::shared_ptr<SDL_Renderer> renderer_;
};

View File

@@ -63,6 +63,8 @@ class MasterEditor : public SharedRom,
void Shutdown() { overworld_editor_.Shutdown(); }
auto emulator() -> emu::Emulator& { return emulator_; }
private:
void DrawFileDialog();
void DrawStatusPopup();
@@ -101,7 +103,7 @@ class MasterEditor : public SharedRom,
ScreenEditor screen_editor_;
SpriteEditor sprite_editor_;
Editor *current_editor_ = nullptr;
Editor* current_editor_ = nullptr;
};
} // namespace editor