Skip to content

Commit

Permalink
Limit speed when no audio device is open
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Nov 9, 2024
1 parent f4bd771 commit 46843b4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions platforms/shared/audio/sound_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ int SoundQueue::GetSampleCount()
return m_buffer_size * m_buffer_count - buffer_free;
}

int16_t* SoundQueue::GetCurrentlyPlaying()
{
return m_currently_playing;
}

bool SoundQueue::IsOpen()
{
return m_sound_open;
}

void SoundQueue::Write(int16_t* samples, int count, bool sync)
{
if (!m_sound_open)
Expand Down
1 change: 1 addition & 0 deletions platforms/shared/audio/sound_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class SoundQueue
void Write(int16_t* samples, int count, bool sync);
int GetSampleCount();
int16_t* GetCurrentlyPlaying();
bool IsOpen();

private:
int16_t* volatile m_buffers;
Expand Down
2 changes: 1 addition & 1 deletion platforms/shared/desktop/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ static void render(void)

static void frame_throttle(void)
{
if (emu_is_empty() || emu_is_paused() || emu_is_debug_idle() || config_emulator.ffwd)
if (emu_is_empty() || emu_is_paused() || emu_is_debug_idle() || !emu_is_audio_open() || config_emulator.ffwd)
{
Uint64 count_per_sec = SDL_GetPerformanceFrequency();
float elapsed = (float)(frame_time_end - frame_time_start) / (float)count_per_sec;
Expand Down
5 changes: 5 additions & 0 deletions platforms/shared/desktop/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ bool emu_is_audio_enabled(void)
return audio_enabled;
}

bool emu_is_audio_open(void)
{
return sound_queue->IsOpen();
}

void emu_save_ram(const char* file_path)
{
// TODO
Expand Down
1 change: 1 addition & 0 deletions platforms/shared/desktop/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ EXTERN void emu_reset(void);
EXTERN void emu_audio_mute(bool mute);
EXTERN void emu_audio_reset(void);
EXTERN bool emu_is_audio_enabled(void);
EXTERN bool emu_is_audio_open(void);
EXTERN void emu_save_ram(const char* file_path);
EXTERN void emu_load_ram(const char* file_path);
EXTERN void emu_save_state_slot(int index);
Expand Down

0 comments on commit 46843b4

Please sign in to comment.