本文整理汇总了Java中javax.media.format.AudioFormat.LITTLE_ENDIAN属性的典型用法代码示例。如果您正苦于以下问题:Java AudioFormat.LITTLE_ENDIAN属性的具体用法?Java AudioFormat.LITTLE_ENDIAN怎么用?Java AudioFormat.LITTLE_ENDIAN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.media.format.AudioFormat
的用法示例。
在下文中一共展示了AudioFormat.LITTLE_ENDIAN属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readHeader
private void /* for now void */ readHeader()
throws IOException, BadHeaderException {
minLocation = getLocation(stream); // Should be zero
long contentLength = stream.getContentLength();
if ( contentLength != SourceStream.LENGTH_UNKNOWN ) {
double durationSeconds = contentLength / bytesPerSecond;
duration = new Time(durationSeconds);
maxLocation = contentLength;
} else {
maxLocation = Long.MAX_VALUE;
}
boolean signed = true;
boolean bigEndian = false;
format = new AudioFormat(AudioFormat.GSM,
8000, // sampleRate,
16, // sampleSizeInBits,
1, // channels,
bigEndian ? AudioFormat.BIG_ENDIAN :
AudioFormat.LITTLE_ENDIAN,
signed ? AudioFormat.SIGNED :
AudioFormat.UNSIGNED,
(blockSize * 8), // frameSizeInBits
Format.NOT_SPECIFIED,
Format.byteArray);
}
示例2: doAudioEffect
void doAudioEffect(byte [] dest, byte [] src,
int destOffset, int srcOffset,
int count, int endian) {
short sDest, sSrc, result;
if (audioEffectDiff == 0)
audioEffectDiff = 4.0f / audioEffectDurationInSamples;
if (endian == AudioFormat.LITTLE_ENDIAN) {
for (int i = 0; i < count; i+=4) {
sDest = (short) ((dest[i+destOffset] & 0xFF) | ((dest[i+destOffset+1] & 0xFF) << 8));
sSrc = (short) ((src[i+srcOffset] & 0xFF) | ((src[i+srcOffset+1] & 0xFF) << 8));
result = (short) (sDest * (1 - audioEffectCurrent) + sSrc * audioEffectCurrent);
dest[i+destOffset] = (byte) (result & 0xFF);
dest[i+destOffset+1] = (byte) ((result >> 8) & 0xFF);
sDest = (short) ((dest[i+destOffset+2] & 0xFF) | ((dest[i+destOffset+3] & 0xFF) << 8));
sSrc = (short) ((src[i+srcOffset+2] & 0xFF) | ((src[i+srcOffset+3] & 0xFF) << 8));
result = (short) (sDest * (1 - audioEffectCurrent) + sSrc * audioEffectCurrent);
dest[i+destOffset+2] = (byte) (result & 0xFF);
dest[i+destOffset+3] = (byte) ((result >> 8) & 0xFF);
audioEffectCurrent += audioEffectDiff;
}
} else {
for (int i = 0; i < count; i+=4) {
sDest = (short) ((dest[i+destOffset+1] & 0xFF) | ((dest[i+destOffset+0] & 0xFF) << 8));
sSrc = (short) ((src[i+srcOffset+1] & 0xFF) | ((src[i+srcOffset+0] & 0xFF) << 8));
result = (short) (sDest * (1 - audioEffectCurrent) + sSrc * audioEffectCurrent);
dest[i+destOffset+1] = (byte) (result & 0xFF);
dest[i+destOffset+0] = (byte) ((result >> 8) & 0xFF);
sDest = (short) ((dest[i+destOffset+3] & 0xFF) | ((dest[i+destOffset+2] & 0xFF) << 8));
sSrc = (short) ((src[i+srcOffset+3] & 0xFF) | ((src[i+srcOffset+2] & 0xFF) << 8));
result = (short) (sDest * (1 - audioEffectCurrent) + sSrc * audioEffectCurrent);
dest[i+destOffset+3] = (byte) (result & 0xFF);
dest[i+destOffset+2] = (byte) ((result >> 8) & 0xFF);
audioEffectCurrent += audioEffectDiff;
}
}
}
示例3: processData
public void processData(Buffer buf)
{
if (getMute() || buf.isDiscard() || (buf.getLength() <= 0))
{
return;
}
AudioFormat af = (AudioFormat) buf.getFormat();
byte[] data = (byte[]) buf.getData();
if (af.getEncoding().equalsIgnoreCase("LINEAR"))
{
if (af.getSampleSizeInBits() == 16)
{
int msb = 0;
int lsb = 1;
if (af.getEndian() == AudioFormat.LITTLE_ENDIAN)
{
msb = 1;
lsb = 0;
}
if (af.getSigned() == AudioFormat.SIGNED)
{
int peak = 0;
int samples = data.length / 2;
for (int i = 0; i < samples; i++)
{
int value = (data[(i * 2) + msb] << 8)
+ (data[(i * 2) + lsb] & 0xff);
if (value < 0)
{
value = -value;
}
if (value > peak)
{
peak = value;
}
}
peakLevel = peak / 32768.0f;
}
}
}
}
示例4: processData
public void processData(Buffer buf)
{
if (getMute() || buf.isDiscard() || (buf.getLength() <= 0))
{
return;
}
AudioFormat af = (AudioFormat) buf.getFormat();
byte[] data = (byte[]) buf.getData();
if (af.getEncoding().equalsIgnoreCase("LINEAR"))
{
if (af.getSampleSizeInBits() == 16)
{
int msb = 0;
int lsb = 1;
if (af.getEndian() == AudioFormat.LITTLE_ENDIAN)
{
msb = 1;
lsb = 0;
}
if (af.getSigned() == AudioFormat.SIGNED)
{
int peak = 0;
int samples = data.length / 2;
for (int i = 0; i < samples; i++)
{
int value = (data[(i * 2) + msb] << 8)
+ (data[(i * 2) + lsb] & 0xff);
if (value < 0)
{
value = -value;
}
if (value > peak)
{
peak = value;
}
}
peakLevel = peak / 32768.0f;
}
}
}
}
示例5: convertFormat
/**
* Convert javax.sound.sampled.AudioFormat to
* javax.media.format.AudioFormat.
*/
public static AudioFormat convertFormat(
javax.sound.sampled.AudioFormat format)
{
Encoding encoding = format.getEncoding();
int channels = format.getChannels();
float frameRate = format.getFrameRate();
int frameSize = format.getFrameSize() < 0 ? format.getFrameSize()
: (format.getFrameSize() * 8);
float sampleRate = format.getSampleRate();
int sampleSize = format.getSampleSizeInBits();
int endian = format.isBigEndian() ? AudioFormat.BIG_ENDIAN
: AudioFormat.LITTLE_ENDIAN;
int signed = Format.NOT_SPECIFIED;
String encodingString = AudioFormat.LINEAR;
if (encoding == Encoding.PCM_SIGNED)
{
signed = AudioFormat.SIGNED;
encodingString = AudioFormat.LINEAR;
} else if (encoding == Encoding.PCM_UNSIGNED)
{
signed = AudioFormat.UNSIGNED;
encodingString = AudioFormat.LINEAR;
} else if (encoding == Encoding.ALAW)
{
encodingString = AudioFormat.ALAW;
} else if (encoding == Encoding.ULAW)
{
encodingString = AudioFormat.ULAW;
} else
{
encodingString = encoding.toString();
}
AudioFormat jmfFormat = new AudioFormat(encodingString, sampleRate,
sampleSize, channels, endian, signed, frameSize, frameRate,
Format.byteArray);
return jmfFormat;
}
示例6: getSupportedInputFormats
/**
* Implements {@link Renderer#getSupportedInputFormats()}. Gets the list of
* input <tt>Format</tt>s supported by this <tt>Renderer</tt>.
*
* @return the list of input <tt>Format</tt>s supported by this
* <tt>Renderer</tt>
* @see Renderer#getSupportedInputFormats()
*/
public Format[] getSupportedInputFormats()
{
if (supportedInputFormats == null)
{
double[] supportedInputSampleRates
= new double[1 + Constants.AUDIO_SAMPLE_RATES.length];
int supportedInputSampleRateCount = 0;
supportedInputSampleRates[supportedInputSampleRateCount]
= AudioTrack.getNativeOutputSampleRate(getStreamType());
supportedInputSampleRateCount++;
System.arraycopy(
Constants.AUDIO_SAMPLE_RATES, 0,
supportedInputSampleRates, supportedInputSampleRateCount,
Constants.AUDIO_SAMPLE_RATES.length);
supportedInputSampleRateCount
+= Constants.AUDIO_SAMPLE_RATES.length;
supportedInputFormats
= new Format[2 * supportedInputSampleRateCount];
for (int i = 0; i < supportedInputSampleRateCount; i++)
{
double sampleRate = supportedInputSampleRates[i];
supportedInputFormats[2 * i]
= new AudioFormat(
AudioFormat.LINEAR,
sampleRate,
16 /* sampleSizeInBits */,
Format.NOT_SPECIFIED /* channels */,
AudioFormat.LITTLE_ENDIAN,
AudioFormat.SIGNED,
Format.NOT_SPECIFIED /* frameSizeInBits */,
Format.NOT_SPECIFIED /* frameRate */,
Format.byteArray);
supportedInputFormats[2 * i + 1]
= new AudioFormat(
AudioFormat.LINEAR,
sampleRate,
8 /* sampleSizeInBits */,
Format.NOT_SPECIFIED /* channels */,
AudioFormat.LITTLE_ENDIAN,
AudioFormat.SIGNED,
Format.NOT_SPECIFIED /* frameSizeInBits */,
Format.NOT_SPECIFIED /* frameRate */,
Format.byteArray);
}
}
return supportedInputFormats.clone();
}