protected void convertToDouble(byte[] in, int len, double[] out, int start)
  {
    int db = 0;

    if(frameSize == 1)
    {
      //8-bit signed PCM
      for (int i = 0; i < len; i += frameSize)
        out[start++] = ((double) in[i]) * scale;
    }
    else
    {
      //more than one byte per sample
      if(isBigEndian)
      {
        //the bytes of one sample value are in big-Endian order
        //first byte will be converted to int with respect to the sign
        db = (int) in[0];
        for (int i = 1, j = frameSize; i < len; i++)
        {
          if(i == j)//finished one sample?
          {
            //convert to double value (and rescale for compatibility to the matlab implementation)
            out[start++] = ((double) db) * scale;
            //first byte will be converted to int with respect to the sign
            db = (int) in[i];
            //set the end of the next sample value
            j += frameSize;
          }
          else
          {
            //combine the bytes of the sample (unsigned bytes)
            db = db << 8 | ((int) in[i] & 0xff);
          }
        }
        //convert to double value (and rescale for compatibility to the matlab implementation)
        out[start++] = ((double) db) * scale;
      }
      else
      {
        //the bytes of one sample value are in little-Endian order
        for (int i = 0; i < len; i += frameSize)
        {
          //first byte will be converted to int with respect to the sign
          db = (int) in[i + frameSize - 1];

          //combine the bytes of the sample (unsigned bytes) in reversed order
          for (int b = frameSize - 2; b >= 0; b--)
            db = db << 8 | ((int) in[i + b] & 0xff);

          //convert to double value (and rescale for compatibility to the matlab implementation)
          out[start++] = ((double) db) * scale;
        }
      }
    }
  }