public class AudioRingBuffer extends Object
This implementation uses write/peek/remove pattern - the items are written to the buffer by one thread, then read from the buffer by another and written to the audio output.
At this point, the data is not yet removed from the buffer as we need to know first how many samples we were able to write to the output. Once this method returns, we can remove the written samples from the buffer.
Constructor and Description |
---|
AudioRingBuffer(int capacity) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all items from the buffer.
|
int |
peek(short[] outArray)
Gets elements without removing them from the buffer.
|
void |
remove(int itemCount)
Removes items from the buffer.
|
int |
write(short[] data)
Write samples to the buffer.
|
int |
write(short[] data,
int itemsCount)
Write samples to the buffer.
|
public int write(short[] data)
data
- Source array to copy data from. All elements from
this array will be copied to the ring buffer.public int write(short[] data, int itemsCount)
data
- Source array to copy data from.itemsCount
- The number of items to copy from the data
array.
The items will be copied starting from index 0.public int peek(short[] outArray)
outArray
- Destination array that the read items will be copied to.public void remove(int itemCount)
itemCount
- The number of items to remove from the buffer,
starting from current read position.public void clear()