javazoom.jl.decoder.Bitstream类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(320)

本文整理了Java中javazoom.jl.decoder.Bitstream类的一些代码示例,展示了Bitstream类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitstream类的具体详情如下:
包路径:javazoom.jl.decoder.Bitstream
类名称:Bitstream

Bitstream介绍

[英]The Bistream class is responsible for parsing an MPEG audio bitstream.

REVIEW: much of the parsing currently occurs in the various decoders. This should be moved into this class and associated inner classes.
[中]Bistream类负责解析MPEG音频比特流。
回顾:目前许多解析都发生在各种解码器中。应该将其移动到此类和关联的内部类中。

代码示例

代码示例来源:origin: libgdx/libgdx

ByteArrayOutputStream output = new ByteArrayOutputStream(4096);
Bitstream bitstream = new Bitstream(file.read());
MP3Decoder decoder = new MP3Decoder();
  int sampleRate = -1, channels = -1;
  while (true) {
    Header header = bitstream.readFrame();
    if (header == null) break;
    if (outputBuffer == null) {
    bitstream.closeFrame();
    output.write(outputBuffer.getBuffer(), 0, outputBuffer.reset());
  bitstream.close();
  setup(output.toByteArray(), channels, sampleRate);
} catch (Throwable ex) {

代码示例来源:origin: libgdx/libgdx

public Music (OpenALAudio 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);
  }
}

代码示例来源:origin: libgdx/libgdx

boolean setup = bitstream == null;
if (setup) {
  bitstream = new Bitstream(file.read());
  decoder = new MP3Decoder();
int minRequiredLength = buffer.length - OutputBuffer.BUFFERSIZE * 2;
while (totalLength <= minRequiredLength) {
  Header header = bitstream.readFrame();
  if (header == null) break;
  if (setup) {
  bitstream.closeFrame();

代码示例来源:origin: tulskiy/musique

private Header skipFrame() throws BitstreamException {
  readFrame = bitstream.readFrame();
  if (readFrame == null) {
    return null;
  }
  bitstream.closeFrame();
  return readFrame;
}

代码示例来源:origin: com.badlogicgames.jlayer/jlayer

boolean sync = false;
do {
  headerstring = stream.syncHeader(syncmode);
        h_version = MPEG25_LSF;
      else
        throw stream.newBitstreamException(Bitstream.UNKNOWN_ERROR);
    if ((h_sample_frequency = headerstring >>> 10 & 3) == 3) throw stream.newBitstreamException(Bitstream.UNKNOWN_ERROR);
  int framesizeloaded = stream.read_frame_data(framesize);
  if (framesize >= 0 && framesizeloaded != framesize) // Data loaded does not match to expected framesize,
    throw stream.newBitstreamException(Bitstream.INVALIDFRAME);
  if (stream.isSyncCurrentPosition(syncmode)) {
    if (syncmode == Bitstream.INITIAL_SYNC) {
      syncmode = Bitstream.STRICT_SYNC;
      stream.set_syncword(headerstring & 0xFFF80CC0);
    stream.unreadFrame();
} while (!sync);
stream.parse_frame();
if (h_protection_bit == 0) {
  checksum = (short)stream.get_bits(16);
  if (crc == null) crc = new Crc16();
  crc.add_bits(headerstring, 16);

代码示例来源:origin: tulskiy/musique

boolean sync = false;
do {
  headerstring = stream.syncHeader(syncmode);
        h_version = MPEG25_LSF;
      } else {
        throw stream.newBitstreamException(Bitstream.UNKNOWN_ERROR);
      throw stream.newBitstreamException(Bitstream.UNKNOWN_ERROR);
  int framesizeloaded = stream.read_frame_data(framesize);
  if ((framesize >= 0) && (framesizeloaded != framesize)) {
    throw stream.newBitstreamException(Bitstream.INVALIDFRAME);
  if (stream.isSyncCurrentPosition(syncmode)) {
    if (syncmode == Bitstream.INITIAL_SYNC) {
      syncmode = Bitstream.STRICT_SYNC;
      stream.setSyncword(headerstring & 0xFFF80CC0);
      sync = true;
    } else {
      stream.unreadFrame();
stream.parse_frame();
if (h_protection_bit == 0) {
  checksum = (short) stream.get_bits(16);
  if (crc == null) {

代码示例来源:origin: libgdx/libgdx

public void reset () {
    if (bitstream == null) return;
    try {
      bitstream.close();
    } catch (BitstreamException ignored) {
    }
    bitstream = null;
  }
}

代码示例来源:origin: com.badlogicgames.jlayer/jlayer

/**
 * Construct a IBitstream that reads data from a given InputStream.
 * 
 * @param in The InputStream to read from.
 */
public Bitstream (InputStream in) {
  if (in == null) throw new NullPointerException("in");
  in = new BufferedInputStream(in);
  loadID3v2(in);
  firstframe = true;
  // source = new PushbackInputStream(in, 1024);
  source = new PushbackInputStream(in, BUFFER_INT_SIZE * 4);
  closeFrame();
  // current_frame_number = -1;
  // last_frame_number = -1;
}

代码示例来源:origin: com.googlecode.apparat/apparat-playerglobal

public JLayerSoundSource(final Sound sound, final InputStream input) {
  _sound = sound;
  _bitstream = new Bitstream(input);
  _decoder = new Decoder();
}

代码示例来源:origin: com.badlogicgames.jlayer/jlayer

/**
 * Reads and parses the next frame from the input source.
 * @return the Header describing details of the frame read, or null if the end of the stream has been reached.
 */
public Header readFrame () throws BitstreamException {
  Header result = null;
  try {
    result = readNextFrame();
    // E.B, Parse VBR (if any) first frame.
    if (firstframe == true) {
      result.parseVBR(frame_bytes);
      firstframe = false;
    }
  } catch (BitstreamException ex) {
    if (ex.getErrorCode() == INVALIDFRAME)
      // Try to skip this frame.
      // System.out.println("INVALIDFRAME");
      try {
        closeFrame();
        result = readNextFrame();
      } catch (BitstreamException e) {
        if (e.getErrorCode() != STREAM_EOF) // wrap original exception so stack trace is maintained.
          throw newBitstreamException(e.getErrorCode(), e);
      }
    else if (ex.getErrorCode() != STREAM_EOF) // wrap original exception so stack trace is maintained.
      throw newBitstreamException(ex.getErrorCode(), ex);
  }
  return result;
}

代码示例来源:origin: com.badlogicgames.jlayer/jlayer

/**
 * Get next 32 bits from bitstream. They are stored in the headerstring. syncmod allows Synchro flag ID The returned value is
 * False at the end of stream.
 */
int syncHeader (byte syncmode) throws BitstreamException {
  boolean sync;
  int headerstring;
  // read additional 2 bytes
  int bytesRead = readBytes(syncbuf, 0, 3);
  if (bytesRead != 3) throw newBitstreamException(STREAM_EOF, null);
  headerstring = syncbuf[0] << 16 & 0x00FF0000 | syncbuf[1] << 8 & 0x0000FF00 | syncbuf[2] << 0 & 0x000000FF;
  do {
    headerstring <<= 8;
    if (readBytes(syncbuf, 3, 1) != 1) throw newBitstreamException(STREAM_EOF, null);
    headerstring |= syncbuf[3] & 0x000000FF;
    sync = isSyncMark(headerstring, syncmode, syncword);
  } while (!sync);
  // current_frame_number++;
  // if (last_frame_number < current_frame_number) last_frame_number = current_frame_number;
  return headerstring;
}

代码示例来源:origin: tulskiy/musique

/**
 * Construct a IBitstream that reads data from a
 * given InputStream.
 *
 * @param source The InputStream to read from.
 */
public Bitstream(InputStream source) {
  this.source = new PushbackInputStream(
      new BufferedInputStream(source, 30000), BUFFER_INT_SIZE);
  skipID3v2();
  firstframe = true;
  closeFrame();
}

代码示例来源:origin: com.badlogicgames.jlayer/jlayer

/**
 * Determines if the next 4 bytes of the stream represent a frame header.
 */
public boolean isSyncCurrentPosition (int syncmode) throws BitstreamException {
  int read = readBytes(syncbuf, 0, 4);
  int headerstring = syncbuf[0] << 24 & 0xFF000000 | syncbuf[1] << 16 & 0x00FF0000 | syncbuf[2] << 8 & 0x0000FF00
    | syncbuf[3] << 0 & 0x000000FF;
  try {
    source.unread(syncbuf, 0, read);
  } catch (IOException ex) {
  }
  boolean sync = false;
  switch (read) {
  case 0:
    sync = true;
    break;
  case 4:
    sync = isSyncMark(headerstring, syncmode, syncword);
    break;
  }
  return sync;
}

代码示例来源:origin: javazoom/jlayer

public int readCheckedBits(int n)
{
  // REVIEW: implement CRC check.
  return get_bits(n);
}

代码示例来源:origin: com.googlecode.apparat/apparat-playerglobal

private boolean decodeFrame() {
    try {
      final Header header = _bitstream.readFrame();

      if(null == header) {
        return false;
      }

      _output = (SampleBuffer) _decoder.decodeFrame(header, _bitstream);
      _available += _output.getBufferLength() >> 1;
      _readPos = 0;

      return true;
    } catch(final Throwable t) {
      throw new RuntimeException(t);
    }
  }
}

代码示例来源:origin: com.badlogicgames.jlayer/jlayer

/**
 * Unreads the bytes read from the frame.
 * @throws BitstreamException
 */
// REVIEW: add new error codes for this.
public void unreadFrame () throws BitstreamException {
  if (wordpointer == -1 && bitindex == -1 && framesize > 0) try {
    source.unread(frame_bytes, 0, framesize);
  } catch (IOException ex) {
    throw newBitstreamException(STREAM_ERROR);
  }
}

代码示例来源:origin: libgdx/libgdx

boolean setup = bitstream == null;
if (setup) {
  bitstream = new Bitstream(file.read());
  decoder = new MP3Decoder();
int minRequiredLength = buffer.length - OutputBuffer.BUFFERSIZE * 2;
while (totalLength <= minRequiredLength) {
  Header header = bitstream.readFrame();
  if (header == null) break;
  if (setup) {
  bitstream.closeFrame();

代码示例来源:origin: libgdx/libgdx

public Music (OpenALAudio 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);
  }
}

代码示例来源:origin: javazoom/jlayer

/**
 * skips over a single frame
 * @return false    if there are no more frames to decode, true otherwise.
 */
protected boolean skipFrame() throws JavaLayerException
{
  Header h = bitstream.readFrame();
  if (h == null) return false;
  bitstream.closeFrame();
  return true;
}

代码示例来源:origin: javazoom/jlayer

do
  headerstring = stream.syncHeader(syncmode);
        h_version = MPEG25_LSF;
      else
        throw stream.newBitstreamException(Bitstream.UNKNOWN_ERROR);
    if ((h_sample_frequency = ((headerstring >>> 10) & 3)) == 3)
      throw stream.newBitstreamException(Bitstream.UNKNOWN_ERROR);
  int framesizeloaded = stream.read_frame_data(framesize);
  if ((framesize >=0) && (framesizeloaded != framesize))
    throw stream.newBitstreamException(Bitstream.INVALIDFRAME);
  if (stream.isSyncCurrentPosition(syncmode))
      stream.set_syncword(headerstring & 0xFFF80CC0);
    stream.unreadFrame();
stream.parse_frame();
if (h_protection_bit == 0)
  checksum = (short) stream.get_bits(16);
  if (crc == null)
    crc = new Crc16();

相关文章