javazoom.jl.decoder.Bitstream Java Examples
The following examples show how to use
javazoom.jl.decoder.Bitstream.
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: Player.java From jclic with GNU General Public License v2.0 | 6 votes |
public Player(InputStream stream, AudioDevice device) throws JavaLayerException { bitstream = new Bitstream(stream); decoder = new Decoder(); if (device!=null) { audio = device; } else { FactoryRegistry r = FactoryRegistry.systemRegistry(); audio = r.createAudioDevice(); } audio.open(decoder); }
Example #2
Source File: Player.java From epic-inventor with GNU General Public License v2.0 | 6 votes |
public Player(InputStream stream, AudioDevice device) throws JavaLayerException { bitstream = new Bitstream(stream); decoder = new Decoder(); if (device!=null) { audio = device; } else { FactoryRegistry r = FactoryRegistry.systemRegistry(); audio = r.createAudioDevice(); } audio.open(decoder); }
Example #3
Source File: Mini2DxMp3.java From mini2Dx with Apache License 2.0 | 6 votes |
public Music (Mini2DxOpenALAudio audio, FileHandle file) { super(audio, file); if (audio.noDevice) return; bitstream = new Bitstream(file.read()); decoder = new MP3Decoder(); bufferOverhead = 4096; try { Header header = bitstream.readFrame(); if (header == null) throw new GdxRuntimeException("Empty MP3"); int channels = header.mode() == Header.SINGLE_CHANNEL ? 1 : 2; outputBuffer = new OutputBuffer(channels, false); decoder.setOutputBuffer(outputBuffer); setup(channels, header.getSampleRate()); } catch (BitstreamException e) { throw new GdxRuntimeException("error while preloading mp3", e); } }
Example #4
Source File: MP3SOUNDDATA.java From jpexs-decompiler with GNU General Public License v3.0 | 5 votes |
public MP3SOUNDDATA(SWFInputStream sis, boolean raw) throws IOException { if (!raw) { seekSamples = sis.readSI16("seekSamples"); } frames = new ArrayList<>(); MP3FRAME f; Decoder decoder = new Decoder(); Bitstream bitstream = new Bitstream(new ByteArrayInputStream(sis.readBytesEx(sis.available(), "soundStream"))); while ((f = MP3FRAME.readFrame(bitstream, decoder)) != null) { frames.add(f); } }
Example #5
Source File: AdvancedPlayer.java From jclic with GNU General Public License v2.0 | 5 votes |
public AdvancedPlayer(InputStream stream, AudioDevice device) throws JavaLayerException { bitstream = new Bitstream(stream); if (device!=null) audio = device; else audio = FactoryRegistry.systemRegistry().createAudioDevice(); audio.open(decoder = new Decoder()); }
Example #6
Source File: AdvancedPlayer.java From epic-inventor with GNU General Public License v2.0 | 5 votes |
public AdvancedPlayer(InputStream stream, AudioDevice device) throws JavaLayerException { bitstream = new Bitstream(stream); if (device != null) { audio = device; } else { audio = FactoryRegistry.systemRegistry().createAudioDevice(); } audio.open(decoder = new Decoder()); }
Example #7
Source File: Mini2DxMp3.java From mini2Dx with Apache License 2.0 | 5 votes |
public Sound (Mini2DxOpenALAudio audio, FileHandle file) { super(audio); if (audio.noDevice) return; ByteArrayOutputStream output = new ByteArrayOutputStream(4096); Bitstream bitstream = new Bitstream(file.read()); MP3Decoder decoder = new MP3Decoder(); try { OutputBuffer outputBuffer = null; int sampleRate = -1, channels = -1; while (true) { Header header = bitstream.readFrame(); if (header == null) break; if (outputBuffer == null) { channels = header.mode() == Header.SINGLE_CHANNEL ? 1 : 2; outputBuffer = new OutputBuffer(channels, false); decoder.setOutputBuffer(outputBuffer); sampleRate = header.getSampleRate(); } try { decoder.decodeFrame(header, bitstream); } catch (Exception ignored) { // JLayer's decoder throws ArrayIndexOutOfBoundsException sometimes!? } bitstream.closeFrame(); output.write(outputBuffer.getBuffer(), 0, outputBuffer.reset()); } bitstream.close(); setup(output.toByteArray(), channels, sampleRate); } catch (Throwable ex) { throw new GdxRuntimeException("Error reading audio data.", ex); } }
Example #8
Source File: JLayerDecoderImpl.java From dcs-sdk-java with Apache License 2.0 | 4 votes |
@Override public void decode(InputStream inputStream) throws Exception { Decoder decoder = new Decoder(); Bitstream bitstream = new Bitstream(inputStream); Header header; isStopRead = false; isGetMp3InfoFinished = false; int count = 0; while (!isStopRead && (header = bitstream.readFrame()) != null) { isDecoding = true; long start = System.currentTimeMillis(); SampleBuffer sampleBuffer = (SampleBuffer) decoder.decodeFrame(header, bitstream); // 获取采样率等 if (!isGetMp3InfoFinished) { fireOnDecodeInfo(sampleBuffer.getSampleFrequency(), sampleBuffer.getChannelCount()); isGetMp3InfoFinished = true; } short[] buffer = sampleBuffer.getBuffer(); byte[] pcm = new byte[buffer.length / 2]; for (int i = 0; i < buffer.length / 2 / 2; i++) { int j = i * 2; pcm[j] = (byte) (buffer[i] & 0xff); pcm[j + 1] = (byte) ((buffer[i] >> 8) & 0xff); } if (count == 0 || count == 1) { byte[] newPcm = avoidNullPcm(pcm); if (newPcm != null) { fireOnDecodePcm(newPcm); } } else { fireOnDecodePcm(pcm); } count++; bitstream.closeFrame(); long end = System.currentTimeMillis(); Log.i(TAG, "after decode pcm.length:" + pcm.length + "," + (end - start)); } isDecoding = false; fireOnDecodeFinished(); inputStream.close(); }