Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions core/src/main/java/org/gagravarr/opus/OpusFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public OpusFile(OggFile ogg) throws IOException {
/**
* Loads a Opus File from the given packet reader.
*/
public OpusFile(OggPacketReader r) throws IOException {
public OpusFile(OggPacketReader r) throws IOException {
this.r = r;

OggPacket p = null;
Expand All @@ -91,7 +91,7 @@ public OpusFile(OggPacketReader r) throws IOException {
* Opens for writing.
*/
public OpusFile(OutputStream out) {
this(out, new OpusInfo(), new OpusTags());
this(out, new OpusInfo(), new OpusTags());
}
/**
* Opens for writing, based on the settings
Expand Down Expand Up @@ -178,7 +178,7 @@ public OggAudioSetupHeader getSetup() {
* Sets the maximum number of opus packets per ogg page.
* Shorter values will give less efficient storage, but
* more accurate Granule values.
* Set to -1 if you are managing the ganule change when
* Set to -1 if you are managing the granule change when
* producing your {@link OpusAudioData} packets.
*/
public void setMaxPacketsPerPage(int value) {
Expand Down Expand Up @@ -223,7 +223,7 @@ public void close() throws IOException {
if (w != null) {
w.bufferPacket(info.write(), true);
w.bufferPacket(tags.write(), false);

// The Granule Position on each Ogg Page needs to be
// the total number of PCM samples, including the last
// full Opus Packet in the page.
Expand All @@ -243,7 +243,7 @@ public void close() throws IOException {
packet = packets.get(i);
flushAfter = false;
pageSize++;

// Should we flush before this packet?
if (maxPacketsPerPage == -1) {
// User is handling granule positions
Expand All @@ -257,12 +257,12 @@ public void close() throws IOException {
}
} else {
// We are doing the granule position

// Will we need to flush after this packet?
if (pageSize >= maxPacketsPerPage) {
flushAfter = true;
}

// Calculate the packet granule
pageSamples += packet.getNumberOfSamples();
packet.setGranulePosition(lastGranule+pageSamples);
Expand All @@ -273,15 +273,16 @@ public void close() throws IOException {
if (flushAfter || w.getSizePendingFlush() > 16384) {
lastGranule = packet.getGranulePosition();
w.setGranulePosition(lastGranule);

if (i != packetsSize-1) {
w.flush();
doneFlush = true;
}
}
if (doneFlush) {
if (doneFlush) {
pageSize = 0;
pageSamples = 0;
doneFlush = false;
}
}

Expand All @@ -299,4 +300,4 @@ public void close() throws IOException {
public OggFile getOggFile() {
return ogg;
}
}
}