Skip to content

Latest commit

 

History

History
90 lines (57 loc) · 2.2 KB

CS-98-026_5.md

File metadata and controls

90 lines (57 loc) · 2.2 KB

...menustart

...menuend

Sound: WTF is nesmus doing?

  • call nesmus_loop each frame
  • nesmus binary format
    • Types: start/end loop, note data
    • Which channels are affected
    • 4 bytes data per channe

Music Channels

Music Channel Enable

  • 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

Music Channels 0-1

  • 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)

Music Wavelength

  • 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)

Pitch to Wavelength

  • 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

Demonstration

  • calculate
    • A 440
    • 111875 / 440 - 1 = 253.261
    • binary(253) = %11111101
  • use sndtest.nes to test