

As for whether or not that accuracy is possible, there's two step sequencers out (the one at the top of this thread, and the one on Kongregate made by quickfingers) that seem to indicate it is possible in Unity. You can tell the script to look for each millisecond, but the engine isn't checking fast enough to actually see every millisecond (thus why tomnullpointer's solution at the top of the thread was necessary) as far as I know. It was my understanding, hippocoder, that actual millisecond based checks aren't possible or are difficult because of the speed at which Update, FixedUpdate, and coroutines run in Unity. So by checking once a threshold is hit, it ensures that a new sound will always be triggered once every loop, and then that sound is offset by the number of samples left in the metronome loop, so that the sound plays exactly at the start of the next loop.
STEP SEQ. KONGREGATE UPDATE
We cached the remaining samples in the current metronome loop because, while the goal was to trigger the sound effect at the start of every metronome loop, neither Update nor FixedUpdate (which is faster, to my knowledge) updates anywhere near as fast as the sample rate of an audio file (in this case, 44100 Hz), so it would be impossible to cache the metronome's sample position and simply trigger a sound whenever that position is 0 it simply wouldn't see 0 most of the time. There still remains a very big difference between the results of my scripts/your suggestion, and the results of tomnullpointer's example at the top of the thread, which is what I'm mainly confused about.
STEP SEQ. KONGREGATE CODE
I tried your code out, starpaq, and it seems to have about the same result as a lot of our previous tests, in that there are still very noticeable inaccuracies in the timing of the triggered sample (i.e. This solution might not work for super slow machines and it less accurate as your tempo increases (but you can adjust the margin for that) but its the best, rather only solution ive found so far. This means it will play on the exact loop point that is coming up. BUT offset it by the remaining samples in the current loop (loop sample length- current sample position). If its close enough to the next loop then trigger a new sound to play (and stop checking ).

Use this position to detect if the current loop of the metronome sample is nearing its end (the margin you can detect depends on the frequency of your fixedupdate etc). Run a fixedupdate (or any fast thread) and use this to find the current PCM sample pos of the metronome. Heres the trick ,just in case anyone else has struggled with this. However, with some sneaky tricks Ive managed to get triggers to work down to a acceptable range. Probably only hardware bound callbacks (ie buffer requests from audio cards) are accurate enough. Unity isnt very good for small MS callbacks, it wont give access to fmods callbacks and all manner of timers (threads, coroutines,system timers) have lag and variable results when down to audio MS range. Ive tried what seems like a million ways to get realtime audio sequencing in unity. Generally speaking, iterables are more general than sequence types.Ok so its a bit of a cheat, but it does work! For example, a set is iterable but it’s not a sequence. However, an iterable may not be a sequence type. Sequence type vs iterable typeĪn iterable is a collection of objects where you can get each element one by one. In general, homogeneous sequence types are more efficient than heterogeneous in terms of storage and operations. Lists, however, are heterogeneous sequences where you can store elements of different types including integer, strings, objects, etc. For example, strings are homogeneous sequences where each element is of the same type. In a homogeneous sequence, all elements have the same type. The mutable sequence types are lists and bytearrays while the immutable sequence types are strings, tuples, range, and bytes.Ī sequence can be homogeneous or heterogeneous.

Python classifies sequence types as mutable and immutable. Python has the following built-in sequence types: lists, bytearrays, strings, tuples, range, and bytes. If the sequence s has n items, the last item is s. So the first element is s and the second element is s. In Python, the sequence index starts at 0, not 1. And you can refer to any item in the sequence by using its index number e.g., s and s. Introduction to Python sequencesĪ sequence is a positionally ordered collection of items. Summary: in this tutorial, you’ll learn about the Python sequences and their basic operations.
