Skip to content

Commit 958ad3e

Browse files
author
GH Action
committed
1 parent 3491f61 commit 958ad3e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/sokol/c/sokol_audio.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,7 @@ typedef struct {
10671067
/* sokol-audio state */
10681068
typedef struct {
10691069
bool valid;
1070+
bool setup_called;
10701071
void (*stream_cb)(float* buffer, int num_frames, int num_channels);
10711072
void (*stream_userdata_cb)(float* buffer, int num_frames, int num_channels, void* user_data);
10721073
void* user_data;
@@ -2486,9 +2487,11 @@ void _saudio_backend_shutdown(void) {
24862487
// >>public
24872488
SOKOL_API_IMPL void saudio_setup(const saudio_desc* desc) {
24882489
SOKOL_ASSERT(!_saudio.valid);
2490+
SOKOL_ASSERT(!_saudio.setup_called);
24892491
SOKOL_ASSERT(desc);
24902492
SOKOL_ASSERT((desc->allocator.alloc_fn && desc->allocator.free_fn) || (!desc->allocator.alloc_fn && !desc->allocator.free_fn));
24912493
_saudio_clear(&_saudio, sizeof(_saudio));
2494+
_saudio.setup_called = true;
24922495
_saudio.desc = *desc;
24932496
_saudio.stream_cb = desc->stream_cb;
24942497
_saudio.stream_userdata_cb = desc->stream_userdata_cb;
@@ -2519,6 +2522,8 @@ SOKOL_API_IMPL void saudio_setup(const saudio_desc* desc) {
25192522
}
25202523

25212524
SOKOL_API_IMPL void saudio_shutdown(void) {
2525+
SOKOL_ASSERT(_saudio.setup_called);
2526+
_saudio.setup_called = false;
25222527
if (_saudio.valid) {
25232528
_saudio_backend_shutdown();
25242529
_saudio_fifo_shutdown(&_saudio.fifo);
@@ -2532,26 +2537,32 @@ SOKOL_API_IMPL bool saudio_isvalid(void) {
25322537
}
25332538

25342539
SOKOL_API_IMPL void* saudio_userdata(void) {
2540+
SOKOL_ASSERT(_saudio.setup_called);
25352541
return _saudio.desc.user_data;
25362542
}
25372543

25382544
SOKOL_API_IMPL saudio_desc saudio_query_desc(void) {
2545+
SOKOL_ASSERT(_saudio.setup_called);
25392546
return _saudio.desc;
25402547
}
25412548

25422549
SOKOL_API_IMPL int saudio_sample_rate(void) {
2550+
SOKOL_ASSERT(_saudio.setup_called);
25432551
return _saudio.sample_rate;
25442552
}
25452553

25462554
SOKOL_API_IMPL int saudio_buffer_frames(void) {
2555+
SOKOL_ASSERT(_saudio.setup_called);
25472556
return _saudio.buffer_frames;
25482557
}
25492558

25502559
SOKOL_API_IMPL int saudio_channels(void) {
2560+
SOKOL_ASSERT(_saudio.setup_called);
25512561
return _saudio.num_channels;
25522562
}
25532563

25542564
SOKOL_API_IMPL bool saudio_suspended(void) {
2565+
SOKOL_ASSERT(_saudio.setup_called);
25552566
#if defined(_SAUDIO_EMSCRIPTEN)
25562567
if (_saudio.valid) {
25572568
return 1 == saudio_js_suspended();
@@ -2565,6 +2576,7 @@ SOKOL_API_IMPL bool saudio_suspended(void) {
25652576
}
25662577

25672578
SOKOL_API_IMPL int saudio_expect(void) {
2579+
SOKOL_ASSERT(_saudio.setup_called);
25682580
if (_saudio.valid) {
25692581
const int num_frames = _saudio_fifo_writable_bytes(&_saudio.fifo) / _saudio.bytes_per_frame;
25702582
return num_frames;
@@ -2575,6 +2587,7 @@ SOKOL_API_IMPL int saudio_expect(void) {
25752587
}
25762588

25772589
SOKOL_API_IMPL int saudio_push(const float* frames, int num_frames) {
2590+
SOKOL_ASSERT(_saudio.setup_called);
25782591
SOKOL_ASSERT(frames && (num_frames > 0));
25792592
if (_saudio.valid) {
25802593
const int num_bytes = num_frames * _saudio.bytes_per_frame;

0 commit comments

Comments
 (0)