syncState.init(); int bufferIndex = syncState.buffer(4096); byte[] buffer = syncState.data; int bytes = in.read(buffer, bufferIndex, 4096); syncState.wrote(bytes); if (syncState.pageout(page) != 1) { while (i < 2) { while (i < 2) { int result = syncState.pageout(page); if (result == 0) { break; // Need more data bufferIndex = syncState.buffer(4096); buffer = syncState.data; bytes = in.read(buffer, bufferIndex, 4096); throw new Exception("End of file before finding all Vorbis headers!"); syncState.wrote(bytes);
/** * Copys data from input stream to syncState. */ private void fetchData() throws IOException { if (!eos) { // copy 4096 bytes from compressed stream to syncState. int bufferIndex = syncState.buffer(4096); if (bufferIndex < 0) { eos = true; return; } int bytes = in.read(syncState.data, bufferIndex, 4096); syncState.wrote(bytes); if (bytes == 0) { eos = true; } } }
int index = syncState.buffer(BUFFER_SIZE); if (index == -1) return false; throw new GdxRuntimeException("Failure reading Vorbis.", e); syncState.wrote(bytes); if (syncState.pageout(page) != 1) { while (i < 2) { while (i < 2) { int result = syncState.pageout(page); if (result == 0) break; // Need more data index = syncState.buffer(BUFFER_SIZE); if (index == -1) return false; buffer = syncState.data; throw new GdxRuntimeException("End of file before finding all Vorbis headers."); syncState.wrote(bytes);
SyncState oy=new SyncState(); // sync and verify incoming physical bitstream StreamState os=new StreamState(); // take physical pages, weld into a logical stream of packets Page og=new Page(); // one Ogg bitstream page. Vorbis packets are inside oy.init(); // Now we can read pages int index=oy.buffer(4096); buffer=oy.data; try{ oy.wrote(bytes); if(oy.pageout(og)!=1){ int result=oy.pageout(og); if(result==0) break; // Need more data index=oy.buffer(4096); buffer=oy.data; try{ oy.wrote(bytes); int result=oy.pageout(og); if(result==0) break; // need more data index=oy.buffer(4096);
int open_callbacks(InputStream is, byte[] initial, int ibytes//, callbacks callbacks ) throws JOrbisException { int ret; datasource = is; oy.init(); // perhaps some data was previously read into a buffer for testing // against other stream types. Allow initialization from this // previously read data (as we may be reading from a non-seekable // stream) if (initial != null) { int index = oy.buffer(ibytes); System.arraycopy(initial, 0, oy.data, index, ibytes); oy.wrote(ibytes); } // can we seek? Stevens suggests the seek test was portable if (is instanceof SeekableInputStream) { ret = open_seekable(); } else { ret = open_nonseekable(); } if (ret != 0) { datasource = null; clear(); } return ret; }
/** Initialise the vorbis decoding */ private void initVorbis () { syncState.init(); }
private void initializeJorbis (final ConverterData converterData) { // Initialize SyncState converterData.joggData.syncState.init (); // Prepare the to SyncState internal buffer converterData.joggData.syncState.buffer (JorbisCleanConverter.BUFFER_SIZE); /* * Fill the buffer with the data from SyncState's internal buffer. Note * how the size of this new buffer is different from bufferSize. */ converterData.pcmData.buffer = converterData.joggData.syncState.data; }
private void clear() { os.clear(); oy.clear(); }
result2 = syncState.pageout(page); if (result2 == 0) { fetchData();
public int open(RandomAccessFile input) { this.input = input; oy.clear(); oy.init(); inputStream = new OggInputStream(); decoder = new FLACDecoder(inputStream); long end = 0; try { end = input.length(); } catch (IOException e) { e.printStackTrace(); } getNextPage(1); if (bisect_forward_serialno(0, end, end + 1, serialno, 0) < 0) { clear(); return OV_EREAD; } readMetadata(); return 0; }
public int pageout(Page og){ // all we need to do is verify a page at the head of the stream // buffer. If it doesn't verify, we look for the next potential // frame while(true){ int ret=pageseek(og); if(ret>0){ // have a page return (1); } if(ret==0){ // need more data return (0); } // head did not start a synced page... skipped some bytes if(unsynced==0){ unsynced=1; return (-1); } // loop. keep looking } }
private void updatePcmDataHeaders (final ConverterData converterData) { // We get the new index and an updated buffer. converterData.pcmData.index = converterData.joggData.syncState.buffer (JorbisCleanConverter.BUFFER_SIZE); converterData.pcmData.buffer = converterData.joggData.syncState.data; }
private void readHeader (final ConverterData converterData, final InputStream oggInputStream) throws JorbisReadException { /* * We will read the first three packets of the header. We start off by * defining packet = 1 and increment that value whenever we have * successfully read another packet. */ int step = 1; /* * While we need more data (which we do until we have read the three * header packets), this loop reads from the stream and has a big * <code>switch</code> statement which does what it's supposed to do in * regards to the current packet. */ while (step < JorbisCleanConverter.HEADERS_NB_STEPS) { // Read from the oggInputStream. try { converterData.pcmData.count = oggInputStream.read (converterData.pcmData.buffer, converterData.pcmData.index, JorbisCleanConverter.BUFFER_SIZE); } catch (final IOException exception) { throw new JorbisReadException ("Could not read from the input stream.", exception); } // We let SyncState know how many bytes we read. converterData.joggData.syncState.wrote (converterData.pcmData.count); if (this.readNextPageAndDecideIfStepShouldBeIncreased (converterData, step)) { step++; } } }
public void seekHelper(long offset) { try { input.seek(offset); this.offset = offset; oy.reset(); } catch (IOException e) { e.printStackTrace(); } }
public OggInputStream(InputStream input) throws IOException { this.bytes = 0; this.comment = new Comment(); this.convbuffer = new byte[Bufferer.COMMON_SIZE * 4]; this.convsize = convbuffer.length; this.dspState = new DspState(); this.endOfBitStream = true; this.input = input; this.oggInfo = new Info(); this.packet = new Packet(); this.page = new Page(); this.pcmBuffer = Bufferer.newByteBuffer(Bufferer.COMMON_SIZE * 64); // 256 KB this.streamState = new StreamState(); this.syncState = new SyncState(); this.vorbisBlock = new Block(dspState); initVorbis(); readPCM(); }
int index = syncState.buffer(BUFFER_SIZE); if (index == -1) return false; throw new GdxRuntimeException("Failure reading Vorbis.", e); syncState.wrote(bytes); if (syncState.pageout(page) != 1) { while (i < 2) { while (i < 2) { int result = syncState.pageout(page); if (result == 0) break; // Need more data index = syncState.buffer(BUFFER_SIZE); if (index == -1) return false; buffer = syncState.data; throw new GdxRuntimeException("End of file before finding all Vorbis headers."); syncState.wrote(bytes);