public class FixedSizeSampleAudioProcessor extends AudioProcessor
This class has applications for FFT (for example) where the input sample size must be a power of 2 and the underlying audio stream reader may be returning sample chunks of any size.
The processor can also provide overlapping sample windows. Call
setWindowStep(int)
to determine the slide of each sliding window. If
this is set to 0 or below, the windows will be consecutive and will not
overlap.
The only assumption made by the class about the samples is that they are whole numbers of bytes (8, 16, 24, 32 bits etc.). This is a pretty reasonable assumption.
Constructor and Description |
---|
FixedSizeSampleAudioProcessor(AudioStream stream,
int sizeRequired)
Create processor that will process chunks of the given size.
|
FixedSizeSampleAudioProcessor(AudioStream as,
int nSamplesInWindow,
int nSamplesOverlap)
Chainable constructor that takes the size of the window and the number of
samples overlap.
|
FixedSizeSampleAudioProcessor(int sizeRequired)
Create processor that will process chunks of the given size.
|
FixedSizeSampleAudioProcessor(int nSamplesInWindow,
int nSamplesOverlap)
Constructor that takes the size of the window and the size of the window
overlap.
|
Modifier and Type | Method and Description |
---|---|
int |
getWindowSize()
Returns the size of the sample window.
|
int |
getWindowStep()
Returns the step of each overlapping window.
|
boolean |
isOverlapping()
Returns whether the windows are overlapping or not.
|
SampleChunk |
nextSampleChunk()
Retrieve the next SampleChunk from the audio stream.
|
SampleChunk |
process(SampleChunk sample)
Function that takes a sample chunk and processes the chunk.
|
void |
setWindowSize(int sizeRequired)
Set the size of the window required.
|
void |
setWindowStep(int overlap)
Set the step of each overlapping window.
|
getLength, getUnderlyingStream, process, processingComplete, reset, setUnderlyingStream
iterator, seek
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public FixedSizeSampleAudioProcessor(int sizeRequired)
sizeRequired
- The size of the chunks required (in samples)public FixedSizeSampleAudioProcessor(AudioStream stream, int sizeRequired)
stream
- An audio stream to processsizeRequired
- The size of the chunks required (in samples)public FixedSizeSampleAudioProcessor(int nSamplesInWindow, int nSamplesOverlap)
nSamplesInWindow
- The number of samples in the windownSamplesOverlap
- The size of the overlappublic FixedSizeSampleAudioProcessor(AudioStream as, int nSamplesInWindow, int nSamplesOverlap)
as
- The chained audio streamnSamplesInWindow
- Samples in windownSamplesOverlap
- Samples in window overlappublic SampleChunk nextSampleChunk()
nextSampleChunk
in class AudioProcessor
AudioProcessor.nextSampleChunk()
public void setWindowStep(int overlap)
overlap
- The step of each overlapping window.public int getWindowStep()
public void setWindowSize(int sizeRequired)
sizeRequired
- The size required.public int getWindowSize()
public boolean isOverlapping()
public SampleChunk process(SampleChunk sample) throws Exception
FixedSizeSampleAudioProcessor
is
simply to change the shape of the sample chunk. You may override this
method to process the samples directly.process
in class AudioProcessor
sample
- The sample chunk to process.Exception
- If the processing could not take placeAudioProcessor.process(org.openimaj.audio.SampleChunk)