Package com.jogamp.common.av
Class AudioFormat
- java.lang.Object
-
- com.jogamp.common.av.AudioFormat
-
public class AudioFormat extends Object
Specifies the linear audio PCM format.
-
-
Field Summary
Fields Modifier and Type Field Description int
channelCount
Number of channels, e.g.boolean
fixedP
Fixed or floating point values.boolean
littleEndian
Little-endian byte order if true, otherwise big endian byte order.boolean
planar
Planar or packed samples.int
sampleRate
Sample rate in Hz (1/s, e.g.int
sampleSize
Sample size in bits, e.g.boolean
signed
Signed PCM values if true, otherwise unsigned values.
-
Constructor Summary
Constructors Constructor Description AudioFormat(int sampleRate, int sampleSize, int channelCount, boolean signed, boolean fixedP, boolean planar, boolean littleEndian)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description float
getBytesDuration(int byteCount)
Returns the duration in seconds of the given byte count according tosampleSize
,channelCount
andsampleRate
.int
getBytesSampleCount(int byteCount)
Returns the sample count of given byte count according to thesampleSize
, i.e.:int
getDurationsByteSize(float duration)
Returns the byte size of the given duration in seconds according tosampleSize
,channelCount
andsampleRate
.int
getFrameCount(float duration, float frameDuration)
Returns the rounded frame count of the given duration and frame duration, both in seconds.int
getSamplesByteCount(int sampleCount)
Returns the byte size of given sample count according to thesampleSize
, i.e.:float
getSamplesDuration(int sampleCount)
Returns the duration in seconds of the given sample count per frame and channel according to thesampleRate
, i.e.String
toString()
-
-
-
Field Detail
-
sampleRate
public final int sampleRate
Sample rate in Hz (1/s, e.g. 44100 Hz.
-
sampleSize
public final int sampleSize
Sample size in bits, e.g. 16 bits.
-
channelCount
public final int channelCount
Number of channels, e.g. 2 channels for stereo.
-
signed
public final boolean signed
Signed PCM values if true, otherwise unsigned values.
-
fixedP
public final boolean fixedP
Fixed or floating point values. Floating point 'float' hassampleSize
32, 'double' hassampleSize
64.
-
planar
public final boolean planar
Planar or packed samples. If planar, each channel has their own data buffer. If packed, channel data is interleaved in one buffer.
-
littleEndian
public final boolean littleEndian
Little-endian byte order if true, otherwise big endian byte order.
-
-
Constructor Detail
-
AudioFormat
public AudioFormat(int sampleRate, int sampleSize, int channelCount, boolean signed, boolean fixedP, boolean planar, boolean littleEndian)
- Parameters:
sampleRate
- sample rate in Hz (1/s), e.g. 44100 HzsampleSize
- sample size in bits, e.g. 16 bitschannelCount
- number of channels, e.g. 2 channels for stereosigned
- true if signed PCM values, false for unsigned valuesfixedP
- true for fixed point values, false for unsigned floating point values with a sampleSize of 32 (float) or 64 (double)planar
- true for planar data package (each channel in own data buffer), false for packed data channels interleaved in one buffer.littleEndian
- true for little-endian byte order, false for big endian byte order
-
-
Method Detail
-
getDurationsByteSize
public final int getDurationsByteSize(float duration)
Returns the byte size of the given duration in seconds according tosampleSize
,channelCount
andsampleRate
.final float bytesPerSample = sampleSize/8; return Math.round( duration * channelCount * bytesPerSample * sampleRate );
Time -> Byte Count
- Parameters:
duration
- duration in seconds
-
getBytesDuration
public final float getBytesDuration(int byteCount)
Returns the duration in seconds of the given byte count according tosampleSize
,channelCount
andsampleRate
.final float bytesPerSample = sampleSize/8; return byteCount / ( channelCount * bytesPerSample * sampleRate )
Byte Count -> Time
- Parameters:
byteCount
- size in bytes
-
getSamplesDuration
public final float getSamplesDuration(int sampleCount)
Returns the duration in seconds of the given sample count per frame and channel according to thesampleRate
, i.e.(float)sampleCount / sampleRate
Sample Count -> Time
- Parameters:
sampleCount
- sample count per frame and channel
-
getFrameCount
public final int getFrameCount(float duration, float frameDuration)
Returns the rounded frame count of the given duration and frame duration, both in seconds.Math.max(1, Math.round( duration / frameDuration ))
Note:
frameDuration
can be derived by sample count per frame and channel viagetSamplesDuration(int)
or by byte count viagetBytesDuration(int)
.Frame Time -> Frame Count
- Parameters:
duration
- duration in secondsframeDuration
- duration per frame in seconds, i.e. 1/frame_rate- See Also:
getSamplesDuration(int)
,getBytesDuration(int)
-
getSamplesByteCount
public final int getSamplesByteCount(int sampleCount)
Returns the byte size of given sample count according to thesampleSize
, i.e.:sampleCount * ( sampleSize / 8 )
Note: To retrieve the byte size for all channels, you need to pre-multiply
sampleCount
withchannelCount
.Sample Count -> Byte Count
- Parameters:
sampleCount
- sample count
-
getBytesSampleCount
public final int getBytesSampleCount(int byteCount)
Returns the sample count of given byte count according to thesampleSize
, i.e.:( byteCount * 8 ) / sampleSize
Note: If
byteCount
covers all channels and you request the sample size per channel, you need to divide the result bysampleCount
bychannelCount
.Byte Count -> Sample Count
- Parameters:
byteCount
- number of bytes
-
-