Ejemplo n.º 1
0
 public final short readShort() throws IOException {
   short s = mRaf.readShort();
   if (mIsLittleEndian) {
     return (short) (((s & 0x00ff) << 8) | ((s & 0xff00) >>> 8));
   }
   return s;
 }
Ejemplo n.º 2
0
 /** {@inheritDoc} */
 public short readShort() throws IOException {
   fileSize -= 2;
   if (fileSize < 0) {
     throw new EOFException();
   }
   return dataInput.readShort();
 }
Ejemplo n.º 3
0
  private void loadDataXM(RandomAccessFile fp) throws IOException {
    byte[] b = new byte[20];

    // WHY THE HELL AM I DOING THIS
    name = Util.readStringNoNul(fp, b, 20);
    System.out.printf("name: \"%s\"\n", name);
    fp.read(); // skip 0x1A byte

    // THIS CAN'T BE HAPPENING
    fp.read(b, 0, 20); // skip tracker name

    // OH HELL NO
    int xmver = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    System.out.printf("XM version: %04X\n", xmver);

    // WHAT IS THIS CRAP
    InhibitedFileBlock ifb = new InhibitedFileBlock(fp, Integer.reverseBytes(fp.readInt()) - 4);

    // HELP ME PLEASE
    int ordnum = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int respos =
        0xFFFF & (int) Short.reverseBytes(ifb.readShort()); // can't be bothered right now --GM
    int chnnum =
        0xFFFF & (int) Short.reverseBytes(ifb.readShort()); // yeah sure, allow out of range values
    if (chnnum > 64)
      throw new RuntimeException(
          String.format("%d-channel modules not supported (max 64)", chnnum));
    int patnum = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int insnum = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int xmflags = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int xmspeed = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int xmtempo = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());

    // OH PLEASE, STOP IT
    if (ordnum > 255) ordnum = 255;
    if (xmtempo > 255) xmtempo = 255;
    if (xmspeed > 255) xmspeed = 255;
    this.bpm = xmtempo;
    this.spd = xmspeed;
    this.flags = FLAG_COMPATGXX | FLAG_OLDEFFECTS | FLAG_INSMODE | FLAG_STEREO | FLAG_VOL0MIX;

    if ((xmflags & 0x01) != 0) this.flags |= FLAG_LINEAR;

    // NONONONONONO
    System.out.printf("chn=%d ordnum=%d tempo=%d speed=%s\n", chnnum, ordnum, xmtempo, xmspeed);
    for (int i = 0; i < 256; i++) orderlist[i] = ifb.read();
    for (int i = ordnum; i < 256; i++) orderlist[i] = 255;

    ifb.done();

    // SAVE ME PLEEEEEAAASSSSEEEE
    for (int i = 0; i < patnum; i++)
      map_pat.put((Integer) i, new SessionPattern(this, fp, SessionPattern.FORMAT_XM, chnnum));
    for (int i = 0; i < insnum; i++)
      map_ins.put((Integer) (i + 1), new SessionInstrument(fp, SessionInstrument.FORMAT_XM, this));
  }
 private static void alterLastIFDOffset(RandomAccessFile rFile, int fileLen) throws IOException {
   rFile.seek(0);
   rFile.skipBytes(4);
   int offsetIFD = rFile.readInt();
   while (true) {
     rFile.seek(offsetIFD);
     int dirs = rFile.readShort();
     rFile.skipBytes(dirs * 12);
     offsetIFD = rFile.readInt();
     if (offsetIFD == 0) {
       int pointer = (int) rFile.getFilePointer();
       rFile.seek(pointer - 4);
       rFile.writeInt(fileLen);
       break;
     }
   }
 }
Ejemplo n.º 5
0
  /**
   * Get the next rtp packet recorded in the rtpdump file.
   *
   * @param loopFile if true, when the end of the rtpdump file is reached, this
   *     <tt>RtpdumpFileReader</tt> will go back at the beginning of the file and get the first
   *     packet.
   * @return a <tt>RawPacket</tt> containing all the information and data of the next rtp packet
   *     recorded in the rtpdump file
   * @throws IOException if <tt>loopFile</tt> was false and the end of the file is reached.
   */
  public RawPacket getNextPacket(boolean loopFile) throws IOException {
    if (loopFile && (stream.getFilePointer() >= stream.length())) {
      resetFile();
    }

    byte[] rtpdumpPacket;
    int sizeInBytes;

    stream.readShort(); // read away an useless short (2 bytes)
    sizeInBytes = stream.readUnsignedShort();
    rtpdumpPacket = new byte[sizeInBytes];
    stream.readInt(); // read away the rtpdump timestamp

    stream.read(rtpdumpPacket);

    return new RawPacket(rtpdumpPacket, 0, rtpdumpPacket.length);
  }
  public RecordRange seek(String pattern, int size) {
    RandomAccessFile currentFile = file[size - 1];
    long pos, mid, head, tail;
    short strLen;
    byte buf[] = new byte[strSize];

    try {
      head = 0;
      tail = currentFile.length() / recLen - 1;

      while (head <= tail) {
        mid = (head + tail) / 2;
        pos = mid * recLen;
        currentFile.seek(pos);
        strLen = currentFile.readShort();
        currentFile.read(buf, 0, strLen);
        String str = new String(buf, 0, strLen);

        int cmp = pattern.compareTo(str);

        if (cmp < 0) tail = mid - 1;
        else if (cmp > 0) head = mid + 1;
        else {
          currentFile.seek(pos + lenSize + strSize);
          int spageID = currentFile.readInt();
          int soffset = currentFile.readInt();
          int epageID = currentFile.readInt();
          int eoffset = currentFile.readInt();

          return new RecordRange(new RID(spageID, soffset), new RID(epageID, eoffset));
        }
      }

    } catch (IOException e) {
      e.printStackTrace();
    }

    return null;
  }
Ejemplo n.º 7
0
  private void loadDataIT(RandomAccessFile fp) throws IOException {
    byte[] b = new byte[26];

    this.name = Util.readString(fp, b, 26);
    System.out.printf("name: \"%s\"\n", name);

    this.philigt = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int ordnum = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int insnum = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int smpnum = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int patnum = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    this.cwtv = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    this.cmwt = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    this.flags = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    this.special = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    this.gv = fp.read();
    this.mv = fp.read();
    this.spd = fp.read();
    this.bpm = fp.read();
    this.pwd = fp.read();
    this.sep = fp.read();
    int msglgth = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int msgoffs = Integer.reverseBytes(fp.readInt());
    this.timestamp = Integer.reverseBytes(fp.readInt());
    fp.read(chnpan, 0, 64);
    fp.read(chnvol, 0, 64);

    System.out.printf("ver: %04X / compat: %04X\n", cwtv, cmwt);

    // Load orderlist
    for (int i = 0; i < ordnum; i++) orderlist[i] = fp.readUnsignedByte();
    for (int i = ordnum; i < 256; i++) orderlist[i] = 255;

    // Load pointers
    int[] insptrs = new int[insnum];
    int[] smpptrs = new int[smpnum];
    int[] patptrs = new int[patnum];

    for (int i = 0; i < insnum; i++) insptrs[i] = Integer.reverseBytes(fp.readInt());
    for (int i = 0; i < smpnum; i++) smpptrs[i] = Integer.reverseBytes(fp.readInt());
    for (int i = 0; i < patnum; i++) patptrs[i] = Integer.reverseBytes(fp.readInt());

    // TODO: read MIDI + timestamp bollocks
    //   TODO: look up and/or reverse engineer said bollocks

    // Load data
    for (int i = 0; i < insnum; i++) {
      if (insptrs[i] != 0) {
        fp.seek(insptrs[i]);
        map_ins.put(
            (Integer) (i + 1),
            new SessionInstrument(
                fp,
                cmwt < 0x200 ? SessionInstrument.FORMAT_IT100 : SessionInstrument.FORMAT_IT200));
      }
    }

    for (int i = 0; i < smpnum; i++) {
      if (smpptrs[i] != 0) {
        fp.seek(smpptrs[i]);
        map_smp.put((Integer) (i + 1), new SessionSample(fp, SessionSample.FORMAT_IT));
      }
    }

    for (int i = 0; i < patnum; i++) {
      if (patptrs[i] != 0) {
        fp.seek(patptrs[i]);
        map_pat.put((Integer) i, new SessionPattern(this, fp, SessionPattern.FORMAT_IT));
      }
    }
  }
Ejemplo n.º 8
0
  private void loadDataS3M(RandomAccessFile fp) throws IOException {
    byte[] b = new byte[28];

    this.name = Util.readString(fp, b, 28);
    System.out.printf("name: \"%s\"\n", name);

    fp.readInt(); // first two bytes we've seen, second two are unused

    int ordnum = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int smpnum = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int patnum = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int s3flags = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int s3cwtv = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int ffi = 0xFFFF & (int) Short.reverseBytes(fp.readShort());

    fp.readInt(); // should have "SCRM" but really doesn't matter

    this.flags = FLAG_OLDEFFECTS | FLAG_VOL0MIX;

    this.gv = fp.read() * 2;
    this.spd = fp.read();
    this.bpm = fp.read();
    this.mv = fp.read();
    fp.read(); // NO WE DON'T HAVE A GUS
    int dfpflag = fp.read();

    // weird S3M crap
    // note: assuming default of 6/125
    // it actually uses the previously-used speed/tempo

    if (this.spd == 0 || this.spd == 255) this.spd = 6;
    if (this.bpm < 33) this.bpm = 125;

    if ((this.mv & 0x80) != 0) {
      this.mv &= ~0x80;
      this.flags |= FLAG_STEREO;
      // XXX: this might need to be done internally in the player
      //      if it turns out that IT does the same damn thing --GM
      this.mv = (this.mv * 11 + 4) >> 3;
    }

    // skip all that bollocks
    fp.seek(0x40);

    // load channel mappings
    // yes, we WILL want these!
    // though i don't think anyone's done anything completely bonkers
    // except Storlek and myself --GM
    int[] st3chnmap = new int[32];

    for (int i = 32; i < 64; i++) {
      chnvol[i] = (byte) 0xC0;
      chnpan[i] = 0x20;
    }

    for (int i = 0; i < 32; i++) {
      chnpan[i] = 0;

      int v = fp.read();
      st3chnmap[i] = v & 0x7F;

      // don't enable FM channels!
      chnvol[i] = ((v & 0x80) != 0 && (v & 0x7F) < 16) ? 0x40 : (byte) 0xC0;
    }

    // orderlist!
    // DON'T EVEN NEED TO FILTER IT YES :D
    for (int i = 0; i < ordnum; i++) orderlist[i] = fp.read();
    for (int i = ordnum; i < 256; i++) orderlist[i] = 255;

    // load pointers
    int[] smpptrs = new int[smpnum];
    int[] patptrs = new int[patnum];

    for (int i = 0; i < smpnum; i++)
      smpptrs[i] = (0xFFFF & (int) Short.reverseBytes(fp.readShort())) * 16;
    for (int i = 0; i < patnum; i++)
      patptrs[i] = (0xFFFF & (int) Short.reverseBytes(fp.readShort())) * 16;

    // load default panning if necessary
    for (int i = 0; i < 32; i++) {
      int v = (dfpflag == 252) ? fp.read() : 0x10;

      int pan =
          (v & 0x10) != 0 ? (flags & FLAG_STEREO) != 0 ? (v & 0x08) != 0 ? 0xC : 0x3 : 0x7 : v & 15;

      // TODO: scale this crap correctly
      chnpan[i] = (byte) ((pan + 2) << 2);
    }

    // load data
    for (int i = 0; i < smpnum; i++)
      if (smpptrs[i] != 0) {
        fp.seek(smpptrs[i]);
        map_smp.put((Integer) (i + 1), new SessionSample(fp, SessionSample.FORMAT_S3M, ffi));
      }
    for (int i = 0; i < patnum; i++)
      if (patptrs[i] != 0) {
        fp.seek(patptrs[i]);
        map_pat.put(
            (Integer) i, new SessionPattern(this, fp, SessionPattern.FORMAT_S3M, st3chnmap));
      }

    // XXX: any other crap this needs? --GM
  }
Ejemplo n.º 9
0
 /** This reads a binary short from the file. */
 public short readBinaryShort(int col, int row) throws IOException {
   raf.seek(row * nBytesPerRow + columnStartAt[col]);
   return raf.readShort();
 }
Ejemplo n.º 10
0
 /** Read and set the program counter */
 public static void loader() throws IOException {
   file.seek(0);
   short code_offset = file.readShort();
   cpu.R[15] = code_offset;
 }
Ejemplo n.º 11
0
 /* @see java.io.DataInput.readShort() */
 public short readShort() throws IOException {
   return raf.readShort();
 }