Class OpusSound
java.lang.Object
io.github.kosmx.emotes.common.opus.OpusSound
A validated mono Opus stream: its packets, and the PCM they decode to once someone asks.
The packets live back to back in one array, indexed by
offset(int) and length(int).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classLays packets back to back as they come, in the array the sound then keeps, so an encoder can write each one straight into it.static final record -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionOpusSound(int preSkip, int endTrim, int outputGain, @Nullable Integer trackGain, @Nullable Integer loopStart, byte[] data, int[] offsets) OpusSound(int preSkip, int endTrim, int outputGain, @Nullable Integer trackGain, @Nullable Integer loopStart, byte[] data, int[] offsets, List<String> comments) -
Method Summary
Modifier and TypeMethodDescription@Nullable Stringbyte[]data()decoded()decoded(BooleanSupplier cancelled) The cancellation predicate is also read on the decoder thread.intintendTrim()booleanfailed()intlength(int index) intfloatintoffset(int index) intintintplayable()intpreSkip()static OpusSoundread(InputStream input) Reads without closing the stream, for sounds that come from somewhere other than a file.static OpusSoundvoid
-
Field Details
-
NO_LOOP
public static final int NO_LOOP- See Also:
-
-
Constructor Details
-
OpusSound
public OpusSound(int preSkip, int endTrim, int outputGain, @Nullable @Nullable Integer trackGain, @Nullable @Nullable Integer loopStart, byte[] data, int[] offsets) throws OpusFormatException - Throws:
OpusFormatException
-
OpusSound
public OpusSound(int preSkip, int endTrim, int outputGain, @Nullable @Nullable Integer trackGain, @Nullable @Nullable Integer loopStart, byte[] data, int[] offsets, List<String> comments) throws OpusFormatException - Parameters:
comments- theNAME=valuecomments of the file the sound came from, which a packet does not carry- Throws:
OpusFormatException
-
-
Method Details
-
read
- Throws:
IOException
-
read
Reads without closing the stream, for sounds that come from somewhere other than a file.- Throws:
IOException
-
write
- Throws:
IOException
-
preSkip
public int preSkip() -
outputGain
public int outputGain() -
endTrim
public int endTrim()- Returns:
- the padding at the end, in samples
-
loopStart
public int loopStart()- Returns:
- where a repeat starts, in samples, or
NO_LOOP
-
packetCount
public int packetCount() -
data
public byte[] data() -
offset
public int offset(int index) -
length
public int length(int index) -
comment
-
durationMs
public int durationMs() -
playable
public int playable()- Returns:
- how many samples are left once both ends are trimmed
-
normalization
public float normalization()- Returns:
- what a decode measured the track at, or zero while its PCM is not in memory
-
decoded
- Returns:
- the PCM, decoded in the background if that has not happened yet or was reclaimed
-
decoded
The cancellation predicate is also read on the decoder thread. -
failed
public boolean failed()
-