Comments (2)
The main issue here is that the mixer thread is the thing generating events, dictating when the source actually starts/stops/pauses, when it finishes with a buffer, etc, which needs to be real-time safe. Because of that, it can't allocate or deallocate memory, so the events are stored in preallocated memory (the ring buffer), queued to be handled by a separate event handler thread (which your callback is called on, allowing it to be non-real-time safe). If the preallocated buffer gets filled up with pending events, either because too many events are generated too fast and/or because the callback takes too long to process them, those excess events get lost since the mixer can't allocate more memory or wait for space to become available to store them.
Obviously this causes a problem when a significant number of events are generated without enough time to handle them. And there's no way to accurately predict how many events can get queued, as it depends on how well the event handler thread is scheduled by the OS, how often the audio device does mixing updates, how fast/slow the callback can be, and the behavior of the app/sounds. Basing the queue size on the number of sources can result in an unnecessarily large queue, as it depends on how many start and/or stop very close together (within a few dozen milliseconds normally). Assuming the app even enables notification of those events, which isn't known at the time. As it is, a size of 511 is on the high side for most uses, but this is the first report I'm getting of it being too small.
Having the app specify/hint the queue size seems like it'd rely a lot on trial-and-error, and be somewhat system dependent. Some systems may be more prone to clogging the event queue than others. The amount of memory used for each queue element also isn't public and can change between versions, so specifying a large queue just the be safe can cause a significant memory increase when updating.
I unfortunately don't have an answer for how to best deal with the problem, yet. I'd really like to find a way that isn't limited to a fixed size queue, and also won't suffer from the A-B-A problem. For now, I have been able to increase the queue size while also lowering the memory use (reduced the size of each queue entry to a bit less than 1/4th, and doubled the size of the queue). Ways to improve it further are open to discussion.
from openal-soft.
I understand that it isn't as easy to fix as I thought, especially fixing it properly. For now I reverted back to polling OpenAL due to the described issue and a potential race condition I discovered as well, so no preassure to find a quick fix. Thanks for your efforts nonetheless.
If anyone is curious, here is the race condition I found (Specific to my application and I am not expecting it to be fixed):
My application has a builtin concurrent sound source limit (Works by tracking all currently playing sources). If a new source should be played, but the limit is already reached the oldest source will be deleted, so the new one can start playing. When the source is deleted its removed from the tracked list and the new one is added to it. Due the async nature of SOFT_events the stop event for the deleted source could still be in the event queue. The issue arises when the newly allocated source has the same id as the deleted one and the event for the old one is still in the event queue. As soon as the event gets to my application, it causes the newly created source to be deleted because my application doesn't know if the event is outdated or not (outdated meaning, the source which generated the event doesn't exist anymore and thus all queued events from it aren't relevant anymore and would instead affect the newly created source)
from openal-soft.
Related Issues (20)
- No matching function for call HOT 2
- Looping sound won't stop mid-loop
- [Question] Idea of splitting the output channel; is this possible in the current API? HOT 1
- Support for XAudio2 via the Wine-4.2 compatibility layer HOT 10
- Set log callback HOT 2
- [Question] 16 speakers in Windows using AmbiSonics (without HDMI and Receiver) HOT 5
- Unreal Tournament 2004 - No sound with EAX enabled HOT 3
- Bioshock EAX support HOT 8
- openal-soft.org timeout HOT 2
- Device-less buffer support? HOT 6
- ALC_SOFT_system_events support HOT 4
- Dosbox i586 HOT 2
- Android library failing to build HOT 4
- OpenAL plays back original sound from source ALONGSIDE the sound with the applied effect HOT 2
- Missing `EXCLUDE_FROM_ALL` for Oboe from source HOT 1
- [Question] What's the difference between regular releases an makemhr releases? HOT 1
- [Question] How the Desktop OpenAL-Soft works in the browser using WebAssembly? HOT 1
- [Question] Get current ports of sink and source devices HOT 2
- [bug] atomic doesn't exist on mac, ios but is added HOT 2
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 openal-soft.