private int readBytesFormBuffer(byte[] buffer, int start, int bytesToRead) throws IOException
  {
      int sample = 0;
      int bytesRead = 0;

      while(bytesRead < bytesToRead)
      {
        //read left channel
        sample = readSample();

        if(reduceChannels)
        {
          //there are two channels and therefore two samples per frame
          sample += readSample();

          //prevent overflow
          if(sample > 32767)
            sample = 32767;
          if(sample < -32768)
            sample = -32768;
        }

        //check if we still read vaild data
        if(pos < bytesInBuffer)
        {
          //write sample to output buffer
          buffer[start++] = (byte) (sample & 0xff);
          buffer[start++] = (byte) ((sample >> 8) & 0xff);
          bytesRead += 2;

          //jump to next frame
          pos += skipSize;
        }
        else
        {
          //undo last readSample operation
          if(reduceChannels)
            pos -= 2*sampleSize;
          else
            pos -= sampleSize;

          //try to fill buffer
          if (endOfFile)
          {
            if(bytesRead > 0)
              return bytesRead;
            else
              return -1;
          }
          else
          {
            refillBuffer();
          }
        }
      }

      return bytesRead;
  }