public static void main(String[] args) throws Exception { RIFFWriter writer = null; RIFFReader reader = null; File tempfile = File.createTempFile("test", ".riff"); try { writer = new RIFFWriter(tempfile, "TEST"); RIFFWriter chunk = writer.writeChunk("TSCH"); chunk.writeByte((byte) 33); writer.close(); writer = null; FileInputStream fis = new FileInputStream(tempfile); reader = new RIFFReader(fis); assertEquals(reader.getFormat(), "RIFF"); assertEquals(reader.getType(), "TEST"); RIFFReader readchunk = reader.nextChunk(); assertEquals(readchunk.getFormat(), "TSCH"); assertEquals((int) reader.readByte(), 33); fis.close(); reader = null; } finally { if (writer != null) writer.close(); if (reader != null) reader.close(); if (tempfile.exists()) if (!tempfile.delete()) tempfile.deleteOnExit(); } }
public void write(AudioInputStream stream, RIFFWriter writer) throws IOException { RIFFWriter fmt_chunk = writer.writeChunk("fmt "); AudioFormat format = stream.getFormat(); fmt_chunk.writeUnsignedShort(3); // WAVE_FORMAT_IEEE_FLOAT fmt_chunk.writeUnsignedShort(format.getChannels()); fmt_chunk.writeUnsignedInt((int) format.getSampleRate()); fmt_chunk.writeUnsignedInt(((int) format.getFrameRate()) * format.getFrameSize()); fmt_chunk.writeUnsignedShort(format.getFrameSize()); fmt_chunk.writeUnsignedShort(format.getSampleSizeInBits()); fmt_chunk.close(); RIFFWriter data_chunk = writer.writeChunk("data"); byte[] buff = new byte[1024]; int len; while ((len = stream.read(buff, 0, buff.length)) != -1) data_chunk.write(buff, 0, len); data_chunk.close(); }
public int write(AudioInputStream stream, Type fileType, File out) throws IOException { checkFormat(fileType, stream); if (stream.getFormat().isBigEndian()) stream = toLittleEndian(stream); RIFFWriter writer = new RIFFWriter(out, "WAVE"); write(stream, writer); int fpointer = (int) writer.getFilePointer(); writer.close(); return fpointer; }
private void writeInfo(RIFFWriter writer) throws IOException { if (this.targetEngine == null) this.targetEngine = "EMU8000"; if (this.name == null) this.name = ""; RIFFWriter ifil_chunk = writer.writeChunk("ifil"); ifil_chunk.writeUnsignedShort(this.major); ifil_chunk.writeUnsignedShort(this.minor); writeInfoStringChunk(writer, "isng", this.targetEngine); writeInfoStringChunk(writer, "INAM", this.name); writeInfoStringChunk(writer, "irom", this.romName); if (romVersionMajor != -1) { RIFFWriter iver_chunk = writer.writeChunk("iver"); iver_chunk.writeUnsignedShort(this.romVersionMajor); iver_chunk.writeUnsignedShort(this.romVersionMinor); } writeInfoStringChunk(writer, "ICRD", this.creationDate); writeInfoStringChunk(writer, "IENG", this.engineers); writeInfoStringChunk(writer, "IPRD", this.product); writeInfoStringChunk(writer, "ICOP", this.copyright); writeInfoStringChunk(writer, "ICMT", this.comments); writeInfoStringChunk(writer, "ISFT", this.tools); writer.close(); }
private void writeSoundbank(RIFFWriter writer) throws IOException { writeInfo(writer.writeList("INFO")); writeSdtaChunk(writer.writeList("sdta")); writePdtaChunk(writer.writeList("pdta")); writer.close(); }