/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
//$$fb this class is buggy. Should be replaced in future.
/**
* AIFF file writer.
*
* @author Jan Borgersen
*/
/**
* Constructs a new AiffFileWriter object.
*/
public AiffFileWriter() {
}
// METHODS TO IMPLEMENT AudioFileWriter
// make sure we can write this stream
return filetypes;
}
}
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException {
//$$fb the following check must come first ! Otherwise
// the next frame length check may throw an IOException and
// interrupt iterating File Writers. (see bug 4351296)
// throws IllegalArgumentException if not supported
// we must know the total data length to calculate the file length
throw new IOException("stream length not specified");
}
return bytesWritten;
}
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {
// throws IllegalArgumentException if not supported
// first write the file without worrying about length fields
// now, if length fields were not specified, calculate them,
// open as a random access file, write the appropriate fields,
// close again....
// $$kk: 10.22.99: jan: please either implement this or throw an exception!
// $$fb: 2001-07-13: done. Fixes Bug 4479981
int ssndBlockSize = (aiffFileFormat.getFormat().getChannels() * aiffFileFormat.getFormat().getSampleSizeInBits());
int aiffLength=bytesWritten;
// skip FORM magic
// skip aiff2 magic, fver chunk, comm magic, comm size, channel count,
// write frame count
// skip sample size, samplerate, SSND magic
// that's all
}
return bytesWritten;
}
// -----------------------------------------------------------------------
/**
* Returns the AudioFileFormat describing the file that will be written from this AudioInputStream.
* Throws IllegalArgumentException if not supported.
*/
float sampleRate;
int sampleSizeInBits;
int channels;
int frameSize;
float frameRate;
int fileSize;
boolean convert8to16 = false;
}
sampleSizeInBits=16;
convert8to16 = true;
} else {
// can't convert non-8-bit ALAW,ULAW
throw new IllegalArgumentException("Encoding " + streamEncoding + " supported only for 8-bit data.");
}
} else {
}
true); // AIFF is big endian
if( convert8to16 ) {
fileSize = (int)stream.getFrameLength()*streamFormat.getFrameSize()*2 + AiffFileFormat.AIFF_HEADERSIZE;
} else {
fileSize = (int)stream.getFrameLength()*streamFormat.getFrameSize() + AiffFileFormat.AIFF_HEADERSIZE;
}
} else {
}
(int)stream.getFrameLength() );
return fileFormat;
}
private int writeAiffFile(InputStream in, AiffFileFormat aiffFileFormat, OutputStream out) throws IOException {
int bytesRead = 0;
int bytesWritten = 0;
byte buffer[] = new byte[bisBufferSize];
if (maxLength>0) {
} else {
maxLength = 0;
break;
}
} else {
}
}
return bytesWritten;
}
private InputStream getFileStream(AiffFileFormat aiffFileFormat, InputStream audioStream) throws IOException {
// private method ... assumes aiffFileFormat is a supported file format
//$$fb a little bit nicer handling of constants
//int headerSize = 54;
//int fverChunkSize = 0;
//int commChunkSize = 26;
int aiffLength = -1;
int ssndChunkSize = -1;
//int ssndOffset = headerSize - 16;
long dataSize = -1;
}
// if we need to do any format conversion, do it here....
if( audioStream instanceof AudioInputStream ) {
// $$jb: Note that AIFF samples are ALWAYS signed
// plug in the transcoder to convert to PCM_SIGNED. big endian
true ),
throw new IllegalArgumentException("unsupported encoding");
}
//$$fb 2001-07-13: this is probably not what we want:
// plug in the transcoder to convert to PCM_SIGNED_BIG_ENDIAN
true ),
}
}
// Now create an AIFF stream header...
baos = new ByteArrayOutputStream();
// Write the outer FORM chunk
// Write a FVER chunk - only for AIFC
//dos.writeInt(FVER_MAGIC);
//dos.writeInt( (fverChunkSize-8) );
//dos.writeInt(FVER_TIMESTAMP);
// Write a COMM chunk
//Only for AIFC
//dos.writeInt(compCode);
//dos.writeInt(compCode);
//dos.writeShort(0);
// Write the SSND chunk header
// ssndOffset and ssndBlockSize set to 0 upon
// recommendation in "Sound Manager" chapter in
// "Inside Macintosh Sound", pp 2-87 (from Babu)
// Concat this with the audioStream and return it
return aiffStream;
}
// HELPER METHODS
/**
* Extended precision IEEE floating-point conversion routine.
* @argument DataOutputStream
* @argument double
* @exception IOException
*/
/* The special cases NaN, Infinity and Zero are ignored, since
they do not represent useful sample rates anyway.
Denormalized number aren't handled, too. Below, there is a cast
from float to double. We hope that in this conversion,
numbers are normalized. Numbers that cannot be normalized are
ignored, too, as they, too, do not represent useful sample rates. */
long extendedMantissa = doubleMantissa
}
}