Fix the RingBuffer implementation

* ReadableCount() previously returned wrong values: for example:

    0 1 2 3 4 5 6 7 8 9        N=10
        W     R

  There are 7 readable elements (5,6,7,8,9,0,1), but ReadableCount() previously
  returned (r - w) which is 3.

* WritableCount() allowed the buffer to get full even though the RingBuffer API
  specified that you should never let the buffer fill up.
Fix the Mixer issues reported by degasus

* Swap and exchange samples in the audio thread instead of the CPU thread.
* Move static variables to class instance variables.
* Pad incomplete buffers by repeating the last value instead of 0.