3939
4040 - on macOS: AudioToolbox
4141 - on iOS: AudioToolbox, AVFoundation
42+ - on FreeBSD: asound
4243 - on Linux: asound
4344 - on Android: link with OpenSLES or aaudio
4445 - on Windows with MSVC or Clang toolchain: no action needed, libs are defined in-source via pragma-comment-lib
5152
5253 - Windows: WASAPI
5354 - Linux: ALSA
55+ - FreeBSD: ALSA
5456 - macOS: CoreAudio
5557 - iOS: CoreAudio+AVAudioSession
5658 - emscripten: WebAudio with ScriptProcessorNode
@@ -780,13 +782,9 @@ inline void saudio_setup(const saudio_desc& desc) { return saudio_setup(&desc);
780782 #include "aaudio/AAudio.h"
781783 #endif
782784#elif defined(_SAUDIO_LINUX )
783- // __v_ start
784- #if !defined(__FreeBSD__ )
785- // __v_ end
786- #include <alloca.h>
787- // __v_ start
788- #endif
789- // __v_ end
785+ #if !defined(__FreeBSD__ )
786+ #include <alloca.h>
787+ #endif
790788 #define _SAUDIO_PTHREADS (1)
791789 #include <pthread.h>
792790 #define ALSA_PCM_NEW_HW_PARAMS_API
@@ -1069,6 +1067,7 @@ typedef struct {
10691067/* sokol-audio state */
10701068typedef struct {
10711069 bool valid ;
1070+ bool setup_called ;
10721071 void (* stream_cb )(float * buffer , int num_frames , int num_channels );
10731072 void (* stream_userdata_cb )(float * buffer , int num_frames , int num_channels , void * user_data );
10741073 void * user_data ;
@@ -2488,9 +2487,11 @@ void _saudio_backend_shutdown(void) {
24882487// >>public
24892488SOKOL_API_IMPL void saudio_setup (const saudio_desc * desc ) {
24902489 SOKOL_ASSERT (!_saudio .valid );
2490+ SOKOL_ASSERT (!_saudio .setup_called );
24912491 SOKOL_ASSERT (desc );
24922492 SOKOL_ASSERT ((desc -> allocator .alloc_fn && desc -> allocator .free_fn ) || (!desc -> allocator .alloc_fn && !desc -> allocator .free_fn ));
24932493 _saudio_clear (& _saudio , sizeof (_saudio ));
2494+ _saudio .setup_called = true;
24942495 _saudio .desc = * desc ;
24952496 _saudio .stream_cb = desc -> stream_cb ;
24962497 _saudio .stream_userdata_cb = desc -> stream_userdata_cb ;
@@ -2521,6 +2522,8 @@ SOKOL_API_IMPL void saudio_setup(const saudio_desc* desc) {
25212522}
25222523
25232524SOKOL_API_IMPL void saudio_shutdown (void ) {
2525+ SOKOL_ASSERT (_saudio .setup_called );
2526+ _saudio .setup_called = false;
25242527 if (_saudio .valid ) {
25252528 _saudio_backend_shutdown ();
25262529 _saudio_fifo_shutdown (& _saudio .fifo );
@@ -2534,26 +2537,32 @@ SOKOL_API_IMPL bool saudio_isvalid(void) {
25342537}
25352538
25362539SOKOL_API_IMPL void * saudio_userdata (void ) {
2540+ SOKOL_ASSERT (_saudio .setup_called );
25372541 return _saudio .desc .user_data ;
25382542}
25392543
25402544SOKOL_API_IMPL saudio_desc saudio_query_desc (void ) {
2545+ SOKOL_ASSERT (_saudio .setup_called );
25412546 return _saudio .desc ;
25422547}
25432548
25442549SOKOL_API_IMPL int saudio_sample_rate (void ) {
2550+ SOKOL_ASSERT (_saudio .setup_called );
25452551 return _saudio .sample_rate ;
25462552}
25472553
25482554SOKOL_API_IMPL int saudio_buffer_frames (void ) {
2555+ SOKOL_ASSERT (_saudio .setup_called );
25492556 return _saudio .buffer_frames ;
25502557}
25512558
25522559SOKOL_API_IMPL int saudio_channels (void ) {
2560+ SOKOL_ASSERT (_saudio .setup_called );
25532561 return _saudio .num_channels ;
25542562}
25552563
25562564SOKOL_API_IMPL bool saudio_suspended (void ) {
2565+ SOKOL_ASSERT (_saudio .setup_called );
25572566 #if defined(_SAUDIO_EMSCRIPTEN )
25582567 if (_saudio .valid ) {
25592568 return 1 == saudio_js_suspended ();
@@ -2567,6 +2576,7 @@ SOKOL_API_IMPL bool saudio_suspended(void) {
25672576}
25682577
25692578SOKOL_API_IMPL int saudio_expect (void ) {
2579+ SOKOL_ASSERT (_saudio .setup_called );
25702580 if (_saudio .valid ) {
25712581 const int num_frames = _saudio_fifo_writable_bytes (& _saudio .fifo ) / _saudio .bytes_per_frame ;
25722582 return num_frames ;
@@ -2577,6 +2587,7 @@ SOKOL_API_IMPL int saudio_expect(void) {
25772587}
25782588
25792589SOKOL_API_IMPL int saudio_push (const float * frames , int num_frames ) {
2590+ SOKOL_ASSERT (_saudio .setup_called );
25802591 SOKOL_ASSERT (frames && (num_frames > 0 ));
25812592 if (_saudio .valid ) {
25822593 const int num_bytes = num_frames * _saudio .bytes_per_frame ;
0 commit comments