本文整理匯總了Java中javax.sound.sampled.AudioFormat.Encoding.PCM_SIGNED屬性的典型用法代碼示例。如果您正苦於以下問題:Java Encoding.PCM_SIGNED屬性的具體用法?Java Encoding.PCM_SIGNED怎麽用?Java Encoding.PCM_SIGNED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類javax.sound.sampled.AudioFormat.Encoding
的用法示例。
在下文中一共展示了Encoding.PCM_SIGNED屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: convertAudioBytes
/**
* Convert the audio bytes into the stream
*
* @param format The audio format being decoded
* @param audio_bytes The audio byts
* @param two_bytes_data True if we using double byte data
* @return The byte bufer of data
*/
private static ByteBuffer convertAudioBytes(AudioFormat format, byte[] audio_bytes, boolean two_bytes_data) {
ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
dest.order(ByteOrder.nativeOrder());
ByteBuffer src = ByteBuffer.wrap(audio_bytes);
src.order(ByteOrder.BIG_ENDIAN);
if (two_bytes_data) {
ShortBuffer dest_short = dest.asShortBuffer();
ShortBuffer src_short = src.asShortBuffer();
while (src_short.hasRemaining())
dest_short.put(src_short.get());
} else {
while (src.hasRemaining()) {
byte b = src.get();
if (format.getEncoding() == Encoding.PCM_SIGNED) {
b = (byte) (b + 127);
}
dest.put(b);
}
}
dest.rewind();
return dest;
}
示例2: AACDecoder
public AACDecoder(byte[] decoderSpecificInfo, javax.sound.sampled.AudioFormat format) throws AACException {
this.format = new AudioFormat(
(int)format.getSampleRate(),
format.getSampleSizeInBits(),
format.getChannels(),
format.getEncoding() == Encoding.PCM_SIGNED,
format.isBigEndian());
this.decoder = new Decoder(decoderSpecificInfo);
}
示例3: convertAudioBytes
/**
* Convert the audio bytes into the stream
*
* @param format The audio format being decoded
* @param audio_bytes The audio byts
* @param two_bytes_data True if we using double byte data
* @return The byte bufer of data
*/
private static ByteBuffer convertAudioBytes(AudioFormat format, byte[] audio_bytes, boolean two_bytes_data) {
ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
dest.order(ByteOrder.nativeOrder());
ByteBuffer src = ByteBuffer.wrap(audio_bytes);
src.order(ByteOrder.BIG_ENDIAN);
if (two_bytes_data) {
ShortBuffer dest_short = dest.asShortBuffer();
ShortBuffer src_short = src.asShortBuffer();
while (src_short.hasRemaining()) {
dest_short.put(src_short.get());
}
} else {
while (src.hasRemaining()) {
byte b = src.get();
if (format.getEncoding() == Encoding.PCM_SIGNED) {
b = (byte) (b + 127);
}
dest.put(b);
}
}
dest.rewind();
return dest;
}
示例4: bytesToShort
/**
* Convert the bytes starting at the given offset to a signed short based upon the AudioFormat. If the frame size
* is 1, then the value is doubled to make it match a frame size of 2.
*
* @param format the audio format
* @param byteArray the byte array
* @return a short
* @throws java.lang.ArrayIndexOutOfBoundsException
*
*/
public static short bytesToShort(AudioFormat format,
byte[] byteArray) {
short result = 0;
Encoding encoding = format.getEncoding();
int frameSize = format.getFrameSize();
if (encoding == Encoding.PCM_SIGNED) {
result = toShort(byteArray, format.isBigEndian());
if (frameSize == 1) {
result = (short) (result << 8);
}
} else if (encoding == Encoding.PCM_UNSIGNED) {
int tmp = toUnsignedShort(byteArray, format.isBigEndian());
if (frameSize == 1) {
tmp = tmp << 8;
}
result = (short) (tmp - (2 << 14));
} else if (encoding == Encoding.ULAW) {
result = ulawTable[byteArray[0] + 128];
} else {
System.out.println("Unknown encoding: " + encoding);
}
return result;
}
示例5: setFormat
@Override
public synchronized void setFormat(AudioFormat format) {
if(this.format!=format){
this.format=format;
if(format!=null){
final boolean signed = format.getEncoding() == Encoding.PCM_SIGNED;
if(format.getSampleSizeInBits()==8)
activePutter=signed?new BytePutter():new UnsignedBytePutter();
else if(format.getSampleSizeInBits()==16)
activePutter=signed?new ShortPutter():new UnsignedShortPutter();
else if(format.getSampleSizeInBits()==32)
activePutter=signed?new IntPutter():new UnsignedIntPutter();
else activePutter=null;
}
ensureSourceDataLineIsReleased();
}//Reset dependencies
setBuffer(null);
}
示例6: getSourceEncodings
@Override
public AudioFormat.Encoding[] getSourceEncodings() {
return new Encoding[]{Encoding.ALAW, Encoding.PCM_SIGNED};
}
示例7: getTargetEncodings
@Override
public Encoding[] getTargetEncodings(AudioFormat sourceFormat) {
if (AudioFloatConverter.getConverter(sourceFormat) == null)
return new Encoding[0];
return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
Encoding.PCM_FLOAT };
}
示例8: getSourceEncodings
@Override
public AudioFormat.Encoding[] getSourceEncodings() {
return new Encoding[]{Encoding.ULAW, Encoding.PCM_SIGNED};
}
示例9: main
public static void main(String[] args) throws Exception {
AudioFormat f3;
f1 = new AudioFormat(44100, 16, 2, true, false);
f2 = new AudioFormat(Encoding.PCM_SIGNED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED, false);
test(true);
// f1 = new AudioFormat(44100, 8, 16, true, false);
f2 = new AudioFormat(Encoding.PCM_SIGNED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED, true);
test(false);
f1 = new AudioFormat(44100, 8, 8, true, false);
test(true);
if (success) {
out("The test PASSED.");
} else {
out("The test FAILED.");
throw new Exception("The test FAILED");
}
}
示例10: PCMDecoder
public PCMDecoder(javax.sound.sampled.AudioFormat format) {
this.format = new AudioFormat(
(int)format.getSampleRate(),
format.getSampleSizeInBits(),
format.getChannels(),
format.getEncoding() == Encoding.PCM_SIGNED,
format.isBigEndian());
}
示例11: FrameGrab
public FrameGrab(SeekableByteChannel in) throws IOException, JCodecException {
ByteBuffer header = ByteBuffer.allocate(65536);
in.read(header);
header.flip();
Format detectFormat = JCodecUtil.detectFormat(header);
switch (detectFormat) {
case MOV:
MP4Demuxer d1 = new MP4Demuxer(in);
videoTrack = d1.getVideoTrack();
if(!(d1.getAudioTracks().isEmpty())) {
audioTrack = d1.getAudioTracks().get(0);
AudioSampleEntry as = (AudioSampleEntry) audioTrack.getSampleEntries()[0];
audioInfo = new AudioFormat(
as.getFormat().isSigned() ? Encoding.PCM_SIGNED : Encoding.PCM_UNSIGNED,
as.getFormat().getSampleRate(),
as.getFormat().getSampleSizeInBits(),
as.getFormat().getChannels(),
as.getFormat().getFrameSize(),
as.getFormat().getFrameRate(),
as.getFormat().isBigEndian());
audioDecoder = audioDecoder(as.getFourcc());
audioBuffer = ByteBuffer.allocate(96000 * audioInfo.getFrameSize() * 10);
} else {
audioTrack = null;
audioInfo = null;
audioDecoder = null;
audioBuffer = null;
}
break;
case MPEG_PS:
throw new UnsupportedFormatException("MPEG PS is temporarily unsupported.");
case MPEG_TS:
throw new UnsupportedFormatException("MPEG TS is temporarily unsupported.");
default:
throw new UnsupportedFormatException("Container format is not supported by JCodec");
}
decodeLeadingFrames();
}
示例12: start
@EnsuresNonNull({"this.mav", "this.audioFormat", "this.dataLine"})
public void start(Mavkit mav) {
this.mav = mav;
try {
AudioFormat af = new AudioFormat(Encoding.PCM_SIGNED, 44100, 16, 1, 2, 44100, true);
SourceDataLine sdl = AudioSystem.getSourceDataLine(af);
sdl.open(af);
audioFormat = af;
dataLine = sdl;
} catch (Exception e) {
throw new Panic("panic.failedAudioSystem", e);
}
}
示例13: JavaSoundAudioRecorder
public JavaSoundAudioRecorder (int samplingRate, boolean isMono) {
try {
AudioFormat format = new AudioFormat(Encoding.PCM_SIGNED, samplingRate, 16, isMono ? 1 : 2, isMono ? 2 : 4,
samplingRate, false);
line = AudioSystem.getTargetDataLine(format);
line.open(format, buffer.length);
line.start();
} catch (Exception ex) {
throw new GdxRuntimeException("Error creating JavaSoundAudioRecorder.", ex);
}
}
示例14: toAudioFormat
public static AudioFormat toAudioFormat(Format fmt) {
// We always use PCM_SIGNED or PCM_UNSIGNED
return new AudioFormat(
!fmt.containsKey(SignedKey) || fmt.get(SignedKey) ? Encoding.PCM_SIGNED : Encoding.PCM_UNSIGNED,
fmt.get(SampleRateKey).floatValue(),
fmt.get(SampleSizeInBitsKey, 16),
fmt.get(ChannelsKey, 1),
fmt.containsKey(FrameSizeKey) ? fmt.get(FrameSizeKey) : (fmt.get(SampleSizeInBitsKey, 16) + 7) / 8 * fmt.get(ChannelsKey, 1),
fmt.containsKey(FrameRateKey) ? fmt.get(FrameRateKey).floatValue() : fmt.get(SampleRateKey).floatValue(),
fmt.containsKey(ByteOrderKey) ? fmt.get(ByteOrderKey) == ByteOrder.BIG_ENDIAN : true);
}
示例15: getSample
protected int getSample(int byteOffset) {
int retVal = 0;
final AudioFormat format = getAudioFileFormat().getFormat();
if(format.getEncoding() != Encoding.PCM_SIGNED &&
format.getEncoding() != Encoding.PCM_UNSIGNED)
throw new IllegalStateException("Unknown format");
switch(format.getSampleSizeInBits()) {
case 8:
retVal = get8bitSample(byteOffset);
break;
case 12:
retVal = get12bitSample(byteOffset);
break;
case 16:
retVal = get16bitSample(byteOffset);
break;
case 24:
retVal = get24bitSample(byteOffset);
break;
case 32:
retVal = get32bitSample(byteOffset);
break;
default:
break;
}
return retVal;
}