Ejemplo n.º 1
0
 private boolean openSeekable() {
   final Info initialInfo = new Info();
   final Comment initialComment = new Comment();
   this.m_chunkSize = Math.min(8500, (int) length(this.m_vorbisStream));
   final Page page = new Page();
   final int[] testSerialno = {0};
   final int ret = this.fetchHeaders(initialInfo, initialComment, testSerialno, null);
   final int serialno = testSerialno[0];
   final int dataOffset = (int) this.m_offset;
   this.m_oggStreamState.clear();
   if (ret < 0) {
     return false;
   }
   seek(this.m_vorbisStream, 0L, 1);
   this.m_offset = tell(this.m_vorbisStream);
   final long end = this.getPreviousPage(page);
   if (page.serialno() != serialno) {
     if (this.bisectForwardSerialno(0L, 0L, end + 1L, serialno, 0) < 0) {
       return false;
     }
   } else if (this.bisectForwardSerialno(0L, end, end + 1L, serialno, 0) < 0) {
     return false;
   }
   this.prefetchAllHeaders(initialInfo, initialComment, dataOffset);
   this.rawSeek(this.m_dataOffsets[0]);
   return true;
 }
Ejemplo n.º 2
0
 @Override
 public int read(final ByteBuffer bb, final int pos) {
   this.m_isReset = false;
   bb.position(pos);
   while (bb.remaining() > 0) {
     boolean needToProcessPacket = true;
     if (this.m_decodeReady) {
       final Info info = this.m_info[this.m_currentLink];
       final int totalSamples = this.m_dspState.synthesis_pcmout(this.m_pcmf_buffer, this._index);
       final float[][] pcm = this.m_pcmf_buffer[0];
       if (totalSamples > 0) {
         final int channelsCount = info.channelsCount;
         final int bytesPerSample = channelsCount * 2;
         int samples = Math.min(totalSamples, bb.remaining() / bytesPerSample);
         samples = Math.min(samples, 8192 / bytesPerSample);
         needToProcessPacket = (samples == totalSamples);
         for (int i = 0; i < channelsCount; ++i) {
           int ptr = i * 2;
           final int mono = this._index[i];
           for (int j = 0; j < samples; ++j) {
             int val = (int) (pcm[i][mono + j] * 32767.0f);
             if (val > 32767) {
               val = 32767;
             }
             if (val < -32768) {
               val = -32768;
             }
             if (val < 0) {
               val |= 0x8000;
             }
             if (JOrbisStream.m_bigEndian) {
               this.m_conversionBuffer[ptr] = (byte) (val >>> 8 & 0xFF);
               this.m_conversionBuffer[ptr + 1] = (byte) (val & 0xFF);
             } else {
               this.m_conversionBuffer[ptr] = (byte) (val & 0xFF);
               this.m_conversionBuffer[ptr + 1] = (byte) (val >>> 8 & 0xFF);
             }
             ptr += 2 * channelsCount;
           }
         }
         final int writtenBytesLength = samples * bytesPerSample;
         bb.put(this.m_conversionBuffer, 0, writtenBytesLength);
         this.m_dspState.synthesis_read(samples);
         this.m_pcmOffset += samples;
       }
     }
     if (needToProcessPacket) {
       switch (this.processPacket(true)) {
         case 0:
           {
             return -(bb.position() - pos);
           }
         case -1:
           {
             return -(bb.position() - pos);
           }
         default:
           {
             continue;
           }
       }
     }
   }
   return bb.position() - pos;
 }