Comments (2)
You'll need to take care of this in yourself in the audio callback I'm afraid by copying the generated samples not only into the audio API buffer, but also into a memory location where the rendering code can read them.
Just be aware though that the audio callback usually runs in a separate thread, so you'll also need to make sure that the read and write pointers don't trample on each other's feet.
The audio callback is definitely the method to use (versus the 'push API') for getting the lowest latency out of sokol-audio.h.
I think the only way to reduce latency further between audio output and rendering is to experiment with smaller audio buffer sizes, there's no way to get the actual 'audio play cursor' from sokol-audio though (I'm not even sure if all backend APIs would provide such a feature).
PS: if it needs to work on the web, then reducing the audio buffer size to reduce latency might not be an option unfortunately, because the current WebAudio backend runs the streaming callback on the main thread (no Audio Worklet support yet).
from sokol.
Hi thanks for the quick response. That's okay about the copying - that's how I imagined it. I can wrap it in a mutex or something. I would like to run on web, but it's not a huge priority right now.
I'm not fully looking for an exact solution, just right now I do the naive thing and display the current value after the callback has ended, but it displays the same value for 6-7 frames before the audio updates again and it looks janky.
That's because the audio buffer could span across many video frames. E.g the audio buffer is 46ms and the video frametime is 7ms. Perhaps I can just record at enough points in the audio callback and in the display just interpolate through those values, will that be correct enough?
However my assumption was that even though the audio thread is calling my callback to append to a buffer, those samples aren't necessarily the next ones to be played - the buffer may still contain samples from the previous callback. If that's the case I can't really know when this callback's samples will be played. Maybe I can just assume they will be played immediately and it will look good enough.
Your other suggestion was to lower the buffer so it matches more closely with the video framerate. That does sound like a simpler solution, I'll have to look into that and see what the consequences are
from sokol.
Related Issues (20)
- Idea: Add flags to only initialize certain parts in sokol_app HOT 2
- Planning: Resource binding cleanup
- Is there a plan to add Vulkan? HOT 1
- Support for cubemap arrays HOT 1
- Missing ETC_R11 format HOT 2
- [Question] Can sokol reuse webgl ids from glGen* HOT 2
- Best way of enabling shader debugging for D3D11? HOT 4
- Handling Alt-Tab. HOT 4
- Help using sokol_app with OpenGL on Windows HOT 3
- A simple Initialization texture binding function would be nice to have HOT 3
- render to existing window handle HOT 2
- Toggling fullscreen stalls event updates (macOS) HOT 2
- Turning off Vsync (again) - could it be partially feasible? HOT 2
- sokol_audio.h: capture input HOT 2
- [sokol_app] Alt-tabbing issues on windows in a FPS game on a multi-monitor setup HOT 2
- D3D11 storage buffers do not compile on wine HOT 1
- Seems .c file not generated in bindgen, producing errors HOT 2
- test
- Sokol Fetch Http response 200 is reported as an error HOT 7
- [sokol_gfx d3d11] update_image is wrong for 3d textures HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sokol.