當前位置: 首頁>>代碼示例>>Java>>正文


Java Encoding.PCM_SIGNED屬性代碼示例

本文整理匯總了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;
}
 
開發者ID:j-dong,項目名稱:trashjam2017,代碼行數:30,代碼來源:AiffData.java

示例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);
}
 
開發者ID:arisona,項目名稱:ether,代碼行數:9,代碼來源:AACDecoder.java

示例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;
}
 
開發者ID:Blunderchips,項目名稱:Dwarf2D,代碼行數:31,代碼來源:AiffData.java

示例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;
}
 
開發者ID:juanma2268,項目名稱:jumbertoTeia2600,代碼行數:34,代碼來源:Utils.java

示例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);
   }
 
開發者ID:jtrfp,項目名稱:terminal-recall,代碼行數:18,代碼來源:JavaSoundSystemAudioOutput.java

示例6: getSourceEncodings

@Override
public AudioFormat.Encoding[] getSourceEncodings() {
    return new Encoding[]{Encoding.ALAW, Encoding.PCM_SIGNED};
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:4,代碼來源:AlawCodec.java

示例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 };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:AudioFloatFormatConverter.java

示例8: getSourceEncodings

@Override
public AudioFormat.Encoding[] getSourceEncodings() {
    return new Encoding[]{Encoding.ULAW, Encoding.PCM_SIGNED};
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:4,代碼來源:UlawCodec.java

示例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");
        }
    }
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:30,代碼來源:Matches_NOT_SPECIFIED.java

示例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());
}
 
開發者ID:arisona,項目名稱:ether,代碼行數:8,代碼來源:PCMDecoder.java

示例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();
}
 
開發者ID:arisona,項目名稱:ether,代碼行數:39,代碼來源:FrameGrab.java

示例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);
	}
}
 
開發者ID:mav-assistant,項目名稱:Mavkit,代碼行數:13,代碼來源:AudioProcessor.java

示例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);
	}
}
 
開發者ID:Arcnor,項目名稱:gdx-backend-jglfw,代碼行數:11,代碼來源:JavaSoundAudioRecorder.java

示例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);
}
 
開發者ID:pojosontheweb,項目名稱:selenium-utils,代碼行數:11,代碼來源:AudioFormatKeys.java

示例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;
}
 
開發者ID:phon-ca,項目名稱:phon,代碼行數:35,代碼來源:PCMSampled.java


注:本文中的javax.sound.sampled.AudioFormat.Encoding.PCM_SIGNED屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。