< prev index next >

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

Print this page

        

@@ -57,11 +57,10 @@
      */
     public AiffFileWriter() {
         super(new AudioFileFormat.Type[]{AudioFileFormat.Type.AIFF});
     }
 
-
     // METHODS TO IMPLEMENT AudioFileWriter
 
     @Override
     public AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) {
 

@@ -81,11 +80,10 @@
         }
 
         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);

@@ -100,15 +98,13 @@
         // 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;
+        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);

@@ -171,16 +167,11 @@
         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)) ) {

@@ -233,11 +224,10 @@
                                          (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);

@@ -273,29 +263,24 @@
         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 ssndBlockSize = channels * ((sampleSize + 7) / 8);
         int numFrames                   = aiffFileFormat.getFrameLength();
         long dataSize            = -1;
         if( numFrames != AudioSystem.NOT_SPECIFIED) {
-            dataSize = (long) numFrames * ssndBlockSize / 8;
+            dataSize = (long) numFrames * ssndBlockSize;
             ssndChunkSize = (int)dataSize + 16;
             aiffLength = (int)dataSize+headerSize;
         }
         float sampleFramesPerSecond = format.getSampleRate();
         int compCode = AiffFileFormat.AIFC_PCM;

@@ -401,13 +386,10 @@
 
         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;

@@ -450,8 +432,6 @@
         long extendedBits63To0 = EXTENDED_INTEGER_MASK | extendedMantissa;
 
         dos.writeShort(extendedBits79To64);
         dos.writeLong(extendedBits63To0);
     }
-
-
 }
< prev index next >