SuperDisk / hUGEDriver

An easy-to-use, fast, tracker-based, public domain sound driver for Game Boy homebrew
https://nickfa.ro/index.php/HUGETracker
52 stars 10 forks source link

Implement compression for patterns #2

Open SuperDisk opened 4 years ago

SuperDisk commented 4 years ago

As it stands, the contents of patterns can be fairly repetitive and not benefit from any sort of compression.

There are a couple solutions I've been thinking about:

I'm partial to the first option since I don't really like the idea of having 2 "methods" of breaking up music (patterns/loop areas), and the second option would require some more logic to handle looping in each channel, whereas the first option fits pretty nicely in with the current structure of the code.

To be honest, this can probably be put off until after the first release or whatever since what currently exists is (afaik) better size-wise than everything out there already.

RichardULZ commented 4 years ago

If it's just for compression sake,

Thinking through how it might work For jump commands, they would still need to "Catch up" By reading bytes until the pattern is at the right step, and keeping tabs on where we last read data from, could be 1 byte added to the pattern pointer.

The note byte bit7 would define whether the note/normal 3 bytes of data are here, or what step to wait for new data. Check if the first byte has bit 7 set by subtracting 0x80, jump if we carry or not.

Jump, Has 3 bytes of data. If we're not catching up, read the 3 bytes into ram. If we are catching up, increment our current step counter for this channel, if we're not at the right step, skip the next 2 bytes, and load another.

Jump, Has next step with data, If we're not catching up, store the next real step, when loading a new byte, now every step we have to check if the current step is equal to next real step, only then will we read the next byte. If we are catching up, store the next real step, then math 'desired position' - next real step, see if it carried to determine where we are.

That all thought through out of my head, it's still debatable how slow decompression could be, as the simplicity of knowing it is always 3 bytes per step helps a lot, perhaps things will change when we start loading from other banks with pesky bank switching.

Edit: Now that i read through your ideas again, this is pretty similar to option 2 where the tracker loops through places.