I’m hoping someone can lend a hand here. I’m trying to set up a coroutine to manage looping audio (music) seamlessly but I’m getting a bit of pop/crackle between the clips.
This is being done via a singleton ScriptableObject that manages all my other clips and mixers (this is why I’m not using Update()).
If it helps, I’m rendering the audio out of Ableton Live 11. It’s a 16 bar clip rendered as a loop in .wav format.
Although, it doesn’t seem to matter if the clip is 16 seconds or 4 minutes long, I’m still getting a pop when the scheduled clip starts.
I can post some code for manual looping that works, if you’d like.
The logic is a bit different from what you are using. More flexible.
I’d rather not try to fix your script, because I’m not grasping some of the decisions being made, and debugging these kinds of calculations can be a real time sink.
Ok. I’ve been over every other source out there, including several posts from these boards. I believe my code is correct in the sense that it should work, and it does. The caller retains a handle to the coroutine so that future calls will terminate the “current loop” before executing a new coroutine. There’s just an audible “pop” when the loop begins (or ends?).
All of the resources I’ve seen suggest using 2 audio sources and flipping them with PlayScheduled to create a “seamless” loop. The intent in my script is that we’ll just sleep the thread until 1 second before the current loop is done, schedule it on the secondary source, and go back to sleep after flipping the source index. Each iteration of the coroutine will add the clip duration to the current “time” in dspTime.
I don’t think you’re going to post anything I haven’t already seen, but I’m still interested. I’m not happy with my stopgap solution, and I’ve moved on, but I’m willing to go back and take another look if you can provide something new.
Edit: In fact, it may be that I need to just use AudioSettings.dspTime in my calculation of the next offset rather than updating time, due to the asynchronous nature of the loop itself. I’ll try that.
Audio guy here, I believe the problem is with your audio file. For seamless looping you need a microfade at the start and end of your track.
The pop comes from the engine trying to leap from the volume at the end of your track straight to the volume at the beginning of your track. You need to fade the end of the track down to 0db and fade in from 0db at the start of the track, you can do this at a miniscule level so that the fade isn’t recognisable.