1 /* |
1 /* |
2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
28 import java.io.DataInputStream; |
28 import java.io.DataInputStream; |
29 import java.io.IOException; |
29 import java.io.IOException; |
30 import java.io.InputStream; |
30 import java.io.InputStream; |
31 |
31 |
32 import javax.sound.sampled.AudioFileFormat; |
32 import javax.sound.sampled.AudioFileFormat; |
|
33 import javax.sound.sampled.AudioFileFormat.Type; |
33 import javax.sound.sampled.AudioFormat; |
34 import javax.sound.sampled.AudioFormat; |
34 import javax.sound.sampled.AudioSystem; |
35 import javax.sound.sampled.AudioSystem; |
35 import javax.sound.sampled.UnsupportedAudioFileException; |
36 import javax.sound.sampled.UnsupportedAudioFileException; |
36 |
37 |
37 /** |
38 /** |
54 throw new UnsupportedAudioFileException("not an AU file"); |
55 throw new UnsupportedAudioFileException("not an AU file"); |
55 } |
56 } |
56 |
57 |
57 final int headerSize = dis.readInt(); |
58 final int headerSize = dis.readInt(); |
58 final int dataSize = dis.readInt(); |
59 final int dataSize = dis.readInt(); |
59 final int encoding_local = dis.readInt(); |
60 final int auType = dis.readInt(); |
60 final int sampleRate = dis.readInt(); |
61 final int sampleRate = dis.readInt(); |
61 final int channels = dis.readInt(); |
62 final int channels = dis.readInt(); |
62 if (channels <= 0) { |
63 if (channels <= 0) { |
63 throw new UnsupportedAudioFileException("Invalid number of channels"); |
64 throw new UnsupportedAudioFileException("Invalid number of channels"); |
64 } |
65 } |
65 |
66 |
66 final int sampleSizeInBits; |
67 final int sampleSizeInBits; |
67 final AudioFormat.Encoding encoding; |
68 final AudioFormat.Encoding encoding; |
68 switch (encoding_local) { |
69 switch (auType) { |
69 case AuFileFormat.AU_ULAW_8: |
70 case AuFileFormat.AU_ULAW_8: |
70 encoding = AudioFormat.Encoding.ULAW; |
71 encoding = AudioFormat.Encoding.ULAW; |
71 sampleSizeInBits = 8; |
72 sampleSizeInBits = 8; |
72 break; |
73 break; |
73 case AuFileFormat.AU_ALAW_8: |
74 case AuFileFormat.AU_ALAW_8: |
74 encoding = AudioFormat.Encoding.ALAW; |
75 encoding = AudioFormat.Encoding.ALAW; |
75 sampleSizeInBits = 8; |
76 sampleSizeInBits = 8; |
76 break; |
77 break; |
77 case AuFileFormat.AU_LINEAR_8: |
78 case AuFileFormat.AU_LINEAR_8: |
78 // $$jb: 04.29.99: 8bit linear is *signed*, not *unsigned* |
79 // $$jb: 04.29.99: 8bit linear is *signed*, not *unsigned* |
79 encoding = AudioFormat.Encoding.PCM_SIGNED; |
80 encoding = AudioFormat.Encoding.PCM_SIGNED; |
80 sampleSizeInBits = 8; |
81 sampleSizeInBits = 8; |
81 break; |
82 break; |
82 case AuFileFormat.AU_LINEAR_16: |
83 case AuFileFormat.AU_LINEAR_16: |
83 encoding = AudioFormat.Encoding.PCM_SIGNED; |
84 encoding = AudioFormat.Encoding.PCM_SIGNED; |
84 sampleSizeInBits = 16; |
85 sampleSizeInBits = 16; |
85 break; |
86 break; |
86 case AuFileFormat.AU_LINEAR_24: |
87 case AuFileFormat.AU_LINEAR_24: |
87 encoding = AudioFormat.Encoding.PCM_SIGNED; |
88 encoding = AudioFormat.Encoding.PCM_SIGNED; |
88 |
89 sampleSizeInBits = 24; |
89 sampleSizeInBits = 24; |
90 break; |
90 break; |
91 case AuFileFormat.AU_LINEAR_32: |
91 case AuFileFormat.AU_LINEAR_32: |
92 encoding = AudioFormat.Encoding.PCM_SIGNED; |
92 encoding = AudioFormat.Encoding.PCM_SIGNED; |
93 sampleSizeInBits = 32; |
93 |
94 break; |
94 sampleSizeInBits = 32; |
95 case AuFileFormat.AU_FLOAT: |
95 break; |
96 encoding = AudioFormat.Encoding.PCM_FLOAT; |
96 // $jb: 03.19.99: we don't support these ... |
97 sampleSizeInBits = 32; |
97 /* case AuFileFormat.AU_FLOAT: |
98 break; |
98 encoding = new AudioFormat.FLOAT; |
99 // we don't support these ... |
99 sampleSizeInBits = 32; |
100 /* case AuFileFormat.AU_DOUBLE: |
100 break; |
|
101 case AuFileFormat.AU_DOUBLE: |
|
102 encoding = new AudioFormat.DOUBLE; |
101 encoding = new AudioFormat.DOUBLE; |
103 sampleSizeInBits = 8; |
102 sampleSizeInBits = 8; |
104 break; |
103 break; |
105 case AuFileFormat.AU_ADPCM_G721: |
104 case AuFileFormat.AU_ADPCM_G721: |
106 encoding = new AudioFormat.G721_ADPCM; |
105 encoding = new AudioFormat.G721_ADPCM; |
134 // now seek past the header |
133 // now seek past the header |
135 dis.skipBytes(headerSize - AuFileFormat.AU_HEADERSIZE); |
134 dis.skipBytes(headerSize - AuFileFormat.AU_HEADERSIZE); |
136 final AudioFormat format = new AudioFormat(encoding, sampleRate, |
135 final AudioFormat format = new AudioFormat(encoding, sampleRate, |
137 sampleSizeInBits, channels, |
136 sampleSizeInBits, channels, |
138 frameSize, sampleRate, true); |
137 frameSize, sampleRate, true); |
139 return new AuFileFormat(AudioFileFormat.Type.AU, dataSize + headerSize, |
138 return new AuFileFormat(Type.AU, dataSize + headerSize, format, length); |
140 format, length); |
|
141 } |
139 } |
142 } |
140 } |