diff options
| author | Andre Weissflog <floooh@gmail.com> | 2018-09-23 17:22:15 +0200 |
|---|---|---|
| committer | Andre Weissflog <floooh@gmail.com> | 2018-09-23 17:22:15 +0200 |
| commit | c7b09ba12708983fad0e2ff972bf2d3df0ffb206 (patch) | |
| tree | 1dc2a8e2dfd193b6368cb7f671734f3bf4a2f395 | |
| parent | cf49f351dff9414c014971a47545038833a8f705 (diff) | |
sokol-audio: some code cleanup, and add callback support to emscripten backend
| -rw-r--r-- | sokol_audio.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/sokol_audio.h b/sokol_audio.h index d533bced..f612154d 100644 --- a/sokol_audio.h +++ b/sokol_audio.h @@ -549,7 +549,7 @@ _SOKOL_PRIVATE void* _saudio_alsa_cb(void* param) { else { /* fill the streaming buffer with new data */ if (_saudio.stream_cb) { - _saudio.stream_cb(_saudio_alsa.buffer, _saudio_alsa.buffer_frames); + _saudio.stream_cb(_saudio_alsa.buffer, _saudio_alsa.buffer_byte_size / sizeof(float)); } else { if (0 == _saudio_fifo_read(&_saudio.fifo, (uint8_t*)_saudio_alsa.buffer, _saudio_alsa.buffer_byte_size)) { @@ -671,7 +671,7 @@ static _saudio_wasapi_state _saudio_wasapi; /* fill intermediate buffer with new data and reset buffer_pos */ _SOKOL_PRIVATE void _saudio_wasapi_fill_buffer(void) { if (_saudio.stream_cb) { - _saudio.stream_cb(_saudio_wasapi.thread.src_buffer, _saudio_wasapi.thread.src_buffer_frames); + _saudio.stream_cb(_saudio_wasapi.thread.src_buffer, _saudio_wasapi.thread.src_buffer_byte_size / sizeof(float)); } else { if (0 == _saudio_fifo_read(&_saudio.fifo, (uint8_t*)_saudio_wasapi.thread.src_buffer, _saudio_wasapi.thread.src_buffer_byte_size)) { @@ -870,9 +870,14 @@ EMSCRIPTEN_KEEPALIVE int _saudio_emsc_pull(int num_frames) { SOKOL_ASSERT(_saudio_emsc_buffer); if (num_frames == _saudio.buffer_frames) { const int num_bytes = num_frames * _saudio.bytes_per_frame; - if (0 == _saudio_fifo_read(&_saudio.fifo, _saudio_emsc_buffer, num_bytes)) { - /* not enough read data available, fill the entire buffer with silence */ - memset(_saudio_emsc_buffer, 0, num_bytes); + if (_saudio.stream_cb) { + _saudio.stream_cb((float*)_saudio_emsc_buffer, num_bytes / sizeof(float)); + } + else { + if (0 == _saudio_fifo_read(&_saudio.fifo, _saudio_emsc_buffer, num_bytes)) { + /* not enough read data available, fill the entire buffer with silence */ + memset(_saudio_emsc_buffer, 0, num_bytes); + } } int res = (int) _saudio_emsc_buffer; return res; |