public class Sample extends Object
Data files in other formats will cause an
IllegalArgumentException to be thrown.
| Modifier and Type | Field and Description |
|---|---|
static AudioFormat |
SC_AUDIO_FORMAT |
| Constructor and Description |
|---|
Sample(InputStream is)
Creates a
Sample with defined input stream. |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
asByteArray()
Return the interleaved samples as a
byte[]. |
static byte[] |
asByteArray(long sampleCount,
double[] sample)
Helper method to convert a double[] to a byte[] in a format that can be
used by
AudioInputStream. |
void |
decodeBytes(byte[] audioBytes,
double[] audioSamples)
Decodes bytes of audioBytes into audioSamples.
|
AudioInputStream |
getAudioInputStream()
Returns audio stream.
|
void |
getChannelSamples(int channel,
double[] interleavedSamples,
double[] channelSamples)
Extract samples of a particular channel from interleavedSamples and copy
them into channelSamples.
|
AudioFormat |
getFormat()
Returns the current format audio.
|
double[] |
getInterleavedSamples()
Returns the array of interleaved samples.
|
double[] |
getInterleavedSamples(long begin,
long end,
double[] samples)
Get the interleaved decoded samples for all channels, from sample index
begin (included) to sample index end (excluded)
and copy them into samples. |
long |
getSampleCount()
Return the number of samples of all channels.
|
void |
getStereoSamples(double[] leftSamples,
double[] rightSamples)
Convenience method.
|
String |
toString() |
public static final AudioFormat SC_AUDIO_FORMAT
public Sample(InputStream is)
Sample with defined input stream.is - input stream.public AudioInputStream getAudioInputStream()
public AudioFormat getFormat()
public long getSampleCount()
public double[] getInterleavedSamples()
public double[] getInterleavedSamples(long begin,
long end,
double[] samples)
throws IOException
begin (included) to sample index end (excluded)
and copy them into samples. end must not exceed
getSampleCount(), and the number of samples must not be so
large that the associated byte array cannot be allocated.begin - begin index.end - end index.samples - array of samples.IOException - if something gone wrong.public void getChannelSamples(int channel,
double[] interleavedSamples,
double[] channelSamples)
channel - value of channel.interleavedSamples - array of interleaved samples.channelSamples - array of channel samples.public void getStereoSamples(double[] leftSamples,
double[] rightSamples)
throws IOException
leftSamples - array of left samples.rightSamples - array of right samples.IOException - if something gone wrong.public void decodeBytes(byte[] audioBytes,
double[] audioSamples)
audioBytes - bytes of audio.audioSamples - array of audio samples.public final byte[] asByteArray()
byte[].public static byte[] asByteArray(long sampleCount,
double[] sample)
AudioInputStream. Typically this will be used with
a Sample that has been modified from its original.sampleCount - count of sample.sample - array of samples.Copyright © 2015. All rights reserved.