ChipTuneSoundFormat: Difference between revisions
No edit summary |
No edit summary |
||
Line 35: | Line 35: | ||
* (1) Number of envelope groups | * (1) Number of envelope groups | ||
* (1) Number of lookup tables | * (1) Number of lookup tables | ||
===Channels=== | |||
This format uses two kind of channels, being real channels and virtual channels. Virtual channels are sent to a mixer which is then outputs to real channels. | |||
Usually the real channels would be defined as follows: | |||
* 1 channel: mono. | |||
* 2 channels: stereo. channel 0 = left, channel 1 = right. | |||
* 4 channels: surround. channel 0 = left front, channel 1 = right front, channel 2 = left back, channel 3 = right back. | |||
===Metadata=== | ===Metadata=== | ||
Line 48: | Line 56: | ||
* UNIXTIME: The UNIX timestamp (as an integer in decimal notation, with an optional <tt>-</tt> for times before the UNIX epoch). The third part here, if used, is an amount of microseconds, not the same thing in UTF-8. | * UNIXTIME: The UNIX timestamp (as an integer in decimal notation, with an optional <tt>-</tt> for times before the UNIX epoch). The third part here, if used, is an amount of microseconds, not the same thing in UTF-8. | ||
* COMMENT: A comment text. You can use CRLF to make line breaks, and form feeds for page breaks. | * COMMENT: A comment text. You can use CRLF to make line breaks, and form feeds for page breaks. | ||
* RATE: A decimal number with similar meaning to the data at offset 0x24 in the VGM format, except in decihertz instead of hertz. | |||
* VOLUME: A decimal number (can optionally have <tt>-</tt> or <tt>+</tt> in front) with similar meaning to Volume Modifier in VGM. However, here you have to use -64 for a factor of 0.25 rather than using -63. | |||
It is recommended that unofficial keys are named using "X-" at front like Internet protocols are commonly using. | It is recommended that unofficial keys are named using "X-" at front like Internet protocols are commonly using. | ||
Line 63: | Line 73: | ||
* 2: Butterworth low-pass filter. First argument is one-byte filter order, and second is a four-byte cutoff frequency in decihertz. (This is mainly meant for use with emulation of [[Amiga]] LED filter.) | * 2: Butterworth low-pass filter. First argument is one-byte filter order, and second is a four-byte cutoff frequency in decihertz. (This is mainly meant for use with emulation of [[Amiga]] LED filter.) | ||
* 128: Subsection terminator. This terminates a subsection and applies it to the output, starting new with a blank signal, so that filters and so on can affect each subsection individually. | * 128: Subsection terminator. This terminates a subsection and applies it to the output, starting new with a blank signal, so that filters and so on can affect each subsection individually. Subsections are then added together to make the final output. | ||
* 129-255: Gated command. Between the command number and arguments are a chip number and digital output number. If the signal is high then the command is used, otherwise it is bypassed. | * 129-255: Gated command. Between the command number and arguments are a chip number and digital output number. If the signal is high then the command is used, otherwise it is bypassed. | ||
Line 78: | Line 88: | ||
For each digital input: | For each digital input: | ||
* (1) Chip number (255 = clock) | * (1) Chip number (255 = clock) | ||
* (1) Digital output number from chip (+128 for | * (1) Digital output number from chip (+128 for inverted signal; if clock, use 127 for constant low) | ||
For each analog output: | For each analog output: | ||
Line 84: | Line 94: | ||
* (2) Volume level (signed) | * (2) Volume level (signed) | ||
It is permitted to have as many instances of a chip as you want, and they may have same or different clock rates. | It is permitted to have as many instances of a chip as you want, and they may have same or different clock rates, and same or different parameters. | ||
===Macro definitions=== | ===Macro definitions=== | ||
Each macro consists of a series of commands. | |||
Each command consists of an opcode in the low nybble and an argument type in the high nybble. Opcode zero indicates that no more commands follow. Depending on the argument type, there may be more byte follow as the argument data. | |||
Opcodes: | |||
* 0: Delay and end macro. This command acts the same as command 1 except it is also the terminator for the macro definition. | |||
* 1: Delay. Argument is number of frames (at command rate) to delay before continuing execution. | |||
* 2: Chip select. Argument is the zero-based chip number. The initial chip select is undefined. | |||
* 3: Set address. Argument is an address. It doesn't do anything yet; it just sets an address, and it is associated with the currently selected chip. The initial address is undefined. | |||
* 4: Write data. Argument is data to write, and uses the current address and chip number to write. | |||
* 5: Activate ROM. If the chip uses any external ROM, this selects it. The argument is the ROM number, and the address is a bank number the bank size depends on the chip type). | |||
* 6: Select envelope group and lookup table number. This command selects both the current envelope group and lookup table number for use with further commands. If bit8 is set, playback of the selected envelope group will be stopped. | |||
* 7: Lookup table. The argument is an index into the lookup table, and the value stored there is put into the "previous argument" register. | |||
* 8: Write from lookup table. Reads as in command 7, but instead of storing into an internal register the result is written to the chip register as if it is command 4. | |||
* 9: Activate envelope. Argument is an envelope number within the current envelope group; if 255, it stops the envelope group. Either way, the global Misc registers are copied into the envelope group. | |||
* 10: Read Misc registers from envelope group given as argument, and stops playback of that envelope group. | |||
* 11: (reserved) | |||
* 12: Set Misc1 register. This is a global register. Its initial value when a track starts playing is zero. | |||
* 13: Set Misc2 register. | |||
* 14: Set Misc3 register. | |||
* 15: Set Misc4 register. | |||
Argtypes: | |||
* 0: Zero. | |||
* 1: One byte immediate. An immediate value is given in the macro definition and is used as the argoument value. | |||
* 2: Two byte immediate. | |||
* 3: Four byte immediate. | |||
* 4: Previous argument. Uses the value of the previous argument read from the pattern, or from command 7. | |||
* 5: One byte argument. Read a value from the pattern. | |||
* 6: Two byte argument. | |||
* 7: Four byte argument. | |||
* 8: Misc1 with postincrement. | |||
* 9: Misc3 minus Misc4. | |||
* 10: Misc1 plus Misc2. | |||
* 11: Misc3 plus Misc4. | |||
* 12: Misc1. | |||
* 13: Misc2. | |||
* 14: Misc3. | |||
* 15: Misc4. | |||
===External bit output specifications=== | ===External bit output specifications=== | ||
Line 94: | Line 175: | ||
===ROM images=== | ===ROM images=== | ||
ROM images consist of a four-byte length followed by the raw data. | |||
===Envelope groups=== | |||
Each envelope group contains the following header: | |||
* (1) Number of envelopes in this group | |||
* (1) Flag | |||
The flag is: | |||
[.... ABCD] | |||
|||| | |||
|||+--- Initialize Misc1 to zero if set | |||
||+---- Initialize Misc2 to zero if set | |||
|+----- Initialize Misc3 to zero if set | |||
+------ Initialize Misc4 to zero if set | |||
Initial values are inherited from the current value of the calling macro if these flags are not set. | |||
After the header is a macro definition (see above), although commands 9 and 10 cannot be used within the envelope, and command 6 with bit8 set is also not allowed. | |||
After that follows data for each envelope. | |||
===Envelopes=== | ===Envelopes=== | ||
Envelope local header: | |||
* (2) Length of envelope (number of macro invocations) | |||
* (2) Loop start position (same as length if not looping) | |||
* (2) Length of loop (zero if not looping) | |||
The data in the envelope is then according to the arguments of the macro which is defined to be part of this group. (The data will be empty if the macro takes no arguments, although the header is still present and can still have a nonzero length and loops despite this.) | |||
All Misc registers, as well as the current chip number and address, and the active lookup table number, are all local to each envelope group. | |||
===Lookup tables=== | ===Lookup tables=== | ||
Each lookup table consists of the following header: | |||
* (2) Number of entries | |||
* (1) Flag | |||
The flag is: | |||
[.... ..LL] | |||
|| | |||
++----- Length of each entry (00=1, 01=2, 10=4, 11=reserved) | |||
After the header, the data is given, which is the specified length, for each entry in the table. | |||
===Track data=== | ===Track data=== | ||
Each track consists of: | |||
* Local header | |||
* Local metadata | |||
* Play order table | |||
* Patterns | |||
The local header: | |||
* (1) Number of patterns | |||
* (1) Number of entries in play order table | |||
* (1) Zero-based loop start index into play order table | |||
* (1) Default loop count | |||
* (1) Number of order table entries to use inside the loop | |||
The local metadata is in the same format as the global metadata. Different keys may be used. One possible set of keys to use is as follows: | |||
* TITLE: The title of the song. | |||
* COMPOSER: Name of composer, if different for each track. | |||
* COPYRIGHT: Copyright notice, if different for each track. | |||
* UNIXTIME: The UNIX timestamp (as an integer in decimal notation, with an optional <tt>-</tt> for times before the UNIX epoch). The third part here, if used, is an amount of microseconds, not the same thing in UTF-8. | |||
* DURATION: The estimated duration in seconds, given as an integer in decimal notation. The third part here, if used, is an amount of microseconds, not the same thing in UTF-8. | |||
* COMMENT: A comment text. You can use CRLF to make line breaks, and form feeds for page breaks. | |||
* LOOP: Two numbers, with the ASCII unit separator in between, with purposes similar to the Loop Base and Loop Modifier of VGM format. The player might use this instead of (or in addition to) the default loop count, or it might ignore both. | |||
* FOLLOW-TRACK: If this track does not loop, the specified track is played next. (This is mainly designed for use with MegaZeux.) | |||
The play order table is a list of one-byte zero-based pattern numbers. | |||
===Patterns=== | |||
A pattern consists of a command list. Each entry in the command list is either a macro number followed by the arguments, or 255 followed by a command list as in a macro definition. | |||
If the macro commands are used here, then commands numbered $40 to $7F now have a different meaning than inside of macros, which is to delay a number of frames equal to the given number minus $40, and then terminate both the command list and the pattern. | |||
==Sound chips== | ==Sound chips== |
Revision as of 20:12, 1 July 2014
ChipTuneSoundFormat is a extensible logged music format which can support several sound chips. No known implementations exist.
This is a kind of draft format and may be adjusted by discussions.
File format
All numbers are in small-endian format. All text is case-sensitive unless otherwise specified.
Blocks
The file consists of blocks in the order:
- Master header
- Master metadata
- Clock rates
- Mixer settings
- Chip definitions
- Macro definitions
- External bit output specifications
- ROM images
- Envelopes
- Lookup tables
- Track data
Master header
- (8) ASCII characters spelling "chiptune"
- (1) Version (currently zero)
- (1) Number of real channels
- (1) Number of virtual channels
- (1) Number of clock sources
- (4) Command rate (in decihertz)
- (1) Number of ROM images
- (1) Number of tracks
- (1) Number of external bit outputs
- (1) Master volume (unsigned; 128=default)
- (1) Number of chips
- (1) Number of macros
- (1) Number of envelope groups
- (1) Number of lookup tables
Channels
This format uses two kind of channels, being real channels and virtual channels. Virtual channels are sent to a mixer which is then outputs to real channels.
Usually the real channels would be defined as follows:
- 1 channel: mono.
- 2 channels: stereo. channel 0 = left, channel 1 = right.
- 4 channels: surround. channel 0 = left front, channel 1 = right front, channel 2 = left back, channel 3 = right back.
Metadata
Metadata consists of a number of records, separated by the ASCII record separator, and terminated by the ASCII end of text. Parts of a record are delimited by the ASCII unit separator. All records are optional, and can normally appear in any order.
Each metadata record consists of a key as the first part, and then usually there will also be a second part which is a value. All data must be given in ASCII format. Optionally a third part is possible, which is the same thing in UTF-8.
Some possible keys can be:
- TITLE: The title of the song (or group, if applicable).
- COMPOSER: Name of composer.
- COPYRIGHT: Copyright notice.
- SYSTEM: Name of system being emulated/logged. This should usually be same as the values recommended for GD3 tags.
- UNIXTIME: The UNIX timestamp (as an integer in decimal notation, with an optional - for times before the UNIX epoch). The third part here, if used, is an amount of microseconds, not the same thing in UTF-8.
- COMMENT: A comment text. You can use CRLF to make line breaks, and form feeds for page breaks.
- RATE: A decimal number with similar meaning to the data at offset 0x24 in the VGM format, except in decihertz instead of hertz.
- VOLUME: A decimal number (can optionally have - or + in front) with similar meaning to Volume Modifier in VGM. However, here you have to use -64 for a factor of 0.25 rather than using -63.
It is recommended that unofficial keys are named using "X-" at front like Internet protocols are commonly using.
Clock rates
Clock rates are given in decihertz in four-bytes. They are in order as if digital outputs of chip number 255 with all clock sources on, starting with output pin number zero.
Mixer settings
There is one mixer per real channel. Each one is specified as a sequence of commands as follows:
- 0: Terminator.
- 1: Mix in. Takes two single-byte arguments, first the virtual channel number, and then the unsigned volume level.
- 2: Butterworth low-pass filter. First argument is one-byte filter order, and second is a four-byte cutoff frequency in decihertz. (This is mainly meant for use with emulation of Amiga LED filter.)
- 128: Subsection terminator. This terminates a subsection and applies it to the output, starting new with a blank signal, so that filters and so on can affect each subsection individually. Subsections are then added together to make the final output.
- 129-255: Gated command. Between the command number and arguments are a chip number and digital output number. If the signal is high then the command is used, otherwise it is bypassed.
Chip definitions
Each chip definition begins with a header as follows:
- (1) Length of name
- (1) Length of parameter
- (1) Number of digital inputs
- (1) Number of analog outputs
After this, the name (in ASCII) follows, and then the parameter (which can be arbitrary binary data, depending on the chip), followed by digital inputs, and then analog outputs. It is recommended that chips which are not officially specified are using names with "X-" at first.
For each digital input:
- (1) Chip number (255 = clock)
- (1) Digital output number from chip (+128 for inverted signal; if clock, use 127 for constant low)
For each analog output:
- (1) Virtual channel number
- (2) Volume level (signed)
It is permitted to have as many instances of a chip as you want, and they may have same or different clock rates, and same or different parameters.
Macro definitions
Each macro consists of a series of commands.
Each command consists of an opcode in the low nybble and an argument type in the high nybble. Opcode zero indicates that no more commands follow. Depending on the argument type, there may be more byte follow as the argument data.
Opcodes:
- 0: Delay and end macro. This command acts the same as command 1 except it is also the terminator for the macro definition.
- 1: Delay. Argument is number of frames (at command rate) to delay before continuing execution.
- 2: Chip select. Argument is the zero-based chip number. The initial chip select is undefined.
- 3: Set address. Argument is an address. It doesn't do anything yet; it just sets an address, and it is associated with the currently selected chip. The initial address is undefined.
- 4: Write data. Argument is data to write, and uses the current address and chip number to write.
- 5: Activate ROM. If the chip uses any external ROM, this selects it. The argument is the ROM number, and the address is a bank number the bank size depends on the chip type).
- 6: Select envelope group and lookup table number. This command selects both the current envelope group and lookup table number for use with further commands. If bit8 is set, playback of the selected envelope group will be stopped.
- 7: Lookup table. The argument is an index into the lookup table, and the value stored there is put into the "previous argument" register.
- 8: Write from lookup table. Reads as in command 7, but instead of storing into an internal register the result is written to the chip register as if it is command 4.
- 9: Activate envelope. Argument is an envelope number within the current envelope group; if 255, it stops the envelope group. Either way, the global Misc registers are copied into the envelope group.
- 10: Read Misc registers from envelope group given as argument, and stops playback of that envelope group.
- 11: (reserved)
- 12: Set Misc1 register. This is a global register. Its initial value when a track starts playing is zero.
- 13: Set Misc2 register.
- 14: Set Misc3 register.
- 15: Set Misc4 register.
Argtypes:
- 0: Zero.
- 1: One byte immediate. An immediate value is given in the macro definition and is used as the argoument value.
- 2: Two byte immediate.
- 3: Four byte immediate.
- 4: Previous argument. Uses the value of the previous argument read from the pattern, or from command 7.
- 5: One byte argument. Read a value from the pattern.
- 6: Two byte argument.
- 7: Four byte argument.
- 8: Misc1 with postincrement.
- 9: Misc3 minus Misc4.
- 10: Misc1 plus Misc2.
- 11: Misc3 plus Misc4.
- 12: Misc1.
- 13: Misc2.
- 14: Misc3.
- 15: Misc4.
External bit output specifications
External outputs are considered as digital inputs into a chip which is not actually specified. Its meaning is implementation-dependent.
Normally, these do nothing, however some playback software may use them to synchronize with graphics or for other purposes.
ROM images
ROM images consist of a four-byte length followed by the raw data.
Envelope groups
Each envelope group contains the following header:
- (1) Number of envelopes in this group
- (1) Flag
The flag is:
[.... ABCD] |||| |||+--- Initialize Misc1 to zero if set ||+---- Initialize Misc2 to zero if set |+----- Initialize Misc3 to zero if set +------ Initialize Misc4 to zero if set
Initial values are inherited from the current value of the calling macro if these flags are not set.
After the header is a macro definition (see above), although commands 9 and 10 cannot be used within the envelope, and command 6 with bit8 set is also not allowed.
After that follows data for each envelope.
Envelopes
Envelope local header:
- (2) Length of envelope (number of macro invocations)
- (2) Loop start position (same as length if not looping)
- (2) Length of loop (zero if not looping)
The data in the envelope is then according to the arguments of the macro which is defined to be part of this group. (The data will be empty if the macro takes no arguments, although the header is still present and can still have a nonzero length and loops despite this.)
All Misc registers, as well as the current chip number and address, and the active lookup table number, are all local to each envelope group.
Lookup tables
Each lookup table consists of the following header:
- (2) Number of entries
- (1) Flag
The flag is:
[.... ..LL] || ++----- Length of each entry (00=1, 01=2, 10=4, 11=reserved)
After the header, the data is given, which is the specified length, for each entry in the table.
Track data
Each track consists of:
- Local header
- Local metadata
- Play order table
- Patterns
The local header:
- (1) Number of patterns
- (1) Number of entries in play order table
- (1) Zero-based loop start index into play order table
- (1) Default loop count
- (1) Number of order table entries to use inside the loop
The local metadata is in the same format as the global metadata. Different keys may be used. One possible set of keys to use is as follows:
- TITLE: The title of the song.
- COMPOSER: Name of composer, if different for each track.
- COPYRIGHT: Copyright notice, if different for each track.
- UNIXTIME: The UNIX timestamp (as an integer in decimal notation, with an optional - for times before the UNIX epoch). The third part here, if used, is an amount of microseconds, not the same thing in UTF-8.
- DURATION: The estimated duration in seconds, given as an integer in decimal notation. The third part here, if used, is an amount of microseconds, not the same thing in UTF-8.
- COMMENT: A comment text. You can use CRLF to make line breaks, and form feeds for page breaks.
- LOOP: Two numbers, with the ASCII unit separator in between, with purposes similar to the Loop Base and Loop Modifier of VGM format. The player might use this instead of (or in addition to) the default loop count, or it might ignore both.
- FOLLOW-TRACK: If this track does not loop, the specified track is played next. (This is mainly designed for use with MegaZeux.)
The play order table is a list of one-byte zero-based pattern numbers.
Patterns
A pattern consists of a command list. Each entry in the command list is either a macro number followed by the arguments, or 255 followed by a command list as in a macro definition.
If the macro commands are used here, then commands numbered $40 to $7F now have a different meaning than inside of macros, which is to delay a number of frames equal to the given number minus $40, and then terminate both the command list and the pattern.
Sound chips
You can use the talk page for discussion of proposals and so on. They can also be posted directly on here if agreed with.
Software
None is currently known.