Java Code Examples for javax.sound.sampled.AudioInputStream#getFormat()
The following examples show how to use
javax.sound.sampled.AudioInputStream#getFormat() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WaveFloatFileWriter.java From Bytecoder with Apache License 2.0 | 6 votes |
public void write(AudioInputStream stream, RIFFWriter writer) throws IOException { try (final RIFFWriter fmt_chunk = writer.writeChunk("fmt ")) { AudioFormat format = stream.getFormat(); fmt_chunk.writeUnsignedShort(3); // WAVE_FORMAT_IEEE_FLOAT fmt_chunk.writeUnsignedShort(format.getChannels()); fmt_chunk.writeUnsignedInt((int) format.getSampleRate()); fmt_chunk.writeUnsignedInt(((int) format.getFrameRate()) * format.getFrameSize()); fmt_chunk.writeUnsignedShort(format.getFrameSize()); fmt_chunk.writeUnsignedShort(format.getSampleSizeInBits()); } try (RIFFWriter data_chunk = writer.writeChunk("data")) { byte[] buff = new byte[1024]; int len; while ((len = stream.read(buff, 0, buff.length)) != -1) { data_chunk.write(buff, 0, len); } } }
Example 2
Source File: WaveFloatFileWriter.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public void write(AudioInputStream stream, RIFFWriter writer) throws IOException { RIFFWriter fmt_chunk = writer.writeChunk("fmt "); AudioFormat format = stream.getFormat(); fmt_chunk.writeUnsignedShort(3); // WAVE_FORMAT_IEEE_FLOAT fmt_chunk.writeUnsignedShort(format.getChannels()); fmt_chunk.writeUnsignedInt((int) format.getSampleRate()); fmt_chunk.writeUnsignedInt(((int) format.getFrameRate()) * format.getFrameSize()); fmt_chunk.writeUnsignedShort(format.getFrameSize()); fmt_chunk.writeUnsignedShort(format.getSampleSizeInBits()); fmt_chunk.close(); RIFFWriter data_chunk = writer.writeChunk("data"); byte[] buff = new byte[1024]; int len; while ((len = stream.read(buff, 0, buff.length)) != -1) data_chunk.write(buff, 0, len); data_chunk.close(); }
Example 3
Source File: AuFileWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) { AudioFileFormat.Type[] filetypes = new AudioFileFormat.Type[types.length]; System.arraycopy(types, 0, filetypes, 0, types.length); // make sure we can write this stream AudioFormat format = stream.getFormat(); AudioFormat.Encoding encoding = format.getEncoding(); if( (AudioFormat.Encoding.ALAW.equals(encoding)) || (AudioFormat.Encoding.ULAW.equals(encoding)) || (AudioFormat.Encoding.PCM_SIGNED.equals(encoding)) || (AudioFormat.Encoding.PCM_UNSIGNED.equals(encoding)) ) { return filetypes; } return new AudioFileFormat.Type[0]; }
Example 4
Source File: WaveFileWriter.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) { AudioFileFormat.Type[] filetypes = new AudioFileFormat.Type[types.length]; System.arraycopy(types, 0, filetypes, 0, types.length); // make sure we can write this stream AudioFormat format = stream.getFormat(); AudioFormat.Encoding encoding = format.getEncoding(); if( AudioFormat.Encoding.ALAW.equals(encoding) || AudioFormat.Encoding.ULAW.equals(encoding) || AudioFormat.Encoding.PCM_SIGNED.equals(encoding) || AudioFormat.Encoding.PCM_UNSIGNED.equals(encoding) ) { return filetypes; } return new AudioFileFormat.Type[0]; }
Example 5
Source File: WaveFloatFileWriter.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public void write(AudioInputStream stream, RIFFWriter writer) throws IOException { RIFFWriter fmt_chunk = writer.writeChunk("fmt "); AudioFormat format = stream.getFormat(); fmt_chunk.writeUnsignedShort(3); // WAVE_FORMAT_IEEE_FLOAT fmt_chunk.writeUnsignedShort(format.getChannels()); fmt_chunk.writeUnsignedInt((int) format.getSampleRate()); fmt_chunk.writeUnsignedInt(((int) format.getFrameRate()) * format.getFrameSize()); fmt_chunk.writeUnsignedShort(format.getFrameSize()); fmt_chunk.writeUnsignedShort(format.getSampleSizeInBits()); fmt_chunk.close(); RIFFWriter data_chunk = writer.writeChunk("data"); byte[] buff = new byte[1024]; int len; while ((len = stream.read(buff, 0, buff.length)) != -1) data_chunk.write(buff, 0, len); data_chunk.close(); }
Example 6
Source File: WaveEngine.java From javagame with MIT License | 6 votes |
/** * WAVE�t�@�C�������[�h * @param url WAVE�t�@�C����URL */ public static void load(URL url) throws UnsupportedAudioFileException, IOException, LineUnavailableException { // �I�[�f�B�I�X�g���[�����J�� AudioInputStream ais = AudioSystem.getAudioInputStream(url); // WAVE�t�@�C���̃t�H�[�}�b�g���擾 AudioFormat format = ais.getFormat(); // ���C�����擾 DataLine.Info info = new DataLine.Info(SourceDataLine.class, format, AudioSystem.NOT_SPECIFIED); // WAVE�f�[�^���擾 DataClip clip = new DataClip(ais); // WAVE�f�[�^��o�^ clips[counter] = clip; lines[counter] = (SourceDataLine)AudioSystem.getLine(info); // ���C�����J�� lines[counter].open(format); counter++; }
Example 7
Source File: AudioFloatFormatConverter.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public AudioInputStream getAudioInputStream(Encoding targetEncoding, AudioInputStream sourceStream) { if (sourceStream.getFormat().getEncoding().equals(targetEncoding)) return sourceStream; AudioFormat format = sourceStream.getFormat(); int channels = format.getChannels(); Encoding encoding = targetEncoding; float samplerate = format.getSampleRate(); int bits = format.getSampleSizeInBits(); boolean bigendian = format.isBigEndian(); if (targetEncoding.equals(Encoding.PCM_FLOAT)) bits = 32; AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits, channels, channels * bits / 8, samplerate, bigendian); return getAudioInputStream(targetFormat, sourceStream); }
Example 8
Source File: AudioFloatFormatConverter.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public AudioInputStream getAudioInputStream(Encoding targetEncoding, AudioInputStream sourceStream) { if (sourceStream.getFormat().getEncoding().equals(targetEncoding)) return sourceStream; AudioFormat format = sourceStream.getFormat(); int channels = format.getChannels(); Encoding encoding = targetEncoding; float samplerate = format.getSampleRate(); int bits = format.getSampleSizeInBits(); boolean bigendian = format.isBigEndian(); if (targetEncoding.equals(Encoding.PCM_FLOAT)) bits = 32; AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits, channels, channels * bits / 8, samplerate, bigendian); return getAudioInputStream(targetFormat, sourceStream); }
Example 9
Source File: DataClip.java From javagame with MIT License | 5 votes |
public DataClip(AudioInputStream audioStream) throws IOException { index = 0; format = audioStream.getFormat(); // WAVE�t�@�C���̑傫�������߂� int length = (int)(audioStream.getFrameLength() * format.getFrameSize()); // ���̑傫����byte�z���p�� data = new byte[length]; // data��WAVE�f�[�^���i�[���� DataInputStream is = new DataInputStream(audioStream); is.readFully(data); }
Example 10
Source File: WaveFloatFileWriter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private void checkFormat(AudioFileFormat.Type type, AudioInputStream stream) { if (!Type.WAVE.equals(type)) throw new IllegalArgumentException("File type " + type + " not supported."); if (!stream.getFormat().getEncoding().equals(Encoding.PCM_FLOAT)) throw new IllegalArgumentException("File format " + stream.getFormat() + " not supported."); }
Example 11
Source File: DataClip.java From javagame with MIT License | 5 votes |
public DataClip(AudioInputStream audioStream) throws IOException { index = 0; format = audioStream.getFormat(); // WAVE�t�@�C���̑傫�������߂� int length = (int)(audioStream.getFrameLength() * format.getFrameSize()); // ���̑傫����byte�z���p�� data = new byte[length]; // data��WAVE�f�[�^���i�[���� DataInputStream is = new DataInputStream(audioStream); is.readFully(data); }
Example 12
Source File: AudioFileSoundbankReader.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public Soundbank getSoundbank(AudioInputStream ais) throws InvalidMidiDataException, IOException { try { byte[] buffer; if (ais.getFrameLength() == -1) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buff = new byte[1024 - (1024 % ais.getFormat().getFrameSize())]; int ret; while ((ret = ais.read(buff)) != -1) { baos.write(buff, 0, ret); } ais.close(); buffer = baos.toByteArray(); } else { buffer = new byte[(int) (ais.getFrameLength() * ais.getFormat().getFrameSize())]; new DataInputStream(ais).readFully(buffer); } ModelByteBufferWavetable osc = new ModelByteBufferWavetable( new ModelByteBuffer(buffer), ais.getFormat(), -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 (Exception e) { return null; } }
Example 13
Source File: UlawCodec.java From hottub with GNU General Public License v2.0 | 4 votes |
UlawCodecStream(AudioInputStream stream, AudioFormat outputFormat) { super(stream, outputFormat, AudioSystem.NOT_SPECIFIED); AudioFormat inputFormat = stream.getFormat(); // throw an IllegalArgumentException if not ok if (!(isConversionSupported(outputFormat, inputFormat))) { throw new IllegalArgumentException("Unsupported conversion: " + inputFormat.toString() + " to " + outputFormat.toString()); } //$$fb 2002-07-18: fix for 4714846: JavaSound ULAW (8-bit) encoder erroneously depends on endian-ness boolean PCMIsBigEndian; // determine whether we are encoding or decoding if (AudioFormat.Encoding.ULAW.equals(inputFormat.getEncoding())) { encode = false; encodeFormat = inputFormat; decodeFormat = outputFormat; PCMIsBigEndian = outputFormat.isBigEndian(); } else { encode = true; encodeFormat = outputFormat; decodeFormat = inputFormat; PCMIsBigEndian = inputFormat.isBigEndian(); tempBuffer = new byte[tempBufferSize]; } // setup tables according to byte order if (PCMIsBigEndian) { tabByte1 = ULAW_TABH; tabByte2 = ULAW_TABL; highByte = 0; lowByte = 1; } else { tabByte1 = ULAW_TABL; tabByte2 = ULAW_TABH; highByte = 1; lowByte = 0; } // set the AudioInputStream length in frames if we know it if (stream instanceof AudioInputStream) { frameLength = ((AudioInputStream)stream).getFrameLength(); } // set framePos to zero framePos = 0; frameSize = inputFormat.getFrameSize(); if (frameSize == AudioSystem.NOT_SPECIFIED) { frameSize = 1; } }
Example 14
Source File: AlawCodec.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
AlawCodecStream(AudioInputStream stream, AudioFormat outputFormat) { super(stream, outputFormat, -1); AudioFormat inputFormat = stream.getFormat(); // throw an IllegalArgumentException if not ok if ( ! (isConversionSupported(outputFormat, inputFormat)) ) { throw new IllegalArgumentException("Unsupported conversion: " + inputFormat.toString() + " to " + outputFormat.toString()); } //$$fb 2002-07-18: fix for 4714846: JavaSound ULAW (8-bit) encoder erroneously depends on endian-ness boolean PCMIsBigEndian; // determine whether we are encoding or decoding if (AudioFormat.Encoding.ALAW.equals(inputFormat.getEncoding())) { encode = false; encodeFormat = inputFormat; decodeFormat = outputFormat; PCMIsBigEndian = outputFormat.isBigEndian(); } else { encode = true; encodeFormat = outputFormat; decodeFormat = inputFormat; PCMIsBigEndian = inputFormat.isBigEndian(); tempBuffer = new byte[tempBufferSize]; } if (PCMIsBigEndian) { tabByte1 = ALAW_TABH; tabByte2 = ALAW_TABL; highByte = 0; lowByte = 1; } else { tabByte1 = ALAW_TABL; tabByte2 = ALAW_TABH; highByte = 1; lowByte = 0; } // set the AudioInputStream length in frames if we know it if (stream instanceof AudioInputStream) { frameLength = ((AudioInputStream)stream).getFrameLength(); } // set framePos to zero framePos = 0; frameSize = inputFormat.getFrameSize(); if( frameSize==AudioSystem.NOT_SPECIFIED ) { frameSize=1; } }
Example 15
Source File: UlawCodec.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
UlawCodecStream(AudioInputStream stream, AudioFormat outputFormat) { super(stream, outputFormat, AudioSystem.NOT_SPECIFIED); AudioFormat inputFormat = stream.getFormat(); // throw an IllegalArgumentException if not ok if (!(isConversionSupported(outputFormat, inputFormat))) { throw new IllegalArgumentException("Unsupported conversion: " + inputFormat.toString() + " to " + outputFormat.toString()); } //$$fb 2002-07-18: fix for 4714846: JavaSound ULAW (8-bit) encoder erroneously depends on endian-ness boolean PCMIsBigEndian; // determine whether we are encoding or decoding if (AudioFormat.Encoding.ULAW.equals(inputFormat.getEncoding())) { encode = false; encodeFormat = inputFormat; decodeFormat = outputFormat; PCMIsBigEndian = outputFormat.isBigEndian(); } else { encode = true; encodeFormat = outputFormat; decodeFormat = inputFormat; PCMIsBigEndian = inputFormat.isBigEndian(); tempBuffer = new byte[tempBufferSize]; } // setup tables according to byte order if (PCMIsBigEndian) { tabByte1 = ULAW_TABH; tabByte2 = ULAW_TABL; highByte = 0; lowByte = 1; } else { tabByte1 = ULAW_TABL; tabByte2 = ULAW_TABH; highByte = 1; lowByte = 0; } // set the AudioInputStream length in frames if we know it if (stream instanceof AudioInputStream) { frameLength = ((AudioInputStream)stream).getFrameLength(); } // set framePos to zero framePos = 0; frameSize = inputFormat.getFrameSize(); if (frameSize == AudioSystem.NOT_SPECIFIED) { frameSize = 1; } }
Example 16
Source File: AlawCodec.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
AlawCodecStream(AudioInputStream stream, AudioFormat outputFormat) { super(stream, outputFormat, -1); AudioFormat inputFormat = stream.getFormat(); // throw an IllegalArgumentException if not ok if ( ! (isConversionSupported(outputFormat, inputFormat)) ) { throw new IllegalArgumentException("Unsupported conversion: " + inputFormat.toString() + " to " + outputFormat.toString()); } //$$fb 2002-07-18: fix for 4714846: JavaSound ULAW (8-bit) encoder erroneously depends on endian-ness boolean PCMIsBigEndian; // determine whether we are encoding or decoding if (AudioFormat.Encoding.ALAW.equals(inputFormat.getEncoding())) { encode = false; encodeFormat = inputFormat; decodeFormat = outputFormat; PCMIsBigEndian = outputFormat.isBigEndian(); } else { encode = true; encodeFormat = outputFormat; decodeFormat = inputFormat; PCMIsBigEndian = inputFormat.isBigEndian(); tempBuffer = new byte[tempBufferSize]; } if (PCMIsBigEndian) { tabByte1 = ALAW_TABH; tabByte2 = ALAW_TABL; highByte = 0; lowByte = 1; } else { tabByte1 = ALAW_TABL; tabByte2 = ALAW_TABH; highByte = 1; lowByte = 0; } // set the AudioInputStream length in frames if we know it if (stream instanceof AudioInputStream) { frameLength = ((AudioInputStream)stream).getFrameLength(); } // set framePos to zero framePos = 0; frameSize = inputFormat.getFrameSize(); if( frameSize==AudioSystem.NOT_SPECIFIED ) { frameSize=1; } }
Example 17
Source File: SoftJitterCorrector.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public SoftJitterCorrector(AudioInputStream stream, int buffersize, int smallbuffersize) { super(new JitterStream(stream, buffersize, smallbuffersize), stream.getFormat(), stream.getFrameLength()); }
Example 18
Source File: AlawCodec.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
AlawCodecStream(AudioInputStream stream, AudioFormat outputFormat) { super(stream, outputFormat, -1); AudioFormat inputFormat = stream.getFormat(); // throw an IllegalArgumentException if not ok if ( ! (isConversionSupported(outputFormat, inputFormat)) ) { throw new IllegalArgumentException("Unsupported conversion: " + inputFormat.toString() + " to " + outputFormat.toString()); } //$$fb 2002-07-18: fix for 4714846: JavaSound ULAW (8-bit) encoder erroneously depends on endian-ness boolean PCMIsBigEndian; // determine whether we are encoding or decoding if (AudioFormat.Encoding.ALAW.equals(inputFormat.getEncoding())) { encode = false; encodeFormat = inputFormat; decodeFormat = outputFormat; PCMIsBigEndian = outputFormat.isBigEndian(); } else { encode = true; encodeFormat = outputFormat; decodeFormat = inputFormat; PCMIsBigEndian = inputFormat.isBigEndian(); tempBuffer = new byte[tempBufferSize]; } if (PCMIsBigEndian) { tabByte1 = ALAW_TABH; tabByte2 = ALAW_TABL; highByte = 0; lowByte = 1; } else { tabByte1 = ALAW_TABL; tabByte2 = ALAW_TABH; highByte = 1; lowByte = 0; } // set the AudioInputStream length in frames if we know it if (stream instanceof AudioInputStream) { frameLength = ((AudioInputStream)stream).getFrameLength(); } // set framePos to zero framePos = 0; frameSize = inputFormat.getFrameSize(); if( frameSize==AudioSystem.NOT_SPECIFIED ) { frameSize=1; } }
Example 19
Source File: SoftJitterCorrector.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public SoftJitterCorrector(AudioInputStream stream, int buffersize, int smallbuffersize) { super(new JitterStream(stream, buffersize, smallbuffersize), stream.getFormat(), stream.getFrameLength()); }
Example 20
Source File: AlawCodec.java From hottub with GNU General Public License v2.0 | 4 votes |
AlawCodecStream(AudioInputStream stream, AudioFormat outputFormat) { super(stream, outputFormat, -1); AudioFormat inputFormat = stream.getFormat(); // throw an IllegalArgumentException if not ok if ( ! (isConversionSupported(outputFormat, inputFormat)) ) { throw new IllegalArgumentException("Unsupported conversion: " + inputFormat.toString() + " to " + outputFormat.toString()); } //$$fb 2002-07-18: fix for 4714846: JavaSound ULAW (8-bit) encoder erroneously depends on endian-ness boolean PCMIsBigEndian; // determine whether we are encoding or decoding if (AudioFormat.Encoding.ALAW.equals(inputFormat.getEncoding())) { encode = false; encodeFormat = inputFormat; decodeFormat = outputFormat; PCMIsBigEndian = outputFormat.isBigEndian(); } else { encode = true; encodeFormat = outputFormat; decodeFormat = inputFormat; PCMIsBigEndian = inputFormat.isBigEndian(); tempBuffer = new byte[tempBufferSize]; } if (PCMIsBigEndian) { tabByte1 = ALAW_TABH; tabByte2 = ALAW_TABL; highByte = 0; lowByte = 1; } else { tabByte1 = ALAW_TABL; tabByte2 = ALAW_TABH; highByte = 1; lowByte = 0; } // set the AudioInputStream length in frames if we know it if (stream instanceof AudioInputStream) { frameLength = ((AudioInputStream)stream).getFrameLength(); } // set framePos to zero framePos = 0; frameSize = inputFormat.getFrameSize(); if( frameSize==AudioSystem.NOT_SPECIFIED ) { frameSize=1; } }