CSNG (File Format): Difference between revisions

Jump to navigation Jump to search
Clarify nature of delta time encoding
imported>Jackoalan
imported>Jackoalan
(Clarify nature of delta time encoding)
Line 150: Line 150:


Just like MIDI, each command starts with a '''delta time''' value telling the sequencer  
Just like MIDI, each command starts with a '''delta time''' value telling the sequencer  
how many ticks to wait after the previous command. Unlike MIDI, Factor5 uses a custom
how many ticks to wait after the previous command. Unlike MIDI, Factor5 uses a fixed 16-bit
[[wikipedia:Run-length encoding|RLE scheme]] to adaptively scale the value's precision
value to store the delta times. In case of a delta time greater than 65535, no-op commands
to reduce the value's size.
with a 65535 delta time are inserted into the command stream until the target time is attained.


The RLE operates on 16-bit words, with the value 0xffff triggering a continuation,
In a theoretical Python streaming API, the delta time can be decoded with no-ops automatically consumed like so:
then a 'dead' 16-bit word skipped over, then the 0xffff is summed with the following RLE value,
looping the decode algorithm.
 
In Python, decoding works like so:


<syntaxhighlight lang="python" line="1">
<syntaxhighlight lang="python" line="1">
def DecodeDeltaTimeRLE(streamIn):
def DecodeDeltaTime(streamIn):
     total = 0
     total = 0
     while True:
     while True:
         term = streamIn.ReadU16()
         term = streamIn.ReadU16()
         if term == 0xffff:
        next = streamIn.PeekU16()
         if next == 0:
             total += 0xffff
             total += 0xffff
             dummy = streamIn.ReadU16()
             streamIn.seekAhead(2)
             continue
             continue
         total += term
         total += term
Anonymous user

Navigation menu