libretro: Sound buffering change.

This commit is contained in:
BearOso 2022-03-21 14:52:49 -05:00
parent 93d538dfaf
commit 2262544c4e
1 changed files with 9 additions and 14 deletions

View File

@ -16,6 +16,8 @@
#include "conffile.h" #include "conffile.h"
#include "crosshairs.h" #include "crosshairs.h"
#include <stdio.h> #include <stdio.h>
#include <vector>
#ifdef _WIN32 #ifdef _WIN32
#include <direct.h> #include <direct.h>
#else #else
@ -753,23 +755,16 @@ static void update_variables(void)
static void S9xAudioCallback(void*) static void S9xAudioCallback(void*)
{ {
const int BUFFER_SIZE = 256; static std::vector<int16_t> audio_buffer;
// This is called every time 128 to 132 samples are generated, which happens about 8 times per frame. A buffer size of 256 samples is enough here.
static int16_t audio_buf[BUFFER_SIZE];
size_t avail = S9xGetSampleCount(); size_t avail = S9xGetSampleCount();
while (avail >= BUFFER_SIZE) if (avail > 256)
{ {
//this loop will never be entered, but handle oversized sample counts just in case if (audio_buffer.size() < avail)
S9xMixSamples((uint8*)audio_buf, BUFFER_SIZE); audio_buffer.resize(avail);
audio_batch_cb(audio_buf, BUFFER_SIZE >> 1);
avail -= BUFFER_SIZE; S9xMixSamples((uint8*)&audio_buffer[0], avail);
} audio_batch_cb(&audio_buffer[0], avail >> 1);
if (avail > 0)
{
S9xMixSamples((uint8*)audio_buf, avail);
audio_batch_cb(audio_buf, avail >> 1);
} }
} }
@ -1370,7 +1365,7 @@ void retro_init(void)
exit(1); exit(1);
} }
S9xInitSound(0); S9xInitSound(32);
S9xSetSoundMute(FALSE); S9xSetSoundMute(FALSE);
S9xSetSamplesAvailableCallback(S9xAudioCallback, NULL); S9xSetSamplesAvailableCallback(S9xAudioCallback, NULL);