I have a number of short clips that need to be played with the best timing possible (basically it’s an instrument that plays based on visual timing of moving objects). Is it best to use lots of AudioSources so I don’t have to keep swapping clips? I’ve done a lot of testing and there are considerable differences with playback in the Editor, the EXE, and on Android. (Which is expected, though there were some surprises here and there, like optimal DSP buffer size not being what I expected on Android to avoid dropouts…it was backwards from the usual, so higher settings did better.)
I use PlayOneShot because it allows multiple clips to be played with one AudioSource without cutting the previous ones off. However, even with that, playing a bunch of clips in rapid succession can cause a strange issue: the sounds still play, but are much quieter and seem “far off”…hard to explain. Once the tempo slows down, it returns to normal, and I hear a short series of clicks, as though the previous clips have finished (the timing is about right for this). Wondering if this makes sense to anyone and if you have suggestions…should I use enough AudioSources that I don’t ever have to swap clips? So one for each possible note?
I’m using frames to determine when to play the clips, which I know isn’t ideal, but frames are used to track the visual part and it would be tricky (not sure if even possible) to use PlayScheduled(). Also, as long as the tempo isn’t too high, the timing is good in the EXE and on quality Android devices. It’s just the playback “overload” that’s causing problems.
Also a general question on clips (and any GameObject that holds properties like them): One AudioSource can have different notes in my setup, so when I check which note to play, I always swap the clip (and this is right before playing). If the clip is the same, does the swap still happen? I’m assuming swapping clips is a performance bottleneck even with short ones. I could check earlier (which I plan to), and I could check if the clip is the same before swapping, so don’t bother if it is. But am curious in general: does Unity know if you’re swapping a property that’s the same as what’s there and doesn’t actually do it? This could go for textures etc too.
Thanks!