Skip to content

Commit

Permalink
Limit speed when no audio device is open. Fix #63
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Nov 10, 2024
1 parent 3efd2dc commit 2ce95b8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
10 changes: 10 additions & 0 deletions platforms/audio-shared/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/audio-shared/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
9 changes: 8 additions & 1 deletion platforms/desktop-shared/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,12 +774,19 @@ static void render(void)

static void frame_throttle(void)
{
if (emu_is_empty() || emu_is_paused() || config_emulator.ffwd)
if (emu_is_empty() || emu_is_paused() || !emu_is_audio_open() || config_emulator.ffwd)
{
float elapsed = (float)((frame_time_end - frame_time_start) * 1000) / SDL_GetPerformanceFrequency();

float min = 16.666f;

if (!emu_is_audio_open())
{
GC_RuntimeInfo runtime;
emu_get_runtime(runtime);
min = runtime.region == Region_NTSC ? 16.666f : 20.0f;
}

if (config_emulator.ffwd)
{
switch (config_emulator.ffwd_speed)
Expand Down
5 changes: 5 additions & 0 deletions platforms/desktop-shared/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ bool emu_is_audio_enabled(void)
return audio_enabled;
}

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

void emu_palette(GC_Color* palette)
{
gearcoleco->GetVideo()->SetCustomPalette(palette);
Expand Down
1 change: 1 addition & 0 deletions platforms/desktop-shared/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ EXTERN void emu_dissasemble_rom(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_palette(GC_Color* palette);
EXTERN void emu_predefined_palette(int palette);
EXTERN void emu_save_ram(const char* file_path);
Expand Down

0 comments on commit 2ce95b8

Please sign in to comment.