...menustart
...menuend
- call nesmus_loop each frame
- nesmus binary format
- Types: start/end loop, note data
- Which channels are affected
- 4 bytes data per channe
- Use bitmask to register to enable/disable sound channels
- set $4015 %1111
- enables all four channels
- set $4015 %11111
- enable all five channels (DMC PCM)
- set $4017 %10000000
- probably want this, for correct pitch
- Square waves ($4000-$4003, $4004-$4007)
- Important things to note
- volume (byte 0, bits 0-3)
- length counter enable (byte 0, bit 5)
- length counter load (byte 3, bits 3-7)
- wavelength (11-bit value)
- Wavelength is an ugly 11-bit value based on clock cycles
- 8 LSB of wavelength (byte 2)
- 3 MSB of wavelength (byte 3, bits 0-2)
- Clock cycles are counted at 1.79 MHz
- Sound uses the internal 60 Hz LFO for clock, instead of internal 240 Hz LFO
- This and other funkiness magically gives us a sound-specific clock rate of 1.79 MHz / 16
- Musicians are likely to want a specific frequency (in Hz).We need an easy formula to convert to the ugly 11-bit wavelength.
ugly number = (1.79 MHz / 16) / freq - 1
= (111875 / freq) - 1
- calculate
- A 440
- 111875 / 440 - 1 = 253.261
- binary(253) = %11111101
- use sndtest.nes to test