Amount of music in a game a function of...?

Posts: 108
Joined: Sun Feb 18, 2018 5:25 pm

Re: Amount of music in a game a function of...?

Post by stevenshepherd » Sun Jun 24, 2018 3:32 am

Ok so this is going to be overly simplistic, but if anything hopefully gets across what I am thinking:

So it seems that a 5 second song on a loop would take up less space than a 30 second song with the same 5 second loop 6 times. Which makes me think:

Say I have a song with an AABB structure. If I did this out in Famitracker I would have to copy section A twice, and section B twice, each adding "unique" information that takes up space, but in reality it is just the same section repeated. I am just wondering how the NES handles this and/or if there was a way for it to play AABB as, for example: "play these 32 notes (section A), then play them again. Play these other 32 notes (section B), then play them again" which would be 66 "pieces of information" as opposed to 128. Hopefully that makes sense. This me trying to translate my abstract lay intuitions about memory etc into something that makes sense.
User avatar
Posts: 99
Joined: Fri Mar 09, 2018 11:13 pm

Re: Amount of music in a game a function of...?

Post by Kasumi » Sun Jun 24, 2018 11:02 pm

To answer your first bit. (A 30 second loop with the same 5 second loop 6 times would take up more space.) It usually would, but not for the reason I think you think? Data is usually made of layers of grouped concepts. This is a bit simplified, but... Say a group of 16 notes takes up 16 bytes. That's the first layer. Now say you wanted to repeat those same 16 notes 5 times. That only takes five bytes. (Rather than 80.) This is because the second layer only stores "which set of 16 notes" rather than just outputting a byte for each of the total 80 notes. The size of these 16 notes repeated five times is 21 bytes. The size of it repeated once would be 17 bytes.

So let's say 16 notes is one second. Let's say each second uses a unique set of 16 notes. To store that 5 seconds of note data, you need 80 bytes. But then you also need the second layer. A byte for each second of the song. And then a third layer. Info about the song. (How many groups of 16 notes in the whole song, plus maybe tempo. We'll say that's 3 bytes.)

The equation for how many bytes a song takes up (in this simplified example) is number of unique 16 note sections times 16 plus number of total 16 note sections in the song plus three.

So a 5 second loop looped once is gonna be 16*5+5+3 bytes. 88.

If you wanted to do a five second long loop looped six times. The note data is still 16*5. 80 bytes. The tempo and length of song would still be 3 bytes. (Instead of 5, the length would be 30, but that's still only one byte.) What changes is you still need a byte for each 16 byte section of the song. So the equation is 16*5+30+3. 113 bytes. Which is bigger. But it's not 80 (16*5) bytes vs 480 (16*30) bytes.

A smart enough converter could in theory even detect that it just looped that way and output the exact same thing (88 bytes) for both cases. (But that's something I wouldn't count on expecting.)

If you did AABB in FamiTracker you could not have to copy section A twice, or section B twice. FamiTracker lets you reuse parts of a song. (Provided said sections matched the length of the "Rows" value within FamiTracker.) Edits to either part would change both.

I'd have to investigate how the GGSound Converter handles it, but I would bet it would not create duplicate data if you did that. If you create duplicate data that doesn't match rows, it probably would output the duplicate data more than once. (Detecting reuse in "unaligned" data is a much harder engineering problem.)

Edit: Now I have checked out GGSound handles it. Yes, if you reuse data in the Famitracker way, GGSound will not export duplicate note data. But the looped song is still a bit bigger because of the "song" data rather than the "note" data.

So shorter: Famitracker already lets you re-use parts of a song in a memory friendly way, I would expect most converters that read famitracker's output to not output the same data twice if Famitracker's exported data doesn't. But to reuse parts in Famitracker, you need to have the repeated sections match the "Rows" length.

Edit2: So basically... you can repeat notes, but the information that tells the engine how to repeat still takes up space even if the repeated notes don't. This is why the 30 second loop takes more space than the 5 second loop.

But! You could handle repeated data in any way you like if you wrote your own music engine data. There's no real "default" for NES. You could write code that creates entirely procedural music based on what's happening on screen with no actual note OR song data stored.
Posts: 108
Joined: Sun Feb 18, 2018 5:25 pm

Re: Amount of music in a game a function of...?

Post by stevenshepherd » Sun Jun 24, 2018 11:51 pm

Thanks very much, that is helpful! :)
Post Reply