pinobatch / pently

Scalable music engine for NES games
zlib License
72 stars 4 forks source link

Pattern loop point lookahead #24

Open pinobatch opened 6 years ago

pinobatch commented 6 years ago

Profiling Pently (issue #5) reveals that more complex tracks cause CPU time spikes at the start of patterns, particularly "Isometry" which uses five play commands to start all five tracks at once and ends up taking roughly 3800 cycles. This can happen to a lesser extent if multiple patterns hit their loop point (PATEND in pattern bytecode) at the same time. So during downtime, look for the first track that may hit a play or PATEND on the next row and proactively (re)start it. This should help smooth out peaks other than on the first frame.

Also consider run this sort of lookahead in pently_start_music, which in some games may be done on a blank screen when worst-case CPU use isn't as critical.