39
39
40
40
- on macOS: AudioToolbox
41
41
- on iOS: AudioToolbox, AVFoundation
42
+ - on FreeBSD: asound
42
43
- on Linux: asound
43
44
- on Android: link with OpenSLES or aaudio
44
45
- on Windows with MSVC or Clang toolchain: no action needed, libs are defined in-source via pragma-comment-lib
51
52
52
53
- Windows: WASAPI
53
54
- Linux: ALSA
55
+ - FreeBSD: ALSA
54
56
- macOS: CoreAudio
55
57
- iOS: CoreAudio+AVAudioSession
56
58
- emscripten: WebAudio with ScriptProcessorNode
@@ -780,13 +782,9 @@ inline void saudio_setup(const saudio_desc& desc) { return saudio_setup(&desc);
780
782
#include "aaudio/AAudio.h"
781
783
#endif
782
784
#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
790
788
#define _SAUDIO_PTHREADS (1)
791
789
#include <pthread.h>
792
790
#define ALSA_PCM_NEW_HW_PARAMS_API
@@ -1069,6 +1067,7 @@ typedef struct {
1069
1067
/* sokol-audio state */
1070
1068
typedef struct {
1071
1069
bool valid ;
1070
+ bool setup_called ;
1072
1071
void (* stream_cb )(float * buffer , int num_frames , int num_channels );
1073
1072
void (* stream_userdata_cb )(float * buffer , int num_frames , int num_channels , void * user_data );
1074
1073
void * user_data ;
@@ -2488,9 +2487,11 @@ void _saudio_backend_shutdown(void) {
2488
2487
// >>public
2489
2488
SOKOL_API_IMPL void saudio_setup (const saudio_desc * desc ) {
2490
2489
SOKOL_ASSERT (!_saudio .valid );
2490
+ SOKOL_ASSERT (!_saudio .setup_called );
2491
2491
SOKOL_ASSERT (desc );
2492
2492
SOKOL_ASSERT ((desc -> allocator .alloc_fn && desc -> allocator .free_fn ) || (!desc -> allocator .alloc_fn && !desc -> allocator .free_fn ));
2493
2493
_saudio_clear (& _saudio , sizeof (_saudio ));
2494
+ _saudio .setup_called = true;
2494
2495
_saudio .desc = * desc ;
2495
2496
_saudio .stream_cb = desc -> stream_cb ;
2496
2497
_saudio .stream_userdata_cb = desc -> stream_userdata_cb ;
@@ -2521,6 +2522,8 @@ SOKOL_API_IMPL void saudio_setup(const saudio_desc* desc) {
2521
2522
}
2522
2523
2523
2524
SOKOL_API_IMPL void saudio_shutdown (void ) {
2525
+ SOKOL_ASSERT (_saudio .setup_called );
2526
+ _saudio .setup_called = false;
2524
2527
if (_saudio .valid ) {
2525
2528
_saudio_backend_shutdown ();
2526
2529
_saudio_fifo_shutdown (& _saudio .fifo );
@@ -2534,26 +2537,32 @@ SOKOL_API_IMPL bool saudio_isvalid(void) {
2534
2537
}
2535
2538
2536
2539
SOKOL_API_IMPL void * saudio_userdata (void ) {
2540
+ SOKOL_ASSERT (_saudio .setup_called );
2537
2541
return _saudio .desc .user_data ;
2538
2542
}
2539
2543
2540
2544
SOKOL_API_IMPL saudio_desc saudio_query_desc (void ) {
2545
+ SOKOL_ASSERT (_saudio .setup_called );
2541
2546
return _saudio .desc ;
2542
2547
}
2543
2548
2544
2549
SOKOL_API_IMPL int saudio_sample_rate (void ) {
2550
+ SOKOL_ASSERT (_saudio .setup_called );
2545
2551
return _saudio .sample_rate ;
2546
2552
}
2547
2553
2548
2554
SOKOL_API_IMPL int saudio_buffer_frames (void ) {
2555
+ SOKOL_ASSERT (_saudio .setup_called );
2549
2556
return _saudio .buffer_frames ;
2550
2557
}
2551
2558
2552
2559
SOKOL_API_IMPL int saudio_channels (void ) {
2560
+ SOKOL_ASSERT (_saudio .setup_called );
2553
2561
return _saudio .num_channels ;
2554
2562
}
2555
2563
2556
2564
SOKOL_API_IMPL bool saudio_suspended (void ) {
2565
+ SOKOL_ASSERT (_saudio .setup_called );
2557
2566
#if defined(_SAUDIO_EMSCRIPTEN )
2558
2567
if (_saudio .valid ) {
2559
2568
return 1 == saudio_js_suspended ();
@@ -2567,6 +2576,7 @@ SOKOL_API_IMPL bool saudio_suspended(void) {
2567
2576
}
2568
2577
2569
2578
SOKOL_API_IMPL int saudio_expect (void ) {
2579
+ SOKOL_ASSERT (_saudio .setup_called );
2570
2580
if (_saudio .valid ) {
2571
2581
const int num_frames = _saudio_fifo_writable_bytes (& _saudio .fifo ) / _saudio .bytes_per_frame ;
2572
2582
return num_frames ;
@@ -2577,6 +2587,7 @@ SOKOL_API_IMPL int saudio_expect(void) {
2577
2587
}
2578
2588
2579
2589
SOKOL_API_IMPL int saudio_push (const float * frames , int num_frames ) {
2590
+ SOKOL_ASSERT (_saudio .setup_called );
2580
2591
SOKOL_ASSERT (frames && (num_frames > 0 ));
2581
2592
if (_saudio .valid ) {
2582
2593
const int num_bytes = num_frames * _saudio .bytes_per_frame ;
0 commit comments