; DikuMUD NES - instruments and drums (from the TW2002 NES port) (tools/gen_music.py; format in docs/SOUND.md).
;
; inst NAME env=... [vib=D/DEPTH/PERIOD | arp=.. | arph=.. | pit=.. | pith=.. | slide=STEP/N] [delay=N]
;          [rate=R]  (the envelope and the modulation step every 2^R frames instead of every frame)
;   env: one value a frame (0-15), the last one held; dN sets the duty of the values after it
;        (d0 12.5%, d1 25%, d2 50%, d3 75%); V*N repeats; A-B ramps by 1 (A-B/K: K frames each).
;   vib: a sine of PERIOD frames (power of 2) and DEPTH quarter semitones, after D frames.
;   arp / arph: semitone offsets a frame, looping (power-of-2 length) / holding the last.
;   pit / pith: quarter-semitone offsets a frame, looping / holding.  slide=S/N: 0, S, 2S .. NS
;   quarter semitones, held.  (Positive = up.  On the noise, a semitone = one noise period.)
; drum LETTER INST NOISE  - a noise-channel letter: instrument and noise period (0-15, +16 = mode 1)
; Up to 62 instruments; the envelope pool and the modulation pool hold 256 bytes each.

; ---- pulse: melody
inst lead    env=d1,12,11,10,9,9,8                     rate=1   vib=5/1/4
inst leads   env=d1,12,10,8,6,4,3,2,1,0                rate=1   ; short, bouncy
inst brass   env=d2,9,12,11,10,10,9                    rate=1   pith=-3,-1,0
inst echo    env=d1,4,5,4,4,3                          rate=1   vib=5/1/4
inst soft    env=d2,4,6,7,6,6,5,5,4                    rate=1   vib=8/1/8
inst bell    env=d0,12,10,8,7,6,5,4,3,2,1,0                       rate=1
inst pluck   env=d2,9,7,5,4,3,2,1,0                    rate=1
inst fade    env=d2,8,7,6,5,4,3,2,1,0                             rate=4   ; a last note dying away
; ---- pulse: chords (one frame a step)
inst arpM    env=d2,8,6,5,4,4,3                     rate=1   arp=0,4,7,12
inst arpm    env=d2,8,6,5,4,4,3                     rate=1   arp=0,3,7,12
inst arp7    env=d2,8,6,5,4,4,3                     rate=1   arp=0,4,7,10
inst arpm7   env=d2,8,6,5,4,4,3                     rate=1   arp=0,3,7,10
inst arpM7   env=d2,8,6,5,4,4,3                     rate=1   arp=0,4,7,11
inst arpd    env=d2,8,6,5,4,4,3                     rate=1   arp=0,3,6,9
inst arpfM   env=d2,6*5,5*5,4*5,3*5,2*5,1*5,0          rate=1   arp=0,4,7,12
inst arpfm   env=d2,6*5,5*5,4*5,3*5,2*5,1*5,0          rate=1   arp=0,3,7,12
inst arpsoft env=d2,3,4,5,5,4                          rate=1   arp=0,4,7,11   ; maj7
inst arpsoftm env=d2,3,4,5,5,4                         rate=1   arp=0,3,7,10   ; m7
inst arpsoft5 env=d2,3,4,5,5,4                         rate=1   arp=0,4,7,12   ; major
; ---- triangle (any volume above 0 = on)
inst bass    env=15
inst bass8   env=15,0                                  rate=3   ; 8 frames
inst bass16  env=15,0                                  rate=2   ; 4 frames
inst tkick   env=15*5,0                                           arph=24,16,10,5,1,0
; ---- noise
inst nkick   env=13,10,7,4,2,0                                    arph=0,2,3,4
inst nsnare  env=12,11,9,8,6,5,4,3,2,1,0                          arph=0,1,2,2
inst nhat    env=5,3,1,0
inst nohat   env=6,5,4,4,3,3,2,2,1,1,0
inst ncrash  env=11,10,9,8,7,6,5,4,3,2,1,0                        rate=2
inst nsoft   env=3,2,1,0
; ---- effects
inst sxblip  env=d1,12,11,8,5,2,0
inst sxsel   env=d2,13,12,11,10,9,8,7,6,5,4,3,2,1,0
inst sxsweep env=d1,6,8,10,12                                     slide=4/24
inst sxwarp  env=d1,12*6,11-0                                     rate=1   pit=0,2
inst sxwhoosh env=2,4,6,8,10*3,9-0                               rate=2   arph=0,-1,-2,-3,-4,-5,-6,-7
inst sxcoin  env=d1,13,12,11,10,9,8,7,6,5,4,3,2,1,0
inst sxbuzz  env=d2,13                                            pit=0,-6
inst sxboom  env=15,15,14-0                                       rate=2   arph=0,1,2,3,4,5,6,7,8
inst sxrumble env=d2,12,11-0                                      rate=2   slide=-2/10
inst sxalarm env=d1,12                                            pit=0,0,2,2
inst sxlaser env=d1,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0                 slide=-5/9
inst sxtick  env=9,5,2,0

drum k nkick   10
drum s nsnare  6
drum h nhat    1
drum o nohat   2
drum c ncrash  3
drum t nsoft   1

; ---- added for the DikuMUD songs (most reuse an envelope already in the pool)
inst flute   env=d2,6,8,9,8,8,7                        rate=1   vib=10/1/8   ; town: a hollow flute
inst lute    env=d2,7,5,4,3,2,1,0                      rate=1   ; town: a short plucked string
inst harp    env=d2,5,4,3,2,1,0                        rate=2   ; wild: a softer, longer pluck
inst ghost   env=d1,2,3,4,5,5,4                        rate=2   vib=8/2/16   ; dark: thin, slow swell, wavering
inst ghoste  env=d0,1,2,2,1                            rate=2   vib=8/2/16   ; dark: its faint echo
inst arpx    env=d1,8,6,5,4,4,3                        rate=2   arp=0,3,7,12 ; matrix: a slow minor arp (4 frames a note)
inst arpMx   env=d1,8,6,5,4,4,3                        rate=2   arp=0,4,7,12 ; ... major
inst nwind   env=3,3,2,2,1,1,0                         rate=4   pit=0,4,0,-4 ; dark: a soft gust of wind
drum w nwind   9
drum d nsoft   18
