< prev index next >

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

Print this page




 238                         samplerate, bits, channels, framesize, samplerate,
 239                         false, p);
 240             } else {
 241                 audioformat = new AudioFormat(Encoding.PCM_SIGNED, samplerate,
 242                         bits, channels, framesize, samplerate, false, p);
 243             }
 244         } else if (subFormat.equals(SUBTYPE_IEEE_FLOAT)) {
 245             audioformat = new AudioFormat(Encoding.PCM_FLOAT,
 246                     samplerate, bits, channels, framesize, samplerate, false, p);
 247         } else {
 248             throw new UnsupportedAudioFileException();
 249         }
 250         return new AudioFileFormat(AudioFileFormat.Type.WAVE, audioformat,
 251                                    AudioSystem.NOT_SPECIFIED);
 252     }
 253 
 254     @Override
 255     public AudioInputStream getAudioInputStream(final InputStream stream)
 256             throws UnsupportedAudioFileException, IOException {
 257 
 258         AudioFileFormat format = getAudioFileFormat(stream);
 259         // we've got everything, the stream is supported and it is at the
 260         // beginning of the header, so find the data chunk again and return an
 261         // AudioInputStream
 262         RIFFReader riffiterator = new RIFFReader(stream);
 263         while (riffiterator.hasNextChunk()) {
 264             RIFFReader chunk = riffiterator.nextChunk();
 265             if (chunk.getFormat().equals("data")) {
 266                 return new AudioInputStream(chunk, format.getFormat(), chunk
 267                         .getSize());

 268             }
 269         }
 270         throw new UnsupportedAudioFileException();
 271     }
 272 }


 238                         samplerate, bits, channels, framesize, samplerate,
 239                         false, p);
 240             } else {
 241                 audioformat = new AudioFormat(Encoding.PCM_SIGNED, samplerate,
 242                         bits, channels, framesize, samplerate, false, p);
 243             }
 244         } else if (subFormat.equals(SUBTYPE_IEEE_FLOAT)) {
 245             audioformat = new AudioFormat(Encoding.PCM_FLOAT,
 246                     samplerate, bits, channels, framesize, samplerate, false, p);
 247         } else {
 248             throw new UnsupportedAudioFileException();
 249         }
 250         return new AudioFileFormat(AudioFileFormat.Type.WAVE, audioformat,
 251                                    AudioSystem.NOT_SPECIFIED);
 252     }
 253 
 254     @Override
 255     public AudioInputStream getAudioInputStream(final InputStream stream)
 256             throws UnsupportedAudioFileException, IOException {
 257 
 258         final AudioFileFormat format = getAudioFileFormat(stream);
 259         // we've got everything, the stream is supported and it is at the
 260         // beginning of the header, so find the data chunk again and return an
 261         // AudioInputStream
 262         final RIFFReader riffiterator = new RIFFReader(stream);
 263         while (riffiterator.hasNextChunk()) {
 264             RIFFReader chunk = riffiterator.nextChunk();
 265             if (chunk.getFormat().equals("data")) {
 266                 final AudioFormat af = format.getFormat();
 267                 final long length = chunk.getSize() / af.getFrameSize();
 268                 return new AudioInputStream(chunk, af, length);
 269             }
 270         }
 271         throw new UnsupportedAudioFileException();
 272     }
 273 }
< prev index next >