< prev index next >

src/java.desktop/share/classes/com/sun/media/sound/AiffFileWriter.java

Print this page

        

*** 57,67 **** */ public AiffFileWriter() { super(new AudioFileFormat.Type[]{AudioFileFormat.Type.AIFF}); } - // METHODS TO IMPLEMENT AudioFileWriter @Override public AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) { --- 57,66 ----
*** 81,91 **** } return new AudioFileFormat.Type[0]; } - @Override public int write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException { Objects.requireNonNull(stream); Objects.requireNonNull(fileType); Objects.requireNonNull(out); --- 80,89 ----
*** 100,114 **** // we must know the total data length to calculate the file length if( stream.getFrameLength() == AudioSystem.NOT_SPECIFIED ) { throw new IOException("stream length not specified"); } ! int bytesWritten = writeAiffFile(stream, aiffFileFormat, out); ! return bytesWritten; } - @Override public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException { Objects.requireNonNull(stream); Objects.requireNonNull(fileType); Objects.requireNonNull(out); --- 98,110 ---- // we must know the total data length to calculate the file length if( stream.getFrameLength() == AudioSystem.NOT_SPECIFIED ) { throw new IOException("stream length not specified"); } ! return writeAiffFile(stream, aiffFileFormat, out); } @Override public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException { Objects.requireNonNull(stream); Objects.requireNonNull(fileType); Objects.requireNonNull(out);
*** 127,142 **** // close again.... if( aiffFileFormat.getByteLength()== AudioSystem.NOT_SPECIFIED ) { // $$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; int ssndChunkSize=aiffLength-aiffFileFormat.getHeaderSize()+16; long dataSize=ssndChunkSize-16; ! int numFrames=(int) (dataSize*8/ssndBlockSize); RandomAccessFile raf=new RandomAccessFile(out, "rw"); // skip FORM magic raf.skipBytes(4); raf.writeInt(aiffLength-8); --- 123,141 ---- // close again.... if( aiffFileFormat.getByteLength()== AudioSystem.NOT_SPECIFIED ) { // $$kk: 10.22.99: jan: please either implement this or throw an exception! // $$fb: 2001-07-13: done. Fixes Bug 4479981 ! int channels = aiffFileFormat.getFormat().getChannels(); ! int sampleSize = aiffFileFormat.getFormat().getSampleSizeInBits(); ! int ssndBlockSize = channels * ((sampleSize + 7) / 8); int aiffLength=bytesWritten; int ssndChunkSize=aiffLength-aiffFileFormat.getHeaderSize()+16; long dataSize=ssndChunkSize-16; ! //TODO possibly incorrect round ! int numFrames = (int) (dataSize / ssndBlockSize); RandomAccessFile raf=new RandomAccessFile(out, "rw"); // skip FORM magic raf.skipBytes(4); raf.writeInt(aiffLength-8);
*** 171,186 **** AudioFormat.Encoding encoding = AudioFormat.Encoding.PCM_SIGNED; AudioFormat streamFormat = stream.getFormat(); AudioFormat.Encoding streamEncoding = streamFormat.getEncoding(); - - float sampleRate; int sampleSizeInBits; - int channels; - int frameSize; - float frameRate; int fileSize; boolean convert8to16 = false; if( (AudioFormat.Encoding.ALAW.equals(streamEncoding)) || (AudioFormat.Encoding.ULAW.equals(streamEncoding)) ) { --- 170,180 ----
*** 233,243 **** (int)stream.getFrameLength() ); return fileFormat; } - private int writeAiffFile(InputStream in, AiffFileFormat aiffFileFormat, OutputStream out) throws IOException { int bytesRead = 0; int bytesWritten = 0; InputStream fileStream = getFileStream(aiffFileFormat, in); --- 227,236 ----
*** 273,301 **** AudioFormat format = aiffFileFormat.getFormat(); AudioFormat streamFormat = null; AudioFormat.Encoding encoding = null; //$$fb a little bit nicer handling of constants - - //int headerSize = 54; int headerSize = aiffFileFormat.getHeaderSize(); - //int fverChunkSize = 0; int fverChunkSize = aiffFileFormat.getFverChunkSize(); - //int commChunkSize = 26; int commChunkSize = aiffFileFormat.getCommChunkSize(); int aiffLength = -1; int ssndChunkSize = -1; - //int ssndOffset = headerSize - 16; int ssndOffset = aiffFileFormat.getSsndChunkOffset(); short channels = (short) format.getChannels(); short sampleSize = (short) format.getSampleSizeInBits(); ! int ssndBlockSize = (channels * sampleSize); int numFrames = aiffFileFormat.getFrameLength(); long dataSize = -1; if( numFrames != AudioSystem.NOT_SPECIFIED) { ! dataSize = (long) numFrames * ssndBlockSize / 8; ssndChunkSize = (int)dataSize + 16; aiffLength = (int)dataSize+headerSize; } float sampleFramesPerSecond = format.getSampleRate(); int compCode = AiffFileFormat.AIFC_PCM; --- 266,289 ---- AudioFormat format = aiffFileFormat.getFormat(); AudioFormat streamFormat = null; AudioFormat.Encoding encoding = null; //$$fb a little bit nicer handling of constants int headerSize = aiffFileFormat.getHeaderSize(); //int fverChunkSize = 0; int fverChunkSize = aiffFileFormat.getFverChunkSize(); int commChunkSize = aiffFileFormat.getCommChunkSize(); int aiffLength = -1; int ssndChunkSize = -1; int ssndOffset = aiffFileFormat.getSsndChunkOffset(); short channels = (short) format.getChannels(); short sampleSize = (short) format.getSampleSizeInBits(); ! int ssndBlockSize = channels * ((sampleSize + 7) / 8); int numFrames = aiffFileFormat.getFrameLength(); long dataSize = -1; if( numFrames != AudioSystem.NOT_SPECIFIED) { ! dataSize = (long) numFrames * ssndBlockSize; ssndChunkSize = (int)dataSize + 16; aiffLength = (int)dataSize+headerSize; } float sampleFramesPerSecond = format.getSampleRate(); int compCode = AiffFileFormat.AIFC_PCM;
*** 401,413 **** return aiffStream; } - - - // HELPER METHODS private static final int DOUBLE_MANTISSA_LENGTH = 52; private static final int DOUBLE_EXPONENT_LENGTH = 11; private static final long DOUBLE_SIGN_MASK = 0x8000000000000000L; --- 389,398 ----
*** 450,457 **** long extendedBits63To0 = EXTENDED_INTEGER_MASK | extendedMantissa; dos.writeShort(extendedBits79To64); dos.writeLong(extendedBits63To0); } - - } --- 435,440 ----
< prev index next >