Пример #1
0
  public long getTime() {
    long bytesRead = ringBuffer.getTotalRead();
    if (bytesRead == 0) return 0;

    // long diff = bytesRead - lastWritten;
    long diff = bytesRead;
    long diffNs = (diff * Clock.SECONDS_TO_NANOS) / (2 * info.channels * info.rate);
    long timeSinceLastRead = System.nanoTime() - lastPtsRead;
    return /*lastPts +*/ diffNs + timeSinceLastRead;
  }
Пример #2
0
  public void decode(Packet packet) {
    if (packetIndex < 3) {
      if (info.synthesis_headerin(comment, packet) < 0) {
        // error case; not a Vorbis header
        System.err.println("does not contain Vorbis audio data.");
        return;
      }
      if (packetIndex == 2) {
        dsp.synthesis_init(info);
        block.init(dsp);
        System.out.println("vorbis: " + info);
        System.out.println(comment.toString());
        index = new int[info.channels];

        if (stream == null) {
          stream = new AudioStream();
          stream.setupFormat(info.channels, 16, info.rate);
          stream.updateData(this, -1);
        }

        if (masterClock instanceof SystemClock) {
          SystemClock clock = (SystemClock) masterClock;
          if (clock.needReset()) {
            clock.reset();
            System.out.println("Note: master clock was reset by audio");
          }
        }
      }
    } else {
      long gp = packet.granulepos;
      if (gp != -1) {
        lastPts = (gp * Clock.SECONDS_TO_NANOS) / info.rate;
        lastWritten = ringBuffer.getTotalWritten();
        lastRead = ringBuffer.getTotalRead();
        lastPtsWrite = System.nanoTime();
      }

      decodeDsp(packet);
    }
    packetIndex++;
  }