public RcRiffHeaderChunk() { super(); this.setChunkId(RcRiffBwf.RC_RIFF_HEADER_CHUNK_ID); this.setFormat(RcRiffHeaderChunk.RC_RIFF_FORMAT_WAVE); }
@Override public long read(RandomAccessFile in, long ptr, long chunkSize) throws IOException { this.setPtr(ptr); this.setChunkSize(chunkSize); long bytesRead = 0L; // Read RIFF format this.setFormat(RcRiffFile.readAscii(in, RcRiffHeaderChunk.FORMAT_LENGTH)); bytesRead += RcRiffHeaderChunk.FORMAT_LENGTH; //System.out.println("\tFormat: " + this.getFormat()); return bytesRead; }
RcRiffHeaderChunk rcRiffHeaderChunk = new RcRiffHeaderChunk(); rcRiffHeaderChunk.setChunkId(RcRiffBwf.RC_RIFF_HEADER_CHUNK_ID); rcRiffHeaderChunk.setChunkSize(0); // We will rewrite this value rcRiffHeaderChunk.setFormat(RcRiffHeaderChunk.RC_RIFF_FORMAT_WAVE); riffSize += rcRiffHeaderChunk.write(out);
RcRiffHeaderChunk rcRiffHeaderChunk = new RcRiffHeaderChunk(); riffBytesRead += rcRiffHeaderChunk.read(this.in, ptr, chunkSize); if (!rcRiffHeaderChunk.getFormat().equals(RcRiffHeaderChunk.RC_RIFF_FORMAT_WAVE)) { riffBytesRead -= RcRiffChunk.SIZE_OF_CHUNK_SIZE; if (riffBytesRead < this.getRcRiffHeaderChunk().getChunkSize()) { (this.getRcRiffHeaderChunk().getChunkSize() - riffBytesRead) + " bytes."); else if (riffBytesRead > this.getRcRiffHeaderChunk().getChunkSize()) { (riffBytesRead - this.getRcRiffHeaderChunk().getChunkSize()) + " extra bytes.");
/** * Updates the marker chunk. * * Note: The file must have been opened read / write and the maker chunk * must be the last chunk in the BWF file. * * @throws IOException * @throws RcBwfException */ public void updateMarkerChunk() throws IOException, RcBwfException { if (!this.canUpdateMarkerChunk()) { throw new IOException("The marker chunk is not updatable."); } // Overwrite marker chunk long sizeBefore = this.rcRiffMarkerChunk.getChunkSize(); this.in.seek(this.rcRiffMarkerChunk.getPtr()); this.rcRiffMarkerChunk.write(in); long sizeAfter = this.rcRiffMarkerChunk.getChunkSize(); long sizeDiff = sizeAfter - sizeBefore; this.rcRiffHeaderChunk.setChunkSize(this.rcRiffHeaderChunk.getChunkSize() + sizeDiff); // Update header this.in.seek(4); RcRiffFile.writeUnsignedInt(in, this.rcRiffHeaderChunk.getChunkSize()); // Trim file length if necessary if (sizeDiff < 0) { long length = this.in.length(); this.in.setLength(length + sizeDiff); } }
@Override public long write(RandomAccessFile out) throws IOException, RcBwfException { String exPrefix = "Unable to write RIFF header chunk - "; if (this.getFormat() == null) { throw new IOException( exPrefix + "format is null."); } if (this.getFormat().trim().length() != RcRiffHeaderChunk.FORMAT_LENGTH) { throw new IOException( exPrefix + "format length must be " + RcRiffHeaderChunk.FORMAT_LENGTH + " characters."); } // Write chunk id and chunk size long chunkHeaderSize = super.write(out); // Write format Long chunkDataSize = 0L; chunkDataSize += RcRiffFile.writeAscii(out, this.getFormat().trim()); return chunkHeaderSize + chunkDataSize; }