use of javax.sound.sampled.AudioInputStream in project jdk8u_jdk by JetBrains.
the class WaveFileReader method getAudioInputStream.
/**
* Obtains an audio stream from the File provided. The File must
* point to valid audio file data.
* @param file the File for which the <code>AudioInputStream</code> should be
* constructed
* @return an <code>AudioInputStream</code> object based on the audio file data pointed
* to by the File
* @throws UnsupportedAudioFileException if the File does not point to valid audio
* file data recognized by the system
* @throws IOException if an I/O exception occurs
*/
public AudioInputStream getAudioInputStream(File file) throws UnsupportedAudioFileException, IOException {
// throws IOException
FileInputStream fis = new FileInputStream(file);
AudioFileFormat fileFormat = null;
// part of fix for 4325421
try {
fileFormat = getFMT(fis, false);
} finally {
if (fileFormat == null) {
fis.close();
}
}
return new AudioInputStream(fis, fileFormat.getFormat(), fileFormat.getFrameLength());
}
use of javax.sound.sampled.AudioInputStream in project jdk8u_jdk by JetBrains.
the class WaveFileReader method getAudioInputStream.
/**
* Obtains an audio stream from the URL provided. The URL must
* point to valid audio file data.
* @param url the URL for which the <code>AudioInputStream</code> should be
* constructed
* @return an <code>AudioInputStream</code> object based on the audio file data pointed
* to by the URL
* @throws UnsupportedAudioFileException if the URL does not point to valid audio
* file data recognized by the system
* @throws IOException if an I/O exception occurs
*/
public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException {
// throws IOException
InputStream urlStream = url.openStream();
AudioFileFormat fileFormat = null;
try {
fileFormat = getFMT(urlStream, false);
} finally {
if (fileFormat == null) {
urlStream.close();
}
}
return new AudioInputStream(urlStream, fileFormat.getFormat(), fileFormat.getFrameLength());
}
use of javax.sound.sampled.AudioInputStream in project jdk8u_jdk by JetBrains.
the class SF2Sample method getData.
public Object getData() {
AudioFormat format = getFormat();
/*
if (sampleFile != null) {
FileInputStream fis;
try {
fis = new FileInputStream(sampleFile);
RIFFReader riff = new RIFFReader(fis);
if (!riff.getFormat().equals("RIFF")) {
throw new RIFFInvalidDataException(
"Input stream is not a valid RIFF stream!");
}
if (!riff.getType().equals("sfbk")) {
throw new RIFFInvalidDataException(
"Input stream is not a valid SoundFont!");
}
while (riff.hasNextChunk()) {
RIFFReader chunk = riff.nextChunk();
if (chunk.getFormat().equals("LIST")) {
if (chunk.getType().equals("sdta")) {
while(chunk.hasNextChunk()) {
RIFFReader chunkchunk = chunk.nextChunk();
if(chunkchunk.getFormat().equals("smpl")) {
chunkchunk.skip(sampleOffset);
return new AudioInputStream(chunkchunk,
format, sampleLen);
}
}
}
}
}
return null;
} catch (Exception e) {
return new Throwable(e.toString());
}
}
*/
InputStream is = data.getInputStream();
if (is == null)
return null;
return new AudioInputStream(is, format, data.capacity());
}
use of javax.sound.sampled.AudioInputStream in project jdk8u_jdk by JetBrains.
the class SoftAudioPusher method run.
public void run() {
byte[] buffer = SoftAudioPusher.this.buffer;
AudioInputStream ais = SoftAudioPusher.this.ais;
SourceDataLine sourceDataLine = SoftAudioPusher.this.sourceDataLine;
try {
while (active) {
// Read from audio source
int count = ais.read(buffer);
if (count < 0)
break;
// Write byte buffer to source output
sourceDataLine.write(buffer, 0, count);
}
} catch (IOException e) {
active = false;
//e.printStackTrace();
}
}
use of javax.sound.sampled.AudioInputStream in project jdk8u_jdk by JetBrains.
the class UlawCodec method getConvertedStream.
// OLD CODE
/**
* Opens the codec with the specified parameters.
* @param stream stream from which data to be processed should be read
* @param outputFormat desired data format of the stream after processing
* @return stream from which processed data may be read
* @throws IllegalArgumentException if the format combination supplied is
* not supported.
*/
/* public AudioInputStream getConvertedStream(AudioFormat outputFormat, AudioInputStream stream) { */
private AudioInputStream getConvertedStream(AudioFormat outputFormat, AudioInputStream stream) {
AudioInputStream cs = null;
AudioFormat inputFormat = stream.getFormat();
if (inputFormat.matches(outputFormat)) {
cs = stream;
} else {
cs = (AudioInputStream) (new UlawCodecStream(stream, outputFormat));
}
return cs;
}
Aggregations