Unverified Commit d2e8fc04 authored by Libretro-Admin's avatar Libretro-Admin Committed by GitHub
Browse files

Merge pull request #279 from ds22x/master

Small upstream sync
parents 361f073b f39757b4
Pipeline #99655 passed with stages
in 39 minutes and 36 seconds
......@@ -8,11 +8,11 @@
path = win32/DirectXMath
url = https://github.com/Microsoft/DirectXMath
[submodule "shaders/SPIRV-Cross"]
path = shaders/SPIRV-Cross
path = external/SPIRV-Cross
url = https://github.com/KhronosGroup/SPIRV-Cross.git
[submodule "shaders/glslang"]
path = shaders/glslang
path = external/glslang
url = https://github.com/KhronosGroup/glslang.git
[submodule "vulkan/vulkan"]
path = vulkan/vulkan
path = external/vulkan-headers
url = https://github.com/KhronosGroup/Vulkan-Headers.git
......@@ -75,92 +75,92 @@ slang = get_option('slang')
if slang and opengl
glslang_args = ['-w', '-fno-exceptions', '-DNV_EXTENSIONS', '-DAMD_EXTENSIONS', '-DGLSLANG_OSINCLUDE_UNIX', '-DENABLE_OPT=0']
OSDependent_src = ['../shaders/glslang/glslang/OSDependent/Unix/ossource.cpp']
OSDependent_src = ['../external/glslang/glslang/OSDependent/Unix/ossource.cpp']
OSDependent_lib = static_library('OSDependent',
OSDependent_src,
include_directories: include_directories('../shaders/glslang'),
include_directories: include_directories('../external/glslang'),
cpp_args: glslang_args)
libs += OSDependent_lib
glslang_src = [
'../shaders/glslang/glslang/MachineIndependent/glslang_tab.cpp',
'../shaders/glslang/glslang/MachineIndependent/attribute.cpp',
'../shaders/glslang/glslang/MachineIndependent/Constant.cpp',
'../shaders/glslang/glslang/MachineIndependent/iomapper.cpp',
'../shaders/glslang/glslang/MachineIndependent/InfoSink.cpp',
'../shaders/glslang/glslang/MachineIndependent/Initialize.cpp',
'../shaders/glslang/glslang/MachineIndependent/IntermTraverse.cpp',
'../shaders/glslang/glslang/MachineIndependent/Intermediate.cpp',
'../shaders/glslang/glslang/MachineIndependent/ParseContextBase.cpp',
'../shaders/glslang/glslang/MachineIndependent/ParseHelper.cpp',
'../shaders/glslang/glslang/MachineIndependent/PoolAlloc.cpp',
'../shaders/glslang/glslang/MachineIndependent/RemoveTree.cpp',
'../shaders/glslang/glslang/MachineIndependent/Scan.cpp',
'../shaders/glslang/glslang/MachineIndependent/ShaderLang.cpp',
'../shaders/glslang/glslang/MachineIndependent/SymbolTable.cpp',
'../shaders/glslang/glslang/MachineIndependent/Versions.cpp',
'../shaders/glslang/glslang/MachineIndependent/intermOut.cpp',
'../shaders/glslang/glslang/MachineIndependent/limits.cpp',
'../shaders/glslang/glslang/MachineIndependent/linkValidate.cpp',
'../shaders/glslang/glslang/MachineIndependent/parseConst.cpp',
'../shaders/glslang/glslang/MachineIndependent/reflection.cpp',
'../shaders/glslang/glslang/MachineIndependent/preprocessor/Pp.cpp',
'../shaders/glslang/glslang/MachineIndependent/preprocessor/PpAtom.cpp',
'../shaders/glslang/glslang/MachineIndependent/preprocessor/PpContext.cpp',
'../shaders/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp',
'../shaders/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp',
'../shaders/glslang/glslang/MachineIndependent/propagateNoContraction.cpp',
'../shaders/glslang/glslang/GenericCodeGen/CodeGen.cpp',
'../shaders/glslang/glslang/GenericCodeGen/Link.cpp',
'../shaders/glslang/StandAlone/ResourceLimits.cpp'
'../external/glslang/glslang/MachineIndependent/glslang_tab.cpp',
'../external/glslang/glslang/MachineIndependent/attribute.cpp',
'../external/glslang/glslang/MachineIndependent/Constant.cpp',
'../external/glslang/glslang/MachineIndependent/iomapper.cpp',
'../external/glslang/glslang/MachineIndependent/InfoSink.cpp',
'../external/glslang/glslang/MachineIndependent/Initialize.cpp',
'../external/glslang/glslang/MachineIndependent/IntermTraverse.cpp',
'../external/glslang/glslang/MachineIndependent/Intermediate.cpp',
'../external/glslang/glslang/MachineIndependent/ParseContextBase.cpp',
'../external/glslang/glslang/MachineIndependent/ParseHelper.cpp',
'../external/glslang/glslang/MachineIndependent/PoolAlloc.cpp',
'../external/glslang/glslang/MachineIndependent/RemoveTree.cpp',
'../external/glslang/glslang/MachineIndependent/Scan.cpp',
'../external/glslang/glslang/MachineIndependent/ShaderLang.cpp',
'../external/glslang/glslang/MachineIndependent/SymbolTable.cpp',
'../external/glslang/glslang/MachineIndependent/Versions.cpp',
'../external/glslang/glslang/MachineIndependent/intermOut.cpp',
'../external/glslang/glslang/MachineIndependent/limits.cpp',
'../external/glslang/glslang/MachineIndependent/linkValidate.cpp',
'../external/glslang/glslang/MachineIndependent/parseConst.cpp',
'../external/glslang/glslang/MachineIndependent/reflection.cpp',
'../external/glslang/glslang/MachineIndependent/preprocessor/Pp.cpp',
'../external/glslang/glslang/MachineIndependent/preprocessor/PpAtom.cpp',
'../external/glslang/glslang/MachineIndependent/preprocessor/PpContext.cpp',
'../external/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp',
'../external/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp',
'../external/glslang/glslang/MachineIndependent/propagateNoContraction.cpp',
'../external/glslang/glslang/GenericCodeGen/CodeGen.cpp',
'../external/glslang/glslang/GenericCodeGen/Link.cpp',
'../external/glslang/StandAlone/ResourceLimits.cpp'
]
glslang_lib = static_library('glslang',
glslang_src,
include_directories: include_directories('../shaders/glslang'),
include_directories: include_directories('../external/glslang'),
cpp_args: glslang_args)
libs += glslang_lib
OGLCompilersDLL_src = ['../shaders/glslang/OGLCompilersDLL/InitializeDll.cpp']
OGLCompilersDLL_src = ['../external/glslang/OGLCompilersDLL/InitializeDll.cpp']
OGLCompilersDLL_lib = static_library('OGLCompilersDLL',
OGLCompilersDLL_src,
include_directories: include_directories('../shaders/glslang'),
include_directories: include_directories('../external/glslang'),
cpp_args: glslang_args)
libs += OGLCompilersDLL_lib
SPIRV_src = [
'../shaders/glslang/SPIRV/GlslangToSpv.cpp',
'../shaders/glslang/SPIRV/InReadableOrder.cpp',
'../shaders/glslang/SPIRV/Logger.cpp',
'../shaders/glslang/SPIRV/SpvBuilder.cpp',
'../shaders/glslang/SPIRV/SpvPostProcess.cpp',
'../shaders/glslang/SPIRV/SpvTools.cpp',
'../shaders/glslang/SPIRV/disassemble.cpp',
'../shaders/glslang/SPIRV/SPVRemapper.cpp',
'../shaders/glslang/SPIRV/doc.cpp'
'../external/glslang/SPIRV/GlslangToSpv.cpp',
'../external/glslang/SPIRV/InReadableOrder.cpp',
'../external/glslang/SPIRV/Logger.cpp',
'../external/glslang/SPIRV/SpvBuilder.cpp',
'../external/glslang/SPIRV/SpvPostProcess.cpp',
'../external/glslang/SPIRV/SpvTools.cpp',
'../external/glslang/SPIRV/disassemble.cpp',
'../external/glslang/SPIRV/SPVRemapper.cpp',
'../external/glslang/SPIRV/doc.cpp'
]
SPIRV_lib = static_library('SPIRV',
SPIRV_src,
include_directories: include_directories('../shaders/glslang'),
include_directories: include_directories('../external/glslang'),
cpp_args: glslang_args)
libs += SPIRV_lib
args += ['-DUSE_SLANG',
'-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS']
srcs += ['../shaders/slang.cpp']
srcs += ['../shaders/SPIRV-Cross/spirv_cfg.cpp',
'../shaders/SPIRV-Cross/spirv_cfg.hpp',
'../shaders/SPIRV-Cross/spirv_common.hpp',
'../shaders/SPIRV-Cross/spirv_cross.cpp',
'../shaders/SPIRV-Cross/spirv_cross.hpp',
'../shaders/SPIRV-Cross/spirv_glsl.cpp',
'../shaders/SPIRV-Cross/spirv_glsl.hpp',
'../shaders/SPIRV-Cross/spirv_cross_parsed_ir.cpp',
'../shaders/SPIRV-Cross/spirv_cross_parsed_ir.hpp',
'../shaders/SPIRV-Cross/spirv_parser.cpp',
'../shaders/SPIRV-Cross/spirv_parser.hpp',
'../shaders/SPIRV-Cross/spirv.hpp']
includes += '../shaders/glslang'
srcs += ['../external/SPIRV-Cross/spirv_cfg.cpp',
'../external/SPIRV-Cross/spirv_cfg.hpp',
'../external/SPIRV-Cross/spirv_common.hpp',
'../external/SPIRV-Cross/spirv_cross.cpp',
'../external/SPIRV-Cross/spirv_cross.hpp',
'../external/SPIRV-Cross/spirv_glsl.cpp',
'../external/SPIRV-Cross/spirv_glsl.hpp',
'../external/SPIRV-Cross/spirv_cross_parsed_ir.cpp',
'../external/SPIRV-Cross/spirv_cross_parsed_ir.hpp',
'../external/SPIRV-Cross/spirv_parser.cpp',
'../external/SPIRV-Cross/spirv_parser.hpp',
'../external/SPIRV-Cross/spirv.hpp']
includes += '../external/glslang'
endif
wayland = get_option('wayland')
......
......@@ -13,16 +13,10 @@
#include <sys/ioctl.h>
#include <sys/time.h>
static void alsa_samples_available(void *data)
{
((S9xAlsaSoundDriver *)data)->samples_available();
}
S9xAlsaSoundDriver::S9xAlsaSoundDriver()
{
pcm = NULL;
sound_buffer = NULL;
sound_buffer_size = 0;
pcm = {};
sound_buffer.clear();
}
void S9xAlsaSoundDriver::init()
......@@ -33,20 +27,16 @@ void S9xAlsaSoundDriver::terminate()
{
stop();
S9xSetSamplesAvailableCallback(NULL, NULL);
S9xSetSamplesAvailableCallback(nullptr, nullptr);
if (pcm)
{
snd_pcm_drain(pcm);
snd_pcm_close(pcm);
pcm = NULL;
pcm = nullptr;
}
if (sound_buffer)
{
free(sound_buffer);
sound_buffer = NULL;
}
sound_buffer.clear();
}
void S9xAlsaSoundDriver::start()
......@@ -71,10 +61,7 @@ bool S9xAlsaSoundDriver::open_device()
printf("ALSA sound driver initializing...\n");
printf(" --> (Device: default)...\n");
err = snd_pcm_open(&pcm,
"default",
SND_PCM_STREAM_PLAYBACK,
SND_PCM_NONBLOCK);
err = snd_pcm_open(&pcm, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if (err < 0)
{
......@@ -92,34 +79,34 @@ bool S9xAlsaSoundDriver::open_device()
snd_pcm_hw_params_set_rate_resample(pcm, hw_params, 0);
snd_pcm_hw_params_set_channels(pcm, hw_params, 2);
snd_pcm_hw_params_get_rate_min(hw_params, &min, NULL);
snd_pcm_hw_params_get_rate_max(hw_params, &max, NULL);
snd_pcm_hw_params_get_rate_min(hw_params, &min, nullptr);
snd_pcm_hw_params_get_rate_max(hw_params, &max, nullptr);
printf(" --> Available rates: %d to %d\n", min, max);
if (Settings.SoundPlaybackRate > max && Settings.SoundPlaybackRate < min)
{
printf(" Rate %d not available. Using %d instead.\n", Settings.SoundPlaybackRate, max);
Settings.SoundPlaybackRate = max;
}
snd_pcm_hw_params_set_rate_near(pcm, hw_params, &Settings.SoundPlaybackRate, NULL);
snd_pcm_hw_params_set_rate_near(pcm, hw_params, &Settings.SoundPlaybackRate, nullptr);
snd_pcm_hw_params_get_buffer_time_min(hw_params, &min, NULL);
snd_pcm_hw_params_get_buffer_time_max(hw_params, &max, NULL);
snd_pcm_hw_params_get_buffer_time_min(hw_params, &min, nullptr);
snd_pcm_hw_params_get_buffer_time_max(hw_params, &max, nullptr);
printf(" --> Available buffer sizes: %dms to %dms\n", min / 1000, max / 1000);
if (buffer_size < min && buffer_size > max)
{
printf(" Buffer size %dms not available. Using %d instead.\n", buffer_size / 1000, (min + max) / 2000);
buffer_size = (min + max) / 2;
}
snd_pcm_hw_params_set_buffer_time_near(pcm, hw_params, &buffer_size, NULL);
snd_pcm_hw_params_set_buffer_time_near(pcm, hw_params, &buffer_size, nullptr);
snd_pcm_hw_params_get_periods_min(hw_params, &min, NULL);
snd_pcm_hw_params_get_periods_max(hw_params, &max, NULL);
snd_pcm_hw_params_get_periods_min(hw_params, &min, nullptr);
snd_pcm_hw_params_get_periods_max(hw_params, &max, nullptr);
printf(" --> Period ranges: %d to %d blocks\n", min, max);
if (periods > max)
{
periods = max;
}
snd_pcm_hw_params_set_periods_near(pcm, hw_params, &periods, NULL);
snd_pcm_hw_params_set_periods_near(pcm, hw_params, &periods, nullptr);
if ((err = snd_pcm_hw_params(pcm, hw_params)) < 0)
{
......@@ -144,14 +131,16 @@ bool S9xAlsaSoundDriver::open_device()
printf("OK\n");
S9xSetSamplesAvailableCallback(alsa_samples_available, this);
S9xSetSamplesAvailableCallback([](void *userdata) {
((decltype(this)) userdata)->samples_available();;
}, this);
return true;
close_fail:
snd_pcm_drain(pcm);
snd_pcm_close(pcm);
pcm = NULL;
pcm = nullptr;
fail:
printf("Failed: %s\n", snd_strerror(err));
......@@ -162,7 +151,7 @@ fail:
void S9xAlsaSoundDriver::samples_available()
{
snd_pcm_sframes_t frames_written, frames;
int bytes;
size_t bytes;
frames = snd_pcm_avail(pcm);
......@@ -206,13 +195,10 @@ void S9xAlsaSoundDriver::samples_available()
if (bytes <= 0)
return;
if (sound_buffer_size < bytes || sound_buffer == NULL)
{
sound_buffer = (uint8 *)realloc(sound_buffer, bytes);
sound_buffer_size = bytes;
}
if (sound_buffer.size() < bytes)
sound_buffer.resize(bytes);
S9xMixSamples(sound_buffer, frames * 2);
S9xMixSamples(sound_buffer.data(), frames * 2);
frames_written = 0;
......@@ -221,8 +207,7 @@ void S9xAlsaSoundDriver::samples_available()
int result;
result = snd_pcm_writei(pcm,
sound_buffer +
snd_pcm_frames_to_bytes(pcm, frames_written),
&sound_buffer[snd_pcm_frames_to_bytes(pcm, frames_written)],
frames - frames_written);
if (result < 0)
......
......@@ -24,8 +24,7 @@ class S9xAlsaSoundDriver : public S9xSoundDriver
private:
snd_pcm_t *pcm;
int sound_buffer_size;
uint8 *sound_buffer;
std::vector<uint8_t> sound_buffer;
int output_buffer_size;
};
......
......@@ -13,26 +13,22 @@
#include <sys/ioctl.h>
#include <sys/time.h>
static void pulse_samples_available(void *data)
{
((S9xPulseSoundDriver *)data)->samples_available();
}
S9xPulseSoundDriver::S9xPulseSoundDriver()
{
mainloop = NULL;
context = NULL;
stream = NULL;
buffer_size = 0;
init();
}
void S9xPulseSoundDriver::init()
{
mainloop = {};
context = {};
stream = {};
buffer_size = {};
}
void S9xPulseSoundDriver::terminate()
{
S9xSetSamplesAvailableCallback(NULL, NULL);
S9xSetSamplesAvailableCallback(nullptr, nullptr);
if (mainloop)
pa_threaded_mainloop_stop(mainloop);
......@@ -110,15 +106,14 @@ static void stream_state_callback(pa_stream *p, void *userdata)
bool S9xPulseSoundDriver::open_device()
{
int err = PA_ERR_UNKNOWN;
pa_sample_spec ss;
pa_buffer_attr buffer_attr;
const pa_buffer_attr *actual_buffer_attr;
init();
pa_sample_spec ss;
ss.channels = 2;
ss.format = PA_SAMPLE_S16NE;
ss.rate = Settings.SoundPlaybackRate;
pa_buffer_attr buffer_attr;
buffer_attr.fragsize = -1;
buffer_attr.tlength = pa_usec_to_bytes(gui_config->sound_buffer_size * 1000, &ss);
buffer_attr.maxlength = buffer_attr.tlength * 2;
......@@ -130,93 +125,59 @@ bool S9xPulseSoundDriver::open_device()
printf(" --> (%dhz, 16-bit Stereo, %dms)...",
Settings.SoundPlaybackRate,
gui_config->sound_buffer_size);
fflush(stdout);
int err = PA_ERR_UNKNOWN;
mainloop = pa_threaded_mainloop_new();
if (!mainloop)
{
fprintf(stderr, "Failed to create mainloop.\n");
goto error0;
}
context = pa_context_new(pa_threaded_mainloop_get_api(mainloop), "Snes9x");
if (!context)
goto error1;
pa_context_set_state_callback(context, context_state_cb, this);
if ((err = pa_context_connect(context, NULL, PA_CONTEXT_NOFLAGS, NULL)) != 0)
goto error2;
pa_context_connect(context, nullptr, PA_CONTEXT_NOFLAGS, nullptr);
lock();
if ((err = pa_threaded_mainloop_start(mainloop)) != 0)
goto error2;
pa_threaded_mainloop_start(mainloop);
wait();
if ((err = pa_context_get_state(context)) != PA_CONTEXT_READY)
{
printf("Coundn't create context: State: %d\n", err);
goto error2;
}
return false;
stream = pa_stream_new(context, "Game", &ss, NULL);
if (!stream)
goto error2;
stream = pa_stream_new(context, "Game", &ss, nullptr);
pa_stream_set_state_callback(stream, stream_state_callback, this);
if (pa_stream_connect_playback(stream,
NULL,
nullptr,
&buffer_attr,
PA_STREAM_ADJUST_LATENCY,
NULL,
NULL) < 0)
goto error3;
nullptr,
nullptr) < 0)
{
return false;
}
wait();
if (pa_stream_get_state(stream) != PA_STREAM_READY)
{
goto error3;
}
return false;
actual_buffer_attr = pa_stream_get_buffer_attr(stream);
auto actual_buffer_attr = pa_stream_get_buffer_attr(stream);
unlock();
buffer_size = actual_buffer_attr->tlength;
printf("OK\n");
S9xSetSamplesAvailableCallback(pulse_samples_available, this);
S9xSetSamplesAvailableCallback([](void *userdata) {
((decltype(this)) userdata)->samples_available();;
}, this);
unlock();
return true;
error3:
pa_stream_disconnect(stream);
pa_stream_unref(stream);
error2:
pa_context_disconnect(context);
pa_context_unref(context);
unlock();
error1:
pa_threaded_mainloop_free(mainloop);
error0:
printf("Failed: %s\n", pa_strerror(err));
return false;
}
void S9xPulseSoundDriver::samples_available()
{
size_t bytes;
int samples;
const pa_buffer_attr *buffer_attr;
void *output_buffer = NULL;
lock();
bytes = pa_stream_writable_size(stream);
buffer_attr = pa_stream_get_buffer_attr(stream);
size_t bytes = pa_stream_writable_size(stream);
auto buffer_attr = pa_stream_get_buffer_attr(stream);
unlock();
buffer_size = buffer_attr->tlength;
......@@ -226,22 +187,22 @@ void S9xPulseSoundDriver::samples_available()
S9xUpdateDynamicRate(bytes, buffer_size);
}
samples = S9xGetSampleCount();
size_t samples = S9xGetSampleCount();
if (Settings.DynamicRateControl && !Settings.SoundSync)
int frames_available = samples / 2;
int frames_writable = bytes / 4;
if (frames_writable < frames_available)
{
if ((int)bytes < (samples * 2))
if (Settings.DynamicRateControl && !Settings.SoundSync)
{
S9xClearSamples();
return;
}
}
if (Settings.SoundSync && !Settings.TurboMode && !Settings.Mute)
{
if ((int)bytes < samples * 2)
if (Settings.SoundSync && !Settings.TurboMode && !Settings.Mute)
{
int usec_to_sleep = ((samples >> 1) - (bytes >> 2)) * 10000 /
int usec_to_sleep = (frames_available - frames_writable) * 10000 /
(Settings.SoundPlaybackRate / 100);
usleep(usec_to_sleep > 0 ? usec_to_sleep : 0);
lock();
......@@ -250,16 +211,17 @@ void S9xPulseSoundDriver::samples_available()
}
}
bytes = MIN((int)bytes, samples * 2) & ~1;
bytes = MIN(bytes, samples * 2) & ~1;
if (!bytes)
return;
lock();
void *output_buffer;;
if (pa_stream_begin_write(stream, &output_buffer, &bytes) != 0)
{
pa_stream_flush(stream, NULL, NULL);
pa_stream_flush(stream, nullptr, nullptr);
unlock();
return;
}
......@@ -270,8 +232,8 @@ void S9xPulseSoundDriver::samples_available()
return;
}
S9xMixSamples((uint8 *)output_buffer, bytes >> 1);
pa_stream_write(stream, output_buffer, bytes, NULL, 0, PA_SEEK_RELATIVE);
S9xMixSamples((uint8_t *)output_buffer, bytes >> 1);
pa_stream_write(stream, output_buffer, bytes, nullptr, 0, PA_SEEK_RELATIVE);
unlock();
}
......@@ -9,16 +9,6 @@
#include "apu/apu.h"
#include "snes9x.h"
static void sdl_audio_callback(void *userdata, Uint8 *stream, int len)
{
((S9xSDLSoundDriver *)userdata)->mix((unsigned char *)stream, len);
}
static void c_samples_available(void *data)
{
((S9xSDLSoundDriver *)data)->samples_available();
}
void S9xSDLSoundDriver::samples_available()
{
int snes_samples_available = S9xGetSampleCount();
......@@ -89,7 +79,10 @@ bool S9xSDLSoundDriver::open_device()
audiospec.channels = 2;
audiospec.format = AUDIO_S16SYS;
audiospec.samples = (gui_config->sound_buffer_size * audiospec.freq / 1000) >> 2;
audiospec.callback = sdl_audio_callback;
audiospec.callback = [](void *userdata, uint8_t *stream, int len) {
((S9xSDLSoundDriver *)userdata)->mix((unsigned char *)stream, len);
};
audiospec.userdata = this;
printf("SDL sound driver initializing...\n");
......@@ -106,9 +99,10 @@ bool S9xSDLSoundDriver::open_device()
printf("OK\n");
buffer.resize(gui_config->sound_buffer_size * audiospec.freq / 500);
buffer.time_ratio(1.0);
S9xSetSamplesAvailableCallback(c_samples_available, this);
S9xSetSamplesAvailableCallback([](void *userdata) {
((decltype(this)) userdata)->samples_available();;
}, this);
return true;
}
......@@ -16,6 +16,8 @@
#include "conffile.h"
#include "crosshairs.h"
#include <stdio.h>
#include <vector>
#ifdef _WIN32
#include <direct.h>
#else
......@@ -793,28 +795,6 @@ static void update_variables(void)
}
}
static void S9xAudioCallback(void*)
{
const int BUFFER_SIZE = 256;
// 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];