Class PcmBuffer
java.lang.Object
net.avadeaux.klipspringer.codec.PcmBuffer
- All Implemented Interfaces:
Closeable,AutoCloseable
Intermediary for passing PCM data to a writer with matching sample rate, bit depth and number of
channels, but whose coding may differ in signedness, endianness, or padding (see blog
post about various formats). Wraps a byte buffer to provide additional operations on it,
without duplicating the operations that work on the wrapped buffer directly. Operates on
direct byte buffers (located in external memory), to make bulk data transfer efficient
from decoders and device readers implemented using external libraries, and from files read using
NIO. It is less
efficient when input comes via a
TargetDataLine, AudioInputStream, or plain InputStream, which all operate
on JVM-internal byte arrays.-
Method Summary
Modifier and TypeMethodDescriptionfinal ByteBufferGets the underlying byte buffer.voidclose()SeeCloseable.close().format()Gets the output format, used in writing to the wrapped buffer.final intReads a sample as a signed integer at the current position, and advances position.abstract intgetSample(int index) Reads a sample as a signed integer given the position of its first byte.final voidmonomix(int pos, int frames) Mixes the samples in a segment of the buffer so that all channels get the same value (the arithmetic mean of the original values.static PcmBufferof(ByteBuffer buf, PcmFormat format, Device.BitLayout lout) Constructor that wraps a byte buffer as a PCM buffer for the given output format and layout.final voidput(ByteBuffer data, PcmFormat dataFormat) Transfers data from a byte buffer into this buffer.final voidputSample(int value) Writes a signed integer sample value at the current position, and advances position.abstract voidputSample(int index, int value) Writes a signed integer sample value given the position of its first byte.
-
Method Details
-
format
Gets the output format, used in writing to the wrapped buffer. -
close
public void close()SeeCloseable.close().- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
byteBuffer
Gets the underlying byte buffer. -
getSample
public final int getSample()Reads a sample as a signed integer at the current position, and advances position. -
getSample
public abstract int getSample(int index) Reads a sample as a signed integer given the position of its first byte. -
putSample
public final void putSample(int value) Writes a signed integer sample value at the current position, and advances position. -
putSample
public abstract void putSample(int index, int value) Writes a signed integer sample value given the position of its first byte. -
put
Transfers data from a byte buffer into this buffer. The formats must match in quality, but may differ in signedness, endianness and frame size. If the data buffer is not direct, this method copies its contents to a temporary direct buffer before transferring to the internal buffer.- Throws:
IOException
-
monomix
public final void monomix(int pos, int frames) Mixes the samples in a segment of the buffer so that all channels get the same value (the arithmetic mean of the original values. -
of
Constructor that wraps a byte buffer as a PCM buffer for the given output format and layout. Sets the byte order of the byte buffer to match the format.
-