public class SampleChunk extends Audio
getSamplesAsByteBuffer()
and use the
ByteBuffer
's methods asXXXBuffer (e.g. ByteBuffer#asShortBuffer)
to get the samples in a normalised form.Constructor and Description |
---|
SampleChunk(AudioFormat af)
Create a new SampleChunk buffer with the given
audio format, but do not initialise the samples.
|
SampleChunk(byte[] samples,
AudioFormat af)
Create a new sample chunk using the given samples
and the given audio format.
|
SampleChunk(byte[] samples,
AudioFormat af,
AudioTimecode tc)
Create a new sample chunk using the given samples
and the given audio format.
|
Modifier and Type | Method and Description |
---|---|
SampleChunk |
append(SampleChunk sample)
Appends the given samples to the end of this sample chunk.
|
SampleChunk |
clone() |
int |
getNumberOfSamples()
Returns the number of samples in this sample chunk.
|
SampleBuffer |
getSampleBuffer()
Returns an appropriate sample buffer for this
sample chunk.
|
byte[] |
getSamples()
Get the samples in this sample chunk
|
ByteBuffer |
getSamplesAsByteBuffer()
Returns a
ByteBuffer that can be used to create
views of the samples in the object. |
SampleChunk |
getSampleSlice(int start,
int length)
Return a slice of data from the sample array.
|
AudioTimecode |
getStartTimecode()
Get the timecode at the start of this audio chunk.
|
void |
pad(int requiredSampleSetSize)
Pads the sample chunk to the given size with zeros.
|
SampleChunk |
prepend(SampleChunk sample)
Prepends the given samples to the front of this sample chunk.
|
void |
setSamples(byte[] samples)
Set the samples in this sample chunk.
|
void |
setStartTimecode(AudioTimecode startTimecode)
Set the timecode at the start of this audio chunk.
|
public SampleChunk(AudioFormat af)
af
- The audio format of the samplespublic SampleChunk(byte[] samples, AudioFormat af)
samples
- The samples to initialise withaf
- The audio format of the samplespublic SampleChunk(byte[] samples, AudioFormat af, AudioTimecode tc)
samples
- The samples to initialise withaf
- The audio format of the samplestc
- The audio timecode of these samplespublic void setSamples(byte[] samples)
samples
- the samples in this sample chunk.public byte[] getSamples()
public int getNumberOfSamples()
public ByteBuffer getSamplesAsByteBuffer()
ByteBuffer
that can be used to create
views of the samples in the object. For example, to get short
integers, you can get getSamplesAsByteBuffer()
.asShortBuffer()ByteBuffer
public SampleBuffer getSampleBuffer()
SampleBuffer
public void setStartTimecode(AudioTimecode startTimecode)
startTimecode
- the timecode at the start of the chunk.public AudioTimecode getStartTimecode()
public SampleChunk getSampleSlice(int start, int length)
The assumption is that samples are whole numbers of bytes. So, if the sample size was 16-bits, then passing in 2 for the start index would actually index the byte at index 4 in the underlying sample array. The order of the bytes is unchanged.
start
- The start index of the sample.length
- The length of the samples get.SampleChunk
public SampleChunk prepend(SampleChunk sample)
sample
- the samples to addpublic SampleChunk append(SampleChunk sample)
sample
- the samples to addpublic SampleChunk clone()
public void pad(int requiredSampleSetSize)
requiredSampleSetSize
- The required sample size