Debian Codegraph @

android/app/jni/papers/newIns.md

raw
1 # new Furnace instrument format
2
3 the main issue with Furnace instrument files is that they are too big, even if the instrument is nothing more than the FM setup...
4
5 the aim of this new format is to greatly reduce the size of a resulting instrument.
6
7 # information
8
9 this format is "featural", meaning that only used parameters are stored (depending on instrument types).
10 this is the biggest improvement over the previous format, which stored everything including unused parameters.
11
12 features which are not recognized by Furnace will be ignored.
13
14 instruments are not compressed using zlib, unlike Furnace songs.
15
16 all numbers are little-endian.
17
18 the following fields may be found in "size":
19 - `f` indicates a floating point number.
20 - `STR` is a UTF-8 zero-terminated string.
21 - `???` is an array of variable size.
22 - `S??` is an array of `STR`s.
23 - `1??` is an array of bytes.
24 - `2??` is an array of shorts.
25 - `4??` is an array of ints.
26
27 the format may change across versions. a `(>=VER)` indicates this field is only present starting from format version `VER`, and `(<VER)` indicates this field is present only before version `VER`.
28
29 furthermore, an `or reserved` indicates this field is always present, but is reserved when the version condition is not met.
30
31 the `size of this block` fields represent the size of a block excluding the ID and the aforementioned field.
32
33 # header
34
35 .fui files use the following header:
36
37 ```
38 size | description
39 -----|------------------------------------
40 4 | "FINS" format magic
41 2 | format version
42 2 | instrument type
43 ??? | features...
44 ```
45
46 instruments in a .fur file use the following header instead:
47
48 ```
49 size | description
50 -----|------------------------------------
51 4 | "INS2" block ID
52 4 | size of this block
53 2 | format version
54 2 | instrument type
55 ??? | features...
56 ```
57
58 a feature uses the following format:
59
60 ```
61 size | description
62 -----|------------------------------------
63 2 | feature code
64 2 | length of block
65 ??? | data...
66 ```
67
68 the following instrument types are available:
69
70 - 0: SN76489
71 - 1: FM (OPN)
72 - 2: Game Boy
73 - 3: C64
74 - 4: Amiga/sample
75 - 5: PC Engine
76 - 6: AY-3-8910
77 - 7: AY8930
78 - 8: TIA
79 - 9: SAA1099
80 - 10: VIC
81 - 11: PET
82 - 12: VRC6
83 - 13: OPLL
84 - 14: OPL
85 - 15: FDS
86 - 16: Virtual Boy
87 - 17: Namco 163
88 - 18: SCC
89 - 19: OPZ
90 - 20: POKEY
91 - 21: PC Speaker
92 - 22: WonderSwan
93 - 23: Lynx
94 - 24: VERA
95 - 25: X1-010
96 - 26: VRC6 (saw)
97 - 27: ES5506
98 - 28: MultiPCM
99 - 29: SNES
100 - 30: Sound Unit
101 - 31: Namco WSG
102 - 32: OPL (drums)
103 - 33: FM (OPM)
104 - 34: NES
105 - 35: MSM6258
106 - 36: MSM6295
107 - 37: ADPCM-A
108 - 38: ADPCM-B
109 - 39: SegaPCM
110 - 40: QSound
111 - 41: YMZ280B
112 - 42: RF5C68
113 - 43: MSM5232
114 - 44: T6W28
115 - 45: K007232
116 - 46: GA20
117 - 47: Pokémon Mini/QuadTone
118 - 48: SM8521
119 - 49: PV-1000
120 - 50: K053260
121 - 52: TED
122 - 53: C140
123 - 54: C219
124 - 55: ESFM
125 - 56: PowerNoise (noise)
126 - 57: PowerNoise (slope)
127 - 58: Dave
128 - 59: NDS
129 - 60: GBA DMA
130 - 61: GBA MinMod
131 - 62: Bifurcator
132 - 63: SID2
133 - 64: Supervision
134 - 65: µPD1771C
135 - 66: SID3
136
137 the following feature codes are recognized:
138
139 - `NA`: instrument name
140 - `FM`: FM ins data
141 - `MA`: macro data
142 - `64`: C64 ins data
143 - `GB`: Game Boy ins data
144 - `SM`: sample ins data
145 - `O1`: operator 1 macros
146 - `O2`: operator 2 macros
147 - `O3`: operator 3 macros
148 - `O4`: operator 4 macros
149 - `LD`: OPL drums mode data
150 - `SN`: SNES ins data
151 - `N1`: Namco 163 ins data
152 - `FD`: FDS/Virtual Boy ins data
153 - `WS`: wavetable synth data
154 - `SL`: list of samples (<233)
155 - `WL`: list of wavetables (<233)
156 - `LS`: list of samples (>=233)
157 - `LW`: list of wavetables (>=233)
158 - `MP`: MultiPCM ins data
159 - `SU`: Sound Unit ins data
160 - `ES`: ES5506 ins data
161 - `X1`: X1-010 ins data
162 - `NE`: NES DPCM sample map data
163 - `EF`: ESFM ins data
164 - `PN`: PowerNoise ins data
165 - `S2`: SID2 ins data
166 - `S3`: SID3 ins data
167 - `EN`: end of features
168 - if you find this feature code, stop reading the instrument.
169 - it will usually appear only when there are sample/wave lists.
170 - instruments in a .fur shall end with this feature code.
171
172 # instrument name (NA)
173
174 ```
175 size | description
176 -----|------------------------------------
177 STR | instrument name
178 ```
179
180 # FM data (FM)
181
182 - FM operator order is:
183 - 1/3/2/4 (internal order) for OPN, OPM, OPZ and OPL 4-op
184 - 1/2/?/? (? = unused) for OPL 2-op and OPLL
185
186 ```
187 size | description
188 -----|------------------------------------
189 1 | flags
190 | - bit 4-7: op enabled
191 | - op order from 4 to 7: 0, 2, 1, 3
192 | - 2-op instruments: 0, 1, x, x
193 | - bit 0-3: op count
194 -----|------------------------------------
195 | **base data**
196 | /7 6 5 4 3 2 1 0|
197 1 | |x| ALG |x| FB |
198 1 | |FMS2 |AMS| FMS |
199 1 | |AM2|4| LLPatch |
200 1 | |xxxxxxx| Block | (>=224)
201 -----|------------------------------------
202 | **operator data × opCount**
203 | /7 6 5 4 3 2 1 0|
204 1 | |r| D T | MULT |
205 | \- KSR
206 1 | |s| T L |
207 | \- SUS
208 1 | |R S|v| A R |
209 | \- VIB
210 1 | |A|KSL| D R |
211 | \- AM
212 1 | |e|KVS| D2R |
213 | \- EGT
214 1 | | S L | R R |
215 1 | | DVB | SSG |
216 1 | | DAM |DT2| W S |
217 ```
218
219 # macro data (MA)
220
221 notes:
222
223 - the macro range varies depending on the instrument type.
224 - "macro open" indicates whether the macro is collapsed or not in the instrument editor.
225 - meaning of extended macros varies depending on instrument type.
226 - meaning of panning macros varies depending on instrument type:
227 - for hard-panned chips (e.g. FM and Game Boy): left panning is 2-bit panning macro (left/right)
228 - otherwise both left and right panning macros are used
229
230 ```
231 size | description
232 -----|------------------------------------
233 2 | length of macro header
234 ??? | data...
235 ```
236
237 each macro is represented like this:
238
239 ```
240 size | description
241 -----|------------------------------------
242 1 | macro code
243 | - 0: vol
244 | - 1: arp
245 | - 2: duty
246 | - 3: wave
247 | - 4: pitch
248 | - 5: ex1
249 | - 6: ex2
250 | - 7: ex3
251 | - 8: alg
252 | - 9: fb
253 | - 10: fms
254 | - 11: ams
255 | - 12: panL
256 | - 13: panR
257 | - 14: phaseReset
258 | - 15: ex4
259 | - 16: ex5
260 | - 17: ex6
261 | - 18: ex7
262 | - 19: ex8
263 | - 20: ex9
264 | - 21: ex10
265 | - 255: stop reading and move on
266 1 | macro length
267 1 | macro loop
268 1 | macro release
269 1 | macro mode
270 1 | macro open/type/word size
271 | - bit 6-7: word size
272 | - 0: 8-bit unsigned
273 | - 1: 8-bit signed
274 | - 2: 16-bit signed
275 | - 3: 32-bit signed
276 | - bit 3: instant release (>=182)
277 | - bit 1-2: type
278 | - 0: normal
279 | - 1: ADSR
280 | - 2: LFO
281 | - bit 0: open
282 1 | macro delay
283 1 | macro speed
284 ??? | macro data
285 | - length: macro length × word size
286 ```
287
288 ## interpreting macro mode values
289
290 - sequence (normal): I think this is obvious...
291 - ADSR:
292 - `val[0]`: bottom
293 - `val[1]`: top
294 - `val[2]`: attack
295 - `val[3]`: hold time
296 - `val[4]`: decay
297 - `val[5]`: sustain level
298 - `val[6]`: sustain hold time
299 - `val[7]`: decay 2
300 - `val[8]`: release
301 - LFO:
302 - `val[11]`: speed
303 - `val[12]`: waveform
304 - 0: triangle
305 - 1: saw
306 - 2: pulse
307 - `val[13]`: phase
308 - `val[14]`: loop
309 - `val[15]`: global (not sure how will I implement this)
310
311 # C64 data (64)
312
313 ```
314 size | description
315 -----|------------------------------------
316 1 | flags 1
317 | - bit 7: dutyIsAbs
318 | - bit 6: initFilter
319 | - bit 5: volIsCutoff (<187)
320 | - from version 187 onwards, volume and cutoff macros are separate.
321 | - if this is on and the version is less than 187, move the volume macro into the ALG one.
322 | - bit 4: toFilter
323 | - bit 3: noise on
324 | - bit 2: pulse on
325 | - bit 1: saw on
326 | - bit 0: triangle on
327 1 | flags 2
328 | - bit 7: oscSync
329 | - bit 6: ringMod
330 | - bit 5: noTest
331 | - bit 4: filterIsAbs
332 | - bit 3: ch3off
333 | - bit 2: band pass
334 | - bit 1: high pass
335 | - bit 0: low pass
336 1 | attack/decay
337 | - bit 4-7: attack
338 | - bit 0-3: decay
339 1 | sustain release
340 | - bit 4-7: sustain
341 | - bit 0-3: release
342 2 | duty
343 2 | cutoff/resonance
344 | - bit 12-15: resonance
345 | - bit 0-10: cutoff (0-11 on SID2)
346 1 | upper nibble of resonance (for SID2) (>=199)
347 | - bits 0-3 hold this upper nibble
348 | - bit 4: reset duty on new note (>=222)
349 ```
350
351 ## C64 compatibility note (>=187)
352
353 in Furnace dev187 the volume and cutoff macros have been separated, as noted above.
354 however, there are two other changes as well: **inverted relative (non-absolute) cutoff macro**; and a new, improved Special macro.
355
356 if version is less than 187, you must convert the Special macro:
357 1. do not continue if ex4 is not a Sequence type macro!
358 2. move bit 0 of ex4 macro data into bit 3.
359 3. set bit 0 on all steps of ex4 macro to 1.
360 4. if ex3 is not a Sequence type macro, stop here.
361 5. if ex3 macro length is 0, stop here.
362 6. merge the ex3 macro (former Special) into ex4 (former Test).
363 - use the largest size (between ex3 and ex4).
364 - if the ex3 macro is shorter than the ex4 one, use the last value of ex3, and vice-versa.
365 - if the ex4 macro length is 0, expand it to the largest size, and set all steps to 1.
366
367 don't worry about loop or release...
368
369 # Game Boy data (GB)
370
371 ```
372 size | description
373 -----|------------------------------------
374 1 | envelope params
375 | - bit 5-7: length
376 | - bit 4: direction
377 | - bit 0-3: volume
378 1 | sound length
379 | - 64 is infinity
380 1 | flags
381 | - bit 2: double wave width for GBA (>=196)
382 | - bit 1: always init envelope
383 | - bit 0: software envelope (zombie mode)
384 1 | hardware sequence length
385 ??? | hardware sequence...
386 | - length: 3*hwSeqLen
387 ```
388
389 a value in the hardware sequence has the following format:
390
391 ```
392 size | description
393 -----|------------------------------------
394 1 | command
395 | - 0: set envelope
396 | - 1: set sweep
397 | - 2: wait
398 | - 3: wait for release
399 | - 4: loop
400 | - 5: loop until release
401 2 | data
402 | - for set envelope:
403 | - 1 byte: parameter
404 | - bit 4-7: volume
405 | - bit 3: direction
406 | - bit 0-2: length
407 | - 1 byte: sound length
408 | - for set sweep:
409 | - 1 byte: parameter
410 | - bit 4-6: length
411 | - bit 3: direction
412 | - bit 0-2: shift
413 | - 1 byte: nothing
414 | - for wait:
415 | - 1 byte: length (in ticks)
416 | - 1 byte: nothing
417 | - for wait for release:
418 | - 2 bytes: nothing
419 | - for loop/loop until release:
420 | - 2 bytes: position
421 ```
422
423 # sample ins data (SM)
424
425 ```
426 size | description
427 -----|------------------------------------
428 2 | initial sample
429 1 | flags
430 | - bit 2: use wave
431 | - bit 1: use sample
432 | - bit 0: use sample map
433 1 | waveform length
434 4?? | sample map... (120 entries)
435 | - only read if sample map is enabled
436 ```
437
438 the sample map format:
439
440 ```
441 size | description
442 -----|------------------------------------
443 2 | note to play (>=152) or reserved
444 2 | sample to play
445 ```
446
447 # operator macro data (O1, O2, O3 and O4)
448
449 similar to macro data, but using these macro codes:
450
451 - 0: AM
452 - 1: AR
453 - 2: DR
454 - 3: MULT
455 - 4: RR
456 - 5: SL
457 - 6: TL
458 - 7: DT2
459 - 8: RS
460 - 9: DT
461 - 10: D2R
462 - 11: SSG-EG
463 - 12: DAM
464 - 13: DVB
465 - 14: EGT
466 - 15: KSL
467 - 16: SUS
468 - 17: VIB
469 - 18: WS
470 - 19: KSR
471
472 # OPL drums mode data (LD)
473
474 ```
475 size | description
476 -----|------------------------------------
477 1 | fixed frequency mode
478 2 | kick freq
479 2 | snare/hat freq
480 2 | tom/top freq
481 ```
482
483 # SNES data (SN)
484
485 ```
486 size | description
487 -----|------------------------------------
488 1 | attack/decay
489 | - bit 4-6: decay
490 | - bit 0-3: attack
491 1 | sustain/release
492 | - bit 5-7: sustain
493 | - bit 0-4: release
494 1 | flags
495 | - bit 4: envelope on
496 | - bit 3: make sustain effective (<131)
497 | - bit 0-2: gain mode
498 | - 0: direct
499 | - 4: dec
500 | - 5: exp
501 | - 6: inc
502 | - 7: bent
503 1 | gain
504 1 | decay 2/sustain mode (>=131)
505 | - bit 5-6: sustain mode
506 | - 0: direct
507 | - 1: sustain (release with dec)
508 | - 2: sustain (release with exp)
509 | - 3: sustain (release with rel)
510 | - bit 0-4: decay 2
511 ```
512
513 # Namco 163 data (N1)
514
515 ```
516 size | description
517 -----|------------------------------------
518 4 | waveform
519 1 | wave pos
520 1 | wave len
521 1 | wave mode
522 | **extra info** (>=164)
523 1 | enable per channel wave pos/len
524 8 | per channel wave pos
525 | - only read if enabled.
526 8 | per channel wave len
527 | - only read if enabled.
528 ```
529
530 # FDS/Virtual Boy data (FD)
531
532 ```
533 size | description
534 -----|------------------------------------
535 4 | mod speed
536 4 | mod depth
537 1 | init mod table with first wave
538 1?? | modulation table (32 entries)
539 ```
540
541 # wavetable synth data (WS)
542
543 ```
544 size | description
545 -----|------------------------------------
546 4 | first wave
547 4 | second wave
548 1 | rate divider
549 1 | effect
550 | - bit 7: single or dual effect
551 1 | enabled
552 1 | global
553 1 | speed (+1)
554 1 | parameter 1
555 1 | parameter 2
556 1 | parameter 3
557 1 | parameter 4
558 ```
559
560 # old list of samples (SL) (<233)
561
562 ```
563 size | description
564 -----|------------------------------------
565 1 | number of samples
566 1?? | sample indexes...
567 4?? | pointers to samples...
568 | - these use the Furnace sample format.
569 ```
570
571 # old list of wavetables (WL) (<233)
572
573 ```
574 size | description
575 -----|------------------------------------
576 1 | number of wavetables
577 1?? | wavetable indexes...
578 4?? | pointers to wavetables...
579 | - these use the Furnace wavetable format.
580 ```
581
582 # new list of samples (LS) (>=233)
583
584 ```
585 size | description
586 -----|------------------------------------
587 2 | number of samples
588 2?? | sample indexes...
589 4?? | pointers to samples...
590 | - these use the Furnace sample format.
591 ```
592
593 # new list of wavetables (LW) (>=233)
594
595 ```
596 size | description
597 -----|------------------------------------
598 2 | number of wavetables
599 2?? | wavetable indexes...
600 4?? | pointers to wavetables...
601 | - these use the Furnace wavetable format.
602 ```
603
604 # MultiPCM data (MP)
605
606 ```
607 size | description
608 -----|------------------------------------
609 1 | attack rate
610 1 | decay 1 rate
611 1 | decay level
612 1 | decay 2 rate
613 1 | release rate
614 1 | rate correction
615 1 | LFO rate
616 1 | vibrato depth
617 1 | AM depth
618 1 | flags (>=221)
619 | - bit 0: damp
620 | - bit 1: pseudo-reverb
621 | - bit 2: LFO reset
622 | - bit 3: level direct
623 ```
624
625 # Sound Unit data (SU)
626
627 ```
628 size | description
629 -----|------------------------------------
630 1 | switch roles of phase reset timer and frequency
631 1 | hardware sequence length (>=185)
632 ??? | hardware sequence...
633 | - length: 5*hwSeqLen
634 ```
635
636 a value in the hardware sequence has the following format:
637
638 ```
639 size | description
640 -----|------------------------------------
641 1 | command
642 | - 0: set volume sweep
643 | - 1: set frequency sweep
644 | - 2: set cutoff sweep
645 | - 3: wait
646 | - 4: wait for release
647 | - 5: loop
648 | - 6: loop until release
649 1 | sweep bound
650 1 | sweep amount/command data
651 | - if "set sweep", this is amount.
652 | - for wait: length in ticks
653 | - for wait for release: nothing
654 | - for loop/loop until release: position
655 2 | sweep period
656 ```
657
658 # ES5506 data (ES)
659
660 ```
661 size | description
662 -----|------------------------------------
663 1 | filter mode
664 | - 0: HPK2_HPK2
665 | - 1: HPK2_LPK1
666 | - 2: LPK2_LPK2
667 | - 3: LPK2_LPK1
668 2 | K1
669 2 | K2
670 2 | envelope count
671 1 | left volume ramp
672 1 | right volume ramp
673 1 | K1 ramp
674 1 | K2 ramp
675 1 | K1 slow
676 1 | K2 slow
677 ```
678
679 # X1-010 data (X1)
680
681 ```
682 size | description
683 -----|------------------------------------
684 4 | bank slot
685 ```
686
687 # NES DPCM sample map data (NE)
688
689 ```
690 size | description
691 -----|------------------------------------
692 1 | use sample map
693 2?? | DPCM sample map... (120 entries)
694 | - only read if sample map is enabled
695 ```
696
697 the DPCM sample map format:
698
699 ```
700 size | description
701 -----|------------------------------------
702 1 | pitch (0-15; otherwise no change)
703 1 | delta counter value (0-127; otherwise no change)
704 ```
705
706 if some fields are missing, that's because they are defined in the SM feature.
707 NES instruments with DPCM sample maps have both SM and NE features.
708
709 # PowerNoise data (PN)
710
711 ```
712 size | description
713 -----|------------------------------------
714 1 | octave
715 ```
716
717 # SID2 data (S2)
718
719 ```
720 size | description
721 -----|------------------------------------
722 1 | parameters
723 | - bit 6-7: noise mode
724 | - bit 4-5: wave mix mode
725 | - bit 0-3: volume
726 ```
727
728 # SID3 data (S3)
729
730 ```
731 size | description
732 -----|------------------------------------
733 1 | flags 1
734 | - bit 7: dutyIsAbs
735 | - bit 3: noise on
736 | - bit 2: pulse on
737 | - bit 1: saw on
738 | - bit 0: triangle on
739 1 | attack
740 1 | decay
741 1 | sustain
742 1 | sustain rate
743 1 | release
744 1 | wave mix mode
745 2 | duty
746 1 | flags 2
747 | - bit 7: phase modulation
748 | - bit 6: enable special wave
749 | - bit 5: 1-bit noise
750 | - bit 4: separate noise pitch
751 | - bit 3: do wavetable
752 | - bit 2: reset duty on new note
753 | - bit 1: osc sync
754 | - bit 0: ring mod
755 1 | phase modulation source channel
756 1 | ring modulation source channel
757 1 | hard sync source channel
758 1 | special wave
759 1 | flags 3
760 | - bit 1: left channel signal inversion
761 | - bit 0: right channel signal inversion
762 1 | feedback
763 1 | number of filters
764 ```
765
766 then, `number of filters` times, come settings for each filter:
767
768 ```
769 size | description
770 -----|------------------------------------
771 1 | parameters
772 | - bit 7: enable filter
773 | - bit 6: initialize filter
774 | - bit 5: absolute cutoff macro
775 | - bit 4: enable cutoff scaling
776 | - bit 3: decrease cutoff when pitch increases (for cutoff scaling)
777 | - bit 2: scale cutoff only once, on new note
778 | - bit 1: enable resonance scaling
779 | - bit 0: decrease resonance when pitch increases (for resonance scaling)
780 1 | parameters
781 | - bit 7: scale resonance only once, on new note
782 2 | filter cutoff
783 1 | filter resonance
784 1 | filter output volume
785 1 | filter distortion level
786 1 | filter mode:
787 | - bit 5: connect filter output to channel master output
788 | - bit 4: connect filter input to channel ADSR output
789 | - bit 2: band pass
790 | - bit 1: high pass
791 | - bit 0: low pass
792 1 | matrix connection:
793 | - bit 3: connect output of filter 4 to input
794 | - bit 2: connect output of filter 3 to input
795 | - bit 1: connect output of filter 2 to input
796 | - bit 0: connect output of filter 1 to input
797 1 | cutoff scaling level
798 1 | cutoff scaling center note: `0` is `c_5`, `1` is `c+5`, ..., `179` is `B-9`
799 1 | resonance scaling level
800 1 | resonance scaling center note: `0` is `c_5`, `1` is `c+5`, ..., `179` is `B-9`
801 ```