def pulse_period(cpu_frequency, note_frequency):
  """ Approximate pulse period that produces the desired frequency

  Taken from https://wiki.nesdev.com/w/index.php/APU_Pulse
  16 comes from the length of the pulse sequence counter (8) 
  times two CPU cycles per one APU cycle (2)

  When used as the triangle period, whose sequence is 32 cycles
  long instead of 16, this results in a transposition of one
  octave.
  """
  return int(cpu_frequency / (16 * note_frequency) - 1)