Skip to content

Commit

Permalink
common: improve audio handling
Browse files Browse the repository at this point in the history
psnes: add AUDIO_SYNC option (on: perfect audio, off: minor audio stuttering in favor of fps)
  • Loading branch information
Cpasjuste committed May 11, 2022
1 parent acb9224 commit a31e1c2
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 187 deletions.
2 changes: 1 addition & 1 deletion pfbneo/sources/fbneo/retro_input_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void poll_cb();

#define RETRO_GAME_TYPE_NEOCD 13
#define HARDWARE_SEGA_SYSTEM32 (HARDWARE_PREFIX_SEGA | 0x000c0000)
#define HARDWARE_NVS (HARDWARE_PREFIX_NES | 0x00010000)
//#define HARDWARE_NVS (HARDWARE_PREFIX_NES | 0x00010000)

#define RETRO_DEVICE_TYPE_SHIFT 8
#define RETRO_DEVICE_MASK ((1 << RETRO_DEVICE_TYPE_SHIFT) - 1)
Expand Down
18 changes: 13 additions & 5 deletions pfbneo/sources/uiEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,8 @@ int PFBAUiEmu::load(const ss_api::Game &game) {
pBurnSoundOut = (INT16 *) malloc(audio->getSamplesSize());
}
audio_sync = !bForce60Hz;
targetFps = (float) nBurnFPS / 100;
printf("PFBAUiEmu::load: FORCE_60HZ: %i, AUDIO_SYNC: %i, FPS: %f (BURNFPS: %f)\n",
bForce60Hz, audio_sync, (float) nBurnFPS / 100.0f, targetFps);
targetFps = (float) nBurnFPS / 100.0f;
printf("PFBAUiEmu::load: FORCE_60HZ: %i, AUDIO_SYNC: %i, FPS: %f\n", bForce60Hz, audio_sync, targetFps);
///////////
// AUDIO
//////////
Expand Down Expand Up @@ -375,8 +374,17 @@ void PFBAUiEmu::onUpdate() {
frameskip = 0;
}

if (audio && audio->isAvailable()) {
audio->play(pBurnSoundOut, audio->getSamples(), audio_sync);
if (audio) {
#if 0
int queued = audio->getSampleBufferQueued();
int capacity = audio->getSampleBufferCapacity();
if (audio->getSamples() + queued > capacity) {
printf("WARNING: samples: %i, queued: %i, capacity: %i (fps: %f)\n",
audio->getSamples(), queued, capacity, targetFps);
}
#endif
audio->play(pBurnSoundOut, audio->getSamples(),
audio_sync ? Audio::SyncMode::LowLatency : Audio::SyncMode::None);
}

UiEmu::onUpdate();
Expand Down
14 changes: 11 additions & 3 deletions pgen/sources/pgen_ui_emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ int PGENUiEmu::load(const ss_api::Game &game) {

// audio init
targetFps = vdp_pal ? 50 : 60;
int samples = 48000 / (int) targetFps;
addAudio(48000, samples);
addAudio(48000, vdp_pal ? 966 : 801);

getUi()->getUiProgressBox()->setProgress(1);
getUi()->flip();
Expand Down Expand Up @@ -166,7 +165,16 @@ void PGENUiEmu::onUpdate() {

// audio
int samples = audio_update(sound_buffer);
getAudio()->play(sound_buffer, samples, vdp_pal);
#if 0
int queued = audio->getSampleBufferQueued();
int capacity = audio->getSampleBufferCapacity();
if (samples + queued > capacity) {
printf("WARNING: samples: %i, queued: %i, capacity: %i (fps: %i)\n",
samples, queued, capacity, vdp_pal ? 50 : 60);
}
#endif
getAudio()->play(sound_buffer, samples,
vdp_pal ? Audio::SyncMode::Safe : Audio::SyncMode::None);
}

return UiEmu::onUpdate();
Expand Down
17 changes: 11 additions & 6 deletions pnes/sources/uiEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,19 @@ void audio_deinit() {
}

void audio_queue() {
if (uiEmu->getAudio()) {
Audio *audio = uiEmu->getAudio();
if (audio) {
#if 0
printf("play: samples: %i, queued: %i, capacity: %i\n",
uiEmu->getAudio()->getSamples(),
uiEmu->getAudio()->getSampleBufferQueued(),
uiEmu->getAudio()->getSampleBufferCapacity());
int samples = uiEmu->getAudio()->getSamples();
int queued = audio->getSampleBufferQueued();
int capacity = audio->getSampleBufferCapacity();
if (samples + queued > capacity) {
printf("WARNING: samples: %i, queued: %i, capacity: %i (fps: %i)\n",
samples, queued, capacity, nst_pal() ? 50 : 60);
}
#endif
uiEmu->getAudio()->play(audio_buffer, uiEmu->getAudio()->getSamples(), nst_pal());
uiEmu->getAudio()->play(audio_buffer, uiEmu->getAudio()->getSamples(),
nst_pal() ? Audio::SyncMode::LowLatency : Audio::SyncMode::None);
}
}

Expand Down
7 changes: 5 additions & 2 deletions psnes/sources/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ using namespace c2d;
using namespace c2dui;

PSNESConfig::PSNESConfig(c2d::Io *io, int version) : Config(io, version) {

printf("PSNESConfig(%s, v%i)\n", getConfigPath().c_str(), version);

add(Option::Id::ROM_SHOW_FPS, "CHEATS", {"OFF", "ON"}, 1,
add(Option::Id::ROM_SHOW_FPS, "AUDIO_SYNC", {"OFF", "ON"}, 0,
Option::Id::ROM_AUDIO_SYNC, Option::Flags::BOOLEAN);
get(Option::Id::ROM_AUDIO_SYNC)->setInfo("ON: PERFECT AUDIO - OFF: MINOR AUDIO STUTTERING (FAVOR FPS)");

add(Option::Id::ROM_AUDIO_SYNC, "CHEATS", {"OFF", "ON"}, 1,
Option::Id::ROM_PSNES_CHEATS, Option::Flags::BOOLEAN);

add(Option::Id::ROM_PSNES_CHEATS, "BLOCk_INVALID_VRAM", {"OFF", "ON"}, 1,
Expand Down
Loading

0 comments on commit a31e1c2

Please sign in to comment.