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


Java Encoding.ULAW屬性代碼示例

本文整理匯總了Java中javax.sound.sampled.AudioFormat.Encoding.ULAW屬性的典型用法代碼示例。如果您正苦於以下問題:Java Encoding.ULAW屬性的具體用法?Java Encoding.ULAW怎麽用?Java Encoding.ULAW使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在javax.sound.sampled.AudioFormat.Encoding的用法示例。


在下文中一共展示了Encoding.ULAW屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: getSourceEncodings

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

示例3: isFormatValid

private boolean isFormatValid(AudioFormat format) {
    final int sampleSizeBits = format.getSampleSizeInBits();
    final int numChannels = format.getChannels();
    if(numChannels != 2)
	return false;
    if(sampleSizeBits != 8 && sampleSizeBits != 16 && sampleSizeBits != 32)
	return false;
    //if(format.getFrameRate() <= 0)
	//return false;
    final Encoding encoding = format.getEncoding();
    if(encoding == Encoding.ALAW || encoding == Encoding.ULAW)
	return false;
    return true;
}
 
開發者ID:jtrfp,項目名稱:terminal-recall,代碼行數:14,代碼來源:JavaSoundSystemAudioOutput.java

示例4: 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;
}
 
開發者ID:champtar,項目名稱:fmj-sourceforge-mirror,代碼行數:47,代碼來源:JavaSoundUtils.java

示例5: createAuHeader

/**
 * Used to create a "fake" AU header for fakeHeader. See
 * http://en.wikipedia.org/wiki/Au_file_format. The Au file format is a
 * simple audio file format that consists of a header of 6 32-bit words and
 * then the data (high-order byte comes first). The format was introduced by
 * Sun Microsystems.
 */
public static byte[] createAuHeader(javax.sound.sampled.AudioFormat f)
{
    byte[] result = new byte[4 * 6];
    encodeIntBE(0x2e736e64, result, 0); // the value 0x2e736e64 (four ASCII
                                        // characters ".snd")
    encodeIntBE(result.length, result, 4); // the offset to the data in
                                           // bytes. The minimum valid
                                           // number is 24 (decimal).
    encodeIntBE(0xffffffff, result, 8); // data size in bytes. If unknown,
                                        // the value 0xffffffff should be
                                        // used.

    // Data encoding format:
    // 1=8-bit ISDN u-law, 2=8-bit linear PCM [REF-PCM], 3=16-bit linear
    // PCM, 4=24-bit linear PCM,
    // 5=32-bit linear PCM, 6=32-bit IEEE floating point, 7=64-bit IEEE
    // floating point,
    // 23=8-bit ISDN u-law compressed using the UIT-T G.721 ADPCM voice data
    // encoding scheme.

    final int encoding;
    if (f.getEncoding() == Encoding.ALAW)
    {
        if (f.getSampleSizeInBits() == 8)
            encoding = 27;
        else
            return null;
    } else if (f.getEncoding() == Encoding.ULAW)
    {
        if (f.getSampleSizeInBits() == 8)
            encoding = 1;
        else
            return null;
    } else if (f.getEncoding() == Encoding.PCM_SIGNED)
    {
        // AU appears to be signed when it uses PCM
        if (f.getSampleSizeInBits() == 8)
            encoding = 2;
        else if (f.getSampleSizeInBits() == 16)
            encoding = 3;
        else if (f.getSampleSizeInBits() == 24)
            encoding = 4;
        else if (f.getSampleSizeInBits() == 32)
            encoding = 5;
        else
            return null;

        if (f.getSampleSizeInBits() > 8 && !f.isBigEndian())
            return null; // must be big-endian
    } else if (f.getEncoding() == Encoding.PCM_UNSIGNED)
    {
        // AU appears to be signed when it uses PCM
        return null;
    } else
    {
        return null;
    }

    encodeIntBE(encoding, result, 12);

    // sample rate - the number of samples/second (e.g., 8000)
    if (f.getSampleRate() < 0)
        return null;
    encodeIntBE((int) f.getSampleRate(), result, 16);

    // channels the number of interleaved channels (e.g., 1 for mono, 2 for
    // stereo)
    if (f.getChannels() < 0)
        return null;
    encodeIntBE(f.getChannels(), result, 20);

    return result;

}
 
開發者ID:champtar,項目名稱:fmj-sourceforge-mirror,代碼行數:81,代碼來源:JavaSoundCodec.java


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