< prev index next >
src/java.desktop/share/classes/com/sun/media/sound/AuFileReader.java
Print this page
*** 27,37 ****
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
- import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFileFormat.Type;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
--- 27,36 ----
*** 43,64 ****
* @author Florian Bomers
*/
public final class AuFileReader extends SunFileReader {
@Override
! public AudioFileFormat getAudioFileFormatImpl(final InputStream stream)
throws UnsupportedAudioFileException, IOException {
final DataInputStream dis = new DataInputStream(stream);
final int magic = dis.readInt();
if (magic != AuFileFormat.AU_SUN_MAGIC) {
// not AU, throw exception
throw new UnsupportedAudioFileException("not an AU file");
}
final int headerSize = dis.readInt();
! final int dataSize = dis.readInt();
final int auType = dis.readInt();
final int sampleRate = dis.readInt();
final int channels = dis.readInt();
if (channels <= 0) {
throw new UnsupportedAudioFileException("Invalid number of channels");
--- 42,63 ----
* @author Florian Bomers
*/
public final class AuFileReader extends SunFileReader {
@Override
! public StandardFileFormat getAudioFileFormatImpl(final InputStream stream)
throws UnsupportedAudioFileException, IOException {
final DataInputStream dis = new DataInputStream(stream);
final int magic = dis.readInt();
if (magic != AuFileFormat.AU_SUN_MAGIC) {
// not AU, throw exception
throw new UnsupportedAudioFileException("not an AU file");
}
final int headerSize = dis.readInt();
! final long /* unsigned int */ dataSize = dis.readInt() & 0xffffffffL;
final int auType = dis.readInt();
final int sampleRate = dis.readInt();
final int channels = dis.readInt();
if (channels <= 0) {
throw new UnsupportedAudioFileException("Invalid number of channels");
*** 118,140 ****
*/
default:
// unsupported filetype, throw exception
throw new UnsupportedAudioFileException("not a valid AU file");
}
final int frameSize = calculatePCMFrameSize(sampleSizeInBits, channels);
//$$fb 2002-11-02: fix for 4629669: AU file reader: problems with empty files
- final int length;
- if (dataSize < 0) {
- length = AudioSystem.NOT_SPECIFIED;
- } else {
//$$fb 2003-10-20: fix for 4940459: AudioInputStream.getFrameLength() returns 0 instead of NOT_SPECIFIED
! length = dataSize / frameSize;
}
- // now seek past the header
- dis.skipBytes(headerSize - AuFileFormat.AU_HEADERSIZE);
final AudioFormat format = new AudioFormat(encoding, sampleRate,
sampleSizeInBits, channels,
frameSize, sampleRate, true);
! return new AuFileFormat(Type.AU, dataSize + headerSize, format, length);
}
}
--- 117,139 ----
*/
default:
// unsupported filetype, throw exception
throw new UnsupportedAudioFileException("not a valid AU file");
}
+ // now seek past the header
+ dis.skipBytes(headerSize - AuFileFormat.AU_HEADERSIZE);
final int frameSize = calculatePCMFrameSize(sampleSizeInBits, channels);
//$$fb 2002-11-02: fix for 4629669: AU file reader: problems with empty files
//$$fb 2003-10-20: fix for 4940459: AudioInputStream.getFrameLength() returns 0 instead of NOT_SPECIFIED
! long frameLength = AudioSystem.NOT_SPECIFIED;
! long byteLength = AudioSystem.NOT_SPECIFIED;
! if (dataSize != AuFileFormat.UNKNOWN_SIZE) {
! frameLength = dataSize / frameSize;
! byteLength = dataSize + headerSize;
}
final AudioFormat format = new AudioFormat(encoding, sampleRate,
sampleSizeInBits, channels,
frameSize, sampleRate, true);
! return new AuFileFormat(Type.AU, byteLength, format, frameLength);
}
}
< prev index next >