Package net.paulhertz.pixelaudio
Class WindowedBuffer
java.lang.Object
net.paulhertz.pixelaudio.WindowedBuffer
A windowed buffer class to permit loading large audio sources into memory and stepping through them.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final float[]private intprivate intprivate final float[]private final int -
Constructor Summary
ConstructorsConstructorDescriptionWindowedBuffer(float[] buffer, int windowSize, int hopSize) Create a windowed buffer with the given source, window size, and hop size. -
Method Summary
Modifier and TypeMethodDescriptionintExpose the underlying array size.intExpose hop size, the number of samples to advance for each window.intgetIndex()Return current buffer indexfloat[]gettWindowAtIndex(int idx) Returns the window at a supplied index.intExpose the reusable window array size.float[]Returns the next window, advancing the read index by hopSize.voidreset()Reset reader to start of buffervoidsetHopSize(int hopSize) Set the hop size, the number of samples to advance for each window.voidsetIndex(int index) Set current index.
-
Field Details
-
buffer
private final float[] buffer -
window
private final float[] window -
windowSize
private final int windowSize -
hopSize
private int hopSize -
index
private int index
-
-
Constructor Details
-
WindowedBuffer
public WindowedBuffer(float[] buffer, int windowSize, int hopSize) Create a windowed buffer with the given source, window size, and hop size.- Parameters:
buffer- the source audio datawindowSize- the number of samples in each windowhopSize- the number of samples to advance for each window (must be > 0)- Throws:
IllegalArgumentException- if buffer is empty, or if windowSize or hopSize are not positive
-
-
Method Details
-
nextWindow
public float[] nextWindow()Returns the next window, advancing the read index by hopSize. Wraps around the buffer as needed.- Returns:
- a window of audio samples from the buffer, starting at the current index and wrapping around if necessary
-
gettWindowAtIndex
public float[] gettWindowAtIndex(int idx) Returns the window at a supplied index. Wraps around the buffer as needed. Updates current index and advances it by hopSize.- Parameters:
idx- the starting index for the window (can be any integer, will be normalized to buffer length)- Returns:
- a window of audio samples from the buffer, starting at the normalized index and wrapping around if necessary
-
reset
public void reset()Reset reader to start of buffer -
getIndex
public int getIndex()Return current buffer index -
setIndex
public void setIndex(int index) Set current index. Wraps around the buffer as needed.- Parameters:
index- the new index to set (can be any integer, will be normalized to buffer length)
-
getBufferSize
public int getBufferSize()Expose the underlying array size.- Returns:
- the length of the backing buffer
-
getWindowSize
public int getWindowSize()Expose the reusable window array size.- Returns:
- the size of the window array, the number of samples in each window
-
getHopSize
public int getHopSize()Expose hop size, the number of samples to advance for each window.- Returns:
- the number of samples to advance for each window, which determines how much the index moves forward after each call to nextWindow()
-
setHopSize
public void setHopSize(int hopSize) Set the hop size, the number of samples to advance for each window.- Parameters:
hopSize- the new hop size to set (must be > 0)- Throws:
IllegalArgumentException- if hopSize is not positive
-