use of javax.sound.sampled.AudioInputStream in project jdk8u_jdk by JetBrains.
the class AuFileReader 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 {
InputStream urlStream = null;
BufferedInputStream bis = null;
AudioFileFormat fileFormat = null;
// throws IOException
urlStream = url.openStream();
AudioInputStream result = null;
try {
bis = new BufferedInputStream(urlStream, bisBufferSize);
result = getAudioInputStream((InputStream) bis);
} finally {
if (result == null) {
urlStream.close();
}
}
return result;
}
use of javax.sound.sampled.AudioInputStream in project jdk8u_jdk by JetBrains.
the class AudioFileSoundbankReader method getSoundbank.
public Soundbank getSoundbank(File file) throws InvalidMidiDataException, IOException {
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(file);
ais.close();
ModelByteBufferWavetable osc = new ModelByteBufferWavetable(new ModelByteBuffer(file, 0, file.length()), -4800);
ModelPerformer performer = new ModelPerformer();
performer.getOscillators().add(osc);
SimpleSoundbank sbk = new SimpleSoundbank();
SimpleInstrument ins = new SimpleInstrument();
ins.add(performer);
sbk.addInstrument(ins);
return sbk;
} catch (UnsupportedAudioFileException e1) {
return null;
} catch (IOException e) {
return null;
}
}
use of javax.sound.sampled.AudioInputStream in project jdk8u_jdk by JetBrains.
the class AudioFloatInputStream method getInputStream.
public static AudioFloatInputStream getInputStream(AudioFormat format, byte[] buffer, int offset, int len) {
AudioFloatConverter converter = AudioFloatConverter.getConverter(format);
if (converter != null)
return new BytaArrayAudioFloatInputStream(converter, buffer, offset, len);
InputStream stream = new ByteArrayInputStream(buffer, offset, len);
long aLen = format.getFrameSize() == AudioSystem.NOT_SPECIFIED ? AudioSystem.NOT_SPECIFIED : len / format.getFrameSize();
AudioInputStream astream = new AudioInputStream(stream, format, aLen);
return getInputStream(astream);
}
use of javax.sound.sampled.AudioInputStream in project jdk8u_jdk by JetBrains.
the class DLSSample method getData.
public Object getData() {
AudioFormat format = getFormat();
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 DLSSoundbank method writeSample.
private void writeSample(RIFFWriter writer, DLSSample sample) throws IOException {
AudioFormat audioformat = sample.getFormat();
Encoding encoding = audioformat.getEncoding();
float sampleRate = audioformat.getSampleRate();
int sampleSizeInBits = audioformat.getSampleSizeInBits();
int channels = audioformat.getChannels();
int frameSize = audioformat.getFrameSize();
float frameRate = audioformat.getFrameRate();
boolean bigEndian = audioformat.isBigEndian();
boolean convert_needed = false;
if (audioformat.getSampleSizeInBits() == 8) {
if (!encoding.equals(Encoding.PCM_UNSIGNED)) {
encoding = Encoding.PCM_UNSIGNED;
convert_needed = true;
}
} else {
if (!encoding.equals(Encoding.PCM_SIGNED)) {
encoding = Encoding.PCM_SIGNED;
convert_needed = true;
}
if (bigEndian) {
bigEndian = false;
convert_needed = true;
}
}
if (convert_needed) {
audioformat = new AudioFormat(encoding, sampleRate, sampleSizeInBits, channels, frameSize, frameRate, bigEndian);
}
// fmt
RIFFWriter fmt_chunk = writer.writeChunk("fmt ");
int sampleformat = 0;
if (audioformat.getEncoding().equals(Encoding.PCM_UNSIGNED))
sampleformat = 1;
else if (audioformat.getEncoding().equals(Encoding.PCM_SIGNED))
sampleformat = 1;
else if (audioformat.getEncoding().equals(Encoding.PCM_FLOAT))
sampleformat = 3;
fmt_chunk.writeUnsignedShort(sampleformat);
fmt_chunk.writeUnsignedShort(audioformat.getChannels());
fmt_chunk.writeUnsignedInt((long) audioformat.getSampleRate());
long srate = ((long) audioformat.getFrameRate()) * audioformat.getFrameSize();
fmt_chunk.writeUnsignedInt(srate);
fmt_chunk.writeUnsignedShort(audioformat.getFrameSize());
fmt_chunk.writeUnsignedShort(audioformat.getSampleSizeInBits());
fmt_chunk.write(0);
fmt_chunk.write(0);
writeSampleOptions(writer.writeChunk("wsmp"), sample.sampleoptions);
if (convert_needed) {
RIFFWriter data_chunk = writer.writeChunk("data");
AudioInputStream stream = AudioSystem.getAudioInputStream(audioformat, (AudioInputStream) sample.getData());
byte[] buff = new byte[1024];
int ret;
while ((ret = stream.read(buff)) != -1) {
data_chunk.write(buff, 0, ret);
}
} else {
RIFFWriter data_chunk = writer.writeChunk("data");
ModelByteBuffer databuff = sample.getDataBuffer();
databuff.writeTo(data_chunk);
/*
data_chunk.write(databuff.array(),
databuff.arrayOffset(),
databuff.capacity());
*/
}
writeInfo(writer.writeList("INFO"), sample.info);
}
Aggregations