The SNG file format - MrLetsplay2003/PlayerRadios GitHub Wiki
An SNG-File in itself is pretty simple. It consists of a file header, one or multiple song headers (Song ID, Song name, Song length, Song TPS, Song height/layers), each associated with one body consisting of instructions (custom sounds, notes, pauses, song/file end). Inspired by the NBS file format (http://www.stuffbydavid.com/mcnbs/format)
Need the song loader for one of your projects? https://github.com/MrLetsplay2003/PlayerRadios/tree/songloader
File header:
- sngF (4 bytes, String) - the literal string "sngF". Indicates that this is indeed an SNG file
Song header:
- Song ID (4 bytes, Integer) - The song's ID (Varies for every server as IDs are automatically set)
- Song name (2 bytes length,
length
bytes name, String) - The song's name - Song length (4 bytes, Integer) - The song's length in ticks. Can be calculated later
- Song TPS (2 bytes, Short) - The song's ticks per second multiplied by 100
- Song height (1 byte) - The song's height/layers
Song body:
- First data byte (1 byte):
- 2 bits - Data type (
00
= note,01
= pause,10
= end,11
= custom sound) - 1 bit - Indicates whether this is the last note/pause of this tick
- 5 bits - The first chunk of data
- 2 bits - Data type (
- If the data type is "note":
- The first data chunk is the note's pitch
- Note instrument (1 byte) - A list of instruments can be found here (http://www.stuffbydavid.com/mcnbs/format) under Part #2, Step #3
- If the data type is "pause":
- Second data chunk (First data chunk + 1 byte) - The pause's length (e.g.: if the first data chunk is
00101
and the second data chunk is01001000
then the pause would be0010101001000
= 8+64+256+1024 = 1352 ticks long)
- Second data chunk (First data chunk + 1 byte) - The pause's length (e.g.: if the first data chunk is
- If the data type is "end":
- If the first chunk of data is
00001
(1): The file has ended. There are no more songs after this - If the first chunk of data is
00000
(0): The song has ended. There should be more songs after this. Continue back at the song header
- If the first chunk of data is
- If the data type is "custom sound":
- The first data chunk is the custom instrument's id
- Custom sound name (2 bytes length,
length
bytes custom sound name, String)