private void addBytesToTrackSequential(int addr, int length) {
   if (length > 0) {
     mem.memcpy(bufBytes.bufferAddr + bufBytes.writeOffset, addr, length);
     bufBytes.writeOffset += length;
     bufBytes.sizeAvailableForRead += length;
   }
 }
  public void addBytesToTrack(int addr, int length) {
    int length1 = Math.min(length, bufBytes.totalSize - bufBytes.writeOffset);
    addBytesToTrackSequential(addr, length1);

    int length2 = length - length1;
    if (length2 > 0) {
      bufBytes.writeOffset = 0;
      addBytesToTrackSequential(addr + length1, length2);
    }
  }
  public void readBytes(int addr, int length) {
    length = Math.min(length, bufBytes.sizeAvailableForRead);
    if (length > 0) {
      int length1 = Math.min(length, bufBytes.totalSize - bufBytes.readOffset);
      mem.memcpy(addr, bufBytes.bufferAddr + bufBytes.readOffset, length1);

      int length2 = length - length1;
      if (length2 > 0) {
        mem.memcpy(addr + length1, bufBytes.bufferAddr, length2);
      }

      bufBytes.notifyRead(length);
    }
  }
 public void addSamplesToTrack(int samples) {
   bufSamples.sizeAvailableForRead += samples;
   currentSample += samples;
 }