Audio stopping after awhile (varies) in MacOS build

I have an audio-based project that has a bunch of objects, each with an AudioSource playing synthesized tones (OnAudioFilterRead drives them). I’ve run it on several different systems (Windows/Mac) for hours with no problem, but when the build was installed on a Mac Mini (not sure of OS, it’s in a gallery), the audio will stop working after awhile. Restarting the app fixes it.

I think I’m driving the audio engine too hard as there are 144 sound sources, and each uses OnAudioFilterRead which I know is processor intensive. What’s the best way to make this less intensive so it won’t quit? What audio settings could I change? I need both the large number of sound sources as well as the synthesis, that’s kind of the basis of the project.

Alternatively, is there a way to “reset” the audio system from within the app? I don’t care if there’s a sound gap every now and then…what I need to avoid is having it stop altogether, it’s in a gallery and I don’t have access to restart it, and I don’t want the gallery folks to have to babysit it!

Sounds like you got a cool project going!

APlaying with AudioConfiguration.dspBufferSize is generally the first thing I would try, to give more time to the engine so it has more time to compute everything or smaller buffers to work with. The side effect if obviously a slight delay in audio production, which might not be a big problem if your concept does not rely too much on input or visual sync with audio.

Having >100 components feeding OnAudioFilterRead might be intensive yeah… You might be able to optimize your sound generation depending on how you’re doing it.

  • if you have a precomputed base sound that you could read a skip some calculations
  • you could “cluster” some sources that are close together and average/merge them to a single source
  • tweaking the priority of sounds based on which one you think are more important
    • generally the engine will do that for you by calculating each sources audibility and then produce <AudioConfiguration.numRealVoices> sources
    • you might bypass some of that computing by making priorities more obvious

Resetting the audio configuration with AudioSettings.Reset might do the trick!

This is excellent, thank you so much. I’m going to tweak a bunch of stuff and see how it goes. I’m also trying a different version with pre-made simple waveforms (sin/saw/square/tri etc) and using speed for pitch variation (just one cycle each at 200 Hz base tone). So far I can use a ton of sources and there’s no glitching.

I do want to try some amp and frequency modulation, but maybe those will be more of the specialty sounds. I’ll probably simulate the amp mod by having sources near each other off by just a bit so there’s beating, or maybe put two sources on each sphere (one on each side) and then rotate the whole thing, get the rotary speaker effect :slight_smile:
Thanks again!