diff options
| author | Andre Weissflog <floooh@gmail.com> | 2021-12-19 23:00:08 +0100 |
|---|---|---|
| committer | Andre Weissflog <floooh@gmail.com> | 2021-12-19 23:00:08 +0100 |
| commit | c919b139e24ed7bd6cb9009fb25bbbab13dee0d9 (patch) | |
| tree | cdddf79e45880bbc90a2f9c3929a5fe8be289497 /sokol_audio.h | |
| parent | a95d6fc4f6a261e7c7087b4d4aeec7d1110a82b4 (diff) | |
sokol_audio.h: add a saudio_suspended() function
Diffstat (limited to 'sokol_audio.h')
| -rw-r--r-- | sokol_audio.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/sokol_audio.h b/sokol_audio.h index dad390ec..68c3ad1c 100644 --- a/sokol_audio.h +++ b/sokol_audio.h @@ -439,6 +439,8 @@ SOKOL_AUDIO_API_DECL int saudio_sample_rate(void); SOKOL_AUDIO_API_DECL int saudio_buffer_frames(void); /* actual number of channels */ SOKOL_AUDIO_API_DECL int saudio_channels(void); +/* return true if audio context is currently suspended (only in WebAudio backend, all other backends return false) */ +SOKOL_AUDIO_API_DECL bool saudio_suspended(void); /* get current number of frames to fill packet queue */ SOKOL_AUDIO_API_DECL int saudio_expect(void); /* push sample frames from main thread, returns number of frames actually pushed */ @@ -1794,6 +1796,18 @@ EM_JS(int, saudio_js_buffer_frames, (void), { } }); +/* return 1 if the WebAudio context is currently suspended, else 0 */ +EM_JS(int, saudio_js_suspended, (void), { + if (Module._saudio_context) { + if (Module._saudio_context.state === 'suspended') { + return 1; + } + else { + return 0; + } + } +}); + _SOKOL_PRIVATE bool _saudio_backend_init(void) { if (saudio_js_init(_saudio.sample_rate, _saudio.num_channels, _saudio.buffer_frames)) { _saudio.bytes_per_frame = (int)sizeof(float) * _saudio.num_channels; @@ -2131,6 +2145,19 @@ SOKOL_API_IMPL int saudio_channels(void) { return _saudio.num_channels; } +SOKOL_API_IMPL bool saudio_suspended(void) { + #if defined(_SAUDIO_EMSCRIPTEN) + if (_saudio.valid) { + return 1 == saudio_js_suspended(); + } + else { + return false; + } + #else + return false; + #endif +} + SOKOL_API_IMPL int saudio_expect(void) { if (_saudio.valid) { const int num_frames = _saudio_fifo_writable_bytes(&_saudio.fifo) / _saudio.bytes_per_frame; |