/** Write NumBytes data. */ public int Write(RiffChunkHeader Triff_header, int NumBytes) { byte[] br = new byte[8]; br[0] = (byte) ((Triff_header.ckID >>> 24) & 0x000000FF); br[1] = (byte) ((Triff_header.ckID >>> 16) & 0x000000FF); br[2] = (byte) ((Triff_header.ckID >>> 8) & 0x000000FF); br[3] = (byte) (Triff_header.ckID & 0x000000FF); byte br4 = (byte) ((Triff_header.ckSize >>> 24) & 0x000000FF); byte br5 = (byte) ((Triff_header.ckSize >>> 16) & 0x000000FF); byte br6 = (byte) ((Triff_header.ckSize >>> 8) & 0x000000FF); byte br7 = (byte) (Triff_header.ckSize & 0x000000FF); br[4] = br7; br[5] = br6; br[6] = br5; br[7] = br4; if (fmode != RFM_WRITE) { return DDC_INVALID_CALL; } try { file.write(br, 0, NumBytes); fmode = RFM_WRITE; } catch (IOException ioe) { return DDC_FILE_ERROR; } riff_header.ckSize += NumBytes; return DDC_SUCCESS; }
/** Dummy Constructor */ public RiffFile() { file = null; fmode = RFM_UNKNOWN; riff_header = new RiffChunkHeader(); riff_header.ckID = FourCC("RIFF"); riff_header.ckSize = 0; }
/** Write NumBytes data. */ public int Write(byte[] Data, int NumBytes) { if (fmode != RFM_WRITE) { return DDC_INVALID_CALL; } try { file.write(Data, 0, NumBytes); fmode = RFM_WRITE; } catch (IOException ioe) { return DDC_FILE_ERROR; } riff_header.ckSize += NumBytes; return DDC_SUCCESS; }
/** Write NumBytes data. */ public int Write(short Data, int NumBytes) { short theData = (short) (((Data >>> 8) & 0x00FF) | ((Data << 8) & 0xFF00)); if (fmode != RFM_WRITE) { return DDC_INVALID_CALL; } try { file.writeShort(theData); fmode = RFM_WRITE; } catch (IOException ioe) { return DDC_FILE_ERROR; } riff_header.ckSize += NumBytes; return DDC_SUCCESS; }
/** Write NumBytes data. */ public int Write(int Data, int NumBytes) { short theDataL = (short) ((Data >>> 16) & 0x0000FFFF); short theDataR = (short) (Data & 0x0000FFFF); short theDataLI = (short) (((theDataL >>> 8) & 0x00FF) | ((theDataL << 8) & 0xFF00)); short theDataRI = (short) (((theDataR >>> 8) & 0x00FF) | ((theDataR << 8) & 0xFF00)); int theData = ((theDataRI << 16) & 0xFFFF0000) | (theDataLI & 0x0000FFFF); if (fmode != RFM_WRITE) { return DDC_INVALID_CALL; } try { file.writeInt(theData); fmode = RFM_WRITE; } catch (IOException ioe) { return DDC_FILE_ERROR; } riff_header.ckSize += NumBytes; return DDC_SUCCESS; }
/** Write NumBytes data. */ public int Write(short[] Data, int NumBytes) { byte[] theData = new byte[NumBytes]; int yc = 0; for (int y = 0; y < NumBytes; y = y + 2) { theData[y] = (byte) (Data[yc] & 0x00FF); theData[y + 1] = (byte) ((Data[yc++] >>> 8) & 0x00FF); } if (fmode != RFM_WRITE) { return DDC_INVALID_CALL; } try { file.write(theData, 0, NumBytes); fmode = RFM_WRITE; } catch (IOException ioe) { return DDC_FILE_ERROR; } riff_header.ckSize += NumBytes; return DDC_SUCCESS; }
/** Open a RIFF file. */ public int Open(String Filename, int NewMode) { int retcode = DDC_SUCCESS; if (fmode != RFM_UNKNOWN) { retcode = Close(); } if (retcode == DDC_SUCCESS) { switch (NewMode) { case RFM_WRITE: try { file = new RandomAccessFile(Filename, "rw"); try { // Write the RIFF header... // We will have to come back later and patch it! byte[] br = new byte[8]; br[0] = (byte) ((riff_header.ckID >>> 24) & 0x000000FF); br[1] = (byte) ((riff_header.ckID >>> 16) & 0x000000FF); br[2] = (byte) ((riff_header.ckID >>> 8) & 0x000000FF); br[3] = (byte) (riff_header.ckID & 0x000000FF); byte br4 = (byte) ((riff_header.ckSize >>> 24) & 0x000000FF); byte br5 = (byte) ((riff_header.ckSize >>> 16) & 0x000000FF); byte br6 = (byte) ((riff_header.ckSize >>> 8) & 0x000000FF); byte br7 = (byte) (riff_header.ckSize & 0x000000FF); br[4] = br7; br[5] = br6; br[6] = br5; br[7] = br4; file.write(br, 0, 8); fmode = RFM_WRITE; } catch (IOException ioe) { file.close(); fmode = RFM_UNKNOWN; } } catch (IOException ioe) { fmode = RFM_UNKNOWN; retcode = DDC_FILE_ERROR; } break; case RFM_READ: try { file = new RandomAccessFile(Filename, "r"); try { // Try to read the RIFF header... byte[] br = new byte[8]; file.read(br, 0, 8); fmode = RFM_READ; riff_header.ckID = ((br[0] << 24) & 0xFF000000) | ((br[1] << 16) & 0x00FF0000) | ((br[2] << 8) & 0x0000FF00) | (br[3] & 0x000000FF); riff_header.ckSize = ((br[4] << 24) & 0xFF000000) | ((br[5] << 16) & 0x00FF0000) | ((br[6] << 8) & 0x0000FF00) | (br[7] & 0x000000FF); } catch (IOException ioe) { file.close(); fmode = RFM_UNKNOWN; } } catch (IOException ioe) { fmode = RFM_UNKNOWN; retcode = DDC_FILE_ERROR; } break; default: retcode = DDC_INVALID_CALL; } } return retcode; }