java类javax.sound.sampled.AudioFormat.Encoding的实例源码

AiffData.java 文件源码 项目:trashjam2017 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AiffData.java 文件源码 项目:Progetto-C 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AiffData.java 文件源码 项目:BaseClient 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AudioFloatFormatConverter.java 文件源码 项目:OpenJSharp 阅读 17 收藏 0 点赞 0 评论 0
public AudioInputStream getAudioInputStream(Encoding targetEncoding,
        AudioInputStream sourceStream) {
    if (sourceStream.getFormat().getEncoding().equals(targetEncoding))
        return sourceStream;
    AudioFormat format = sourceStream.getFormat();
    int channels = format.getChannels();
    Encoding encoding = targetEncoding;
    float samplerate = format.getSampleRate();
    int bits = format.getSampleSizeInBits();
    boolean bigendian = format.isBigEndian();
    if (targetEncoding.equals(Encoding.PCM_FLOAT))
        bits = 32;
    AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
            channels, channels * bits / 8, samplerate, bigendian);
    return getAudioInputStream(targetFormat, sourceStream);
}
AudioFloatFormatConverter.java 文件源码 项目:jdk8u-jdk 阅读 21 收藏 0 点赞 0 评论 0
public AudioInputStream getAudioInputStream(Encoding targetEncoding,
        AudioInputStream sourceStream) {
    if (sourceStream.getFormat().getEncoding().equals(targetEncoding))
        return sourceStream;
    AudioFormat format = sourceStream.getFormat();
    int channels = format.getChannels();
    Encoding encoding = targetEncoding;
    float samplerate = format.getSampleRate();
    int bits = format.getSampleSizeInBits();
    boolean bigendian = format.isBigEndian();
    if (targetEncoding.equals(Encoding.PCM_FLOAT))
        bits = 32;
    AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
            channels, channels * bits / 8, samplerate, bigendian);
    return getAudioInputStream(targetFormat, sourceStream);
}
PCM_FLOAT_support.java 文件源码 项目:jdk8u-jdk 阅读 26 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    // 1st checks Encoding.PCM_FLOAT is available
    pcmFloatEnc = Encoding.PCM_FLOAT;

    Encoding[] encodings = AudioSystem.getTargetEncodings(pcmFloatEnc);
    out("conversion from PCM_FLOAT to " + encodings.length + " encodings:");
    for (Encoding e: encodings) {
        out("  - " + e);
    }
    if (encodings.length == 0) {
        testFailed = true;
    }

    test(Encoding.PCM_SIGNED);
    test(Encoding.PCM_UNSIGNED);

    if (testFailed) {
        throw new Exception("test failed");
    }
    out("test passed.");
}
PCMtoPCMCodec.java 文件源码 项目:openjdk-jdk10 阅读 18 收藏 0 点赞 0 评论 0
@Override
public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){
    Objects.requireNonNull(targetEncoding);

    // filter out targetEncoding from the old getOutputFormats( sourceFormat ) method

    AudioFormat[] formats = getOutputFormats( sourceFormat );
    Vector<AudioFormat> newFormats = new Vector<>();
    for(int i=0; i<formats.length; i++ ) {
        if( formats[i].getEncoding().equals( targetEncoding ) ) {
            newFormats.addElement( formats[i] );
        }
    }

    AudioFormat[] formatArray = new AudioFormat[newFormats.size()];

    for (int i = 0; i < formatArray.length; i++) {
        formatArray[i] = newFormats.elementAt(i);
    }

    return formatArray;
}
PCMtoPCMCodec.java 文件源码 项目:openjdk-jdk10 阅读 19 收藏 0 点赞 0 评论 0
@Override
public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream) {

    if( isConversionSupported(targetEncoding, sourceStream.getFormat()) ) {

        AudioFormat sourceFormat = sourceStream.getFormat();
        AudioFormat targetFormat = new AudioFormat( targetEncoding,
                                                    sourceFormat.getSampleRate(),
                                                    sourceFormat.getSampleSizeInBits(),
                                                    sourceFormat.getChannels(),
                                                    sourceFormat.getFrameSize(),
                                                    sourceFormat.getFrameRate(),
                                                    sourceFormat.isBigEndian() );

        return getConvertedStream(targetFormat, sourceStream);

    } else {
        throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetEncoding.toString() );
    }

}
AudioFloatFormatConverter.java 文件源码 项目:openjdk-jdk10 阅读 17 收藏 0 点赞 0 评论 0
@Override
public AudioInputStream getAudioInputStream(Encoding targetEncoding,
                                            AudioInputStream sourceStream) {
    if (!isConversionSupported(targetEncoding, sourceStream.getFormat())) {
        throw new IllegalArgumentException(
                "Unsupported conversion: " + sourceStream.getFormat()
                        .toString() + " to " + targetEncoding.toString());
    }
    if (sourceStream.getFormat().getEncoding().equals(targetEncoding))
        return sourceStream;
    AudioFormat format = sourceStream.getFormat();
    int channels = format.getChannels();
    Encoding encoding = targetEncoding;
    float samplerate = format.getSampleRate();
    int bits = format.getSampleSizeInBits();
    boolean bigendian = format.isBigEndian();
    if (targetEncoding.equals(Encoding.PCM_FLOAT))
        bits = 32;
    AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
            channels, channels * bits / 8, samplerate, bigendian);
    return getAudioInputStream(targetFormat, sourceStream);
}
Bits32ToFromFloatArray.java 文件源码 项目:openjdk-jdk10 阅读 15 收藏 0 点赞 0 评论 0
private static void test(final Encoding enc, final byte[] expected,
                         boolean end) {
    AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
                                     end);
    byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
    AudioFloatConverter conv = AudioFloatConverter.getConverter(af);

    conv.toByteArray(FLOATS, bytes);

    if (!Arrays.equals(bytes, expected)) {
        System.err.println("Actual: " + Arrays.toString(bytes));
        System.err.println("Expected: " + Arrays.toString(expected));
        throw new RuntimeException();
    }

    float[] floats = new float[bytes.length / af.getFrameSize()];
    conv.toFloatArray(bytes, floats);

    if (!Arrays.equals(floats, FLOATS)) {
        System.err.println("Actual: " + Arrays.toString(floats));
        System.err.println("Expected: " + Arrays.toString(FLOATS));
        throw new RuntimeException();
    }
}
Bits64ToFromFloatArray.java 文件源码 项目:openjdk-jdk10 阅读 18 收藏 0 点赞 0 评论 0
private static void test(final Encoding enc, final byte[] expected,
                         boolean end) {
    System.err.println(enc);
    AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
                                     end);
    byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
    AudioFloatConverter conv = AudioFloatConverter.getConverter(af);

    conv.toByteArray(FLOATS, bytes);

    if (!Arrays.equals(bytes, expected)) {
        System.err.println("Actual:   " + Arrays.toString(bytes));
        System.err.println("Expected: " + Arrays.toString(expected));
        throw new RuntimeException();
    }

    float[] floats = new float[bytes.length / af.getFrameSize()];
    conv.toFloatArray(bytes, floats);

    if (!Arrays.equals(floats, FLOATS)) {
        System.err.println("Actual: " + Arrays.toString(floats));
        System.err.println("Expected: " + Arrays.toString(FLOATS));
        throw new RuntimeException();
    }
}
Bits24ToFromFloatArray.java 文件源码 项目:openjdk-jdk10 阅读 16 收藏 0 点赞 0 评论 0
private static void test(final Encoding enc, final byte[] expected,
                         boolean end) {
    System.err.println(enc);
    AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
                                     end);
    byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
    AudioFloatConverter conv = AudioFloatConverter.getConverter(af);

    conv.toByteArray(FLOATS, bytes);

    if (!Arrays.equals(bytes, expected)) {
        System.err.println("Actual: " + Arrays.toString(bytes));
        System.err.println("Expected: " + Arrays.toString(expected));
        throw new RuntimeException();
    }

    float[] floats = new float[bytes.length / af.getFrameSize()];
    conv.toFloatArray(bytes, floats);

    if (!Arrays.equals(floats, FLOATS)) {
        System.err.println("Actual: " + Arrays.toString(floats));
        System.err.println("Expected: " + Arrays.toString(FLOATS));
        throw new RuntimeException();
    }
}
Bits16ToFromFloatArray.java 文件源码 项目:openjdk-jdk10 阅读 18 收藏 0 点赞 0 评论 0
private static void test(final Encoding enc, final byte[] expected,
                         boolean end) {
    System.err.println("enc = " + enc);
    AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
                                     end);
    byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
    AudioFloatConverter conv = AudioFloatConverter.getConverter(af);

    conv.toByteArray(FLOATS, bytes);

    if (!Arrays.equals(bytes, expected)) {
        System.err.println("Actual: " + Arrays.toString(bytes));
        System.err.println("Expected: " + Arrays.toString(expected));
        throw new RuntimeException();
    }

    float[] floats = new float[bytes.length / af.getFrameSize()];
    conv.toFloatArray(bytes, floats);

    if (!Arrays.equals(floats, FLOATS)) {
        System.err.println("Actual: " + Arrays.toString(floats));
        System.err.println("Expected: " + Arrays.toString(FLOATS));
        throw new RuntimeException();
    }
}
Bits8ToFromFloatArray.java 文件源码 项目:openjdk-jdk10 阅读 17 收藏 0 点赞 0 评论 0
private static void test(final Encoding enc, final byte[] expected) {
    AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
                                     true);
    byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
    AudioFloatConverter conv = AudioFloatConverter.getConverter(af);

    conv.toByteArray(FLOATS, bytes);

    if (!Arrays.equals(bytes, expected)) {
        System.err.println("Actual: " + Arrays.toString(bytes));
        System.err.println("Expected: " + Arrays.toString(expected));
        throw new RuntimeException();
    }

    float[] floats = new float[bytes.length / af.getFrameSize()];
    conv.toFloatArray(bytes, floats);

    if (!Arrays.equals(floats, FLOATS)) {
        System.err.println("Actual: " + Arrays.toString(floats));
        System.err.println("Expected: " + Arrays.toString(FLOATS));
        throw new RuntimeException();
    }
}
PCM_FLOAT_support.java 文件源码 项目:openjdk-jdk10 阅读 24 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    // 1st checks Encoding.PCM_FLOAT is available
    pcmFloatEnc = Encoding.PCM_FLOAT;

    Encoding[] encodings = AudioSystem.getTargetEncodings(pcmFloatEnc);
    out("conversion from PCM_FLOAT to " + encodings.length + " encodings:");
    for (Encoding e: encodings) {
        out("  - " + e);
    }
    if (encodings.length == 0) {
        testFailed = true;
    }

    test(Encoding.PCM_SIGNED);
    test(Encoding.PCM_UNSIGNED);

    if (testFailed) {
        throw new Exception("test failed");
    }
    out("test passed.");
}
AiffData.java 文件源码 项目:Towan 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AudioFloatFormatConverter.java 文件源码 项目:openjdk9 阅读 19 收藏 0 点赞 0 评论 0
public AudioInputStream getAudioInputStream(Encoding targetEncoding,
        AudioInputStream sourceStream) {
    if (!isConversionSupported(targetEncoding, sourceStream.getFormat())) {
        throw new IllegalArgumentException(
                "Unsupported conversion: " + sourceStream.getFormat()
                        .toString() + " to " + targetEncoding.toString());
    }
    if (sourceStream.getFormat().getEncoding().equals(targetEncoding))
        return sourceStream;
    AudioFormat format = sourceStream.getFormat();
    int channels = format.getChannels();
    Encoding encoding = targetEncoding;
    float samplerate = format.getSampleRate();
    int bits = format.getSampleSizeInBits();
    boolean bigendian = format.isBigEndian();
    if (targetEncoding.equals(Encoding.PCM_FLOAT))
        bits = 32;
    AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
            channels, channels * bits / 8, samplerate, bigendian);
    return getAudioInputStream(targetFormat, sourceStream);
}
Bits32ToFromFloatArray.java 文件源码 项目:openjdk9 阅读 20 收藏 0 点赞 0 评论 0
private static void test(final Encoding enc, final byte[] expected,
                         boolean end) {
    AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
                                     end);
    byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
    AudioFloatConverter conv = AudioFloatConverter.getConverter(af);

    conv.toByteArray(FLOATS, bytes);

    if (!Arrays.equals(bytes, expected)) {
        System.err.println("Actual: " + Arrays.toString(bytes));
        System.err.println("Expected: " + Arrays.toString(expected));
        throw new RuntimeException();
    }

    float[] floats = new float[bytes.length / af.getFrameSize()];
    conv.toFloatArray(bytes, floats);

    if (!Arrays.equals(floats, FLOATS)) {
        System.err.println("Actual: " + Arrays.toString(floats));
        System.err.println("Expected: " + Arrays.toString(FLOATS));
        throw new RuntimeException();
    }
}
Bits64ToFromFloatArray.java 文件源码 项目:openjdk9 阅读 19 收藏 0 点赞 0 评论 0
private static void test(final Encoding enc, final byte[] expected,
                         boolean end) {
    System.err.println(enc);
    AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
                                     end);
    byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
    AudioFloatConverter conv = AudioFloatConverter.getConverter(af);

    conv.toByteArray(FLOATS, bytes);

    if (!Arrays.equals(bytes, expected)) {
        System.err.println("Actual:   " + Arrays.toString(bytes));
        System.err.println("Expected: " + Arrays.toString(expected));
        throw new RuntimeException();
    }

    float[] floats = new float[bytes.length / af.getFrameSize()];
    conv.toFloatArray(bytes, floats);

    if (!Arrays.equals(floats, FLOATS)) {
        System.err.println("Actual: " + Arrays.toString(floats));
        System.err.println("Expected: " + Arrays.toString(FLOATS));
        throw new RuntimeException();
    }
}
Bits24ToFromFloatArray.java 文件源码 项目:openjdk9 阅读 18 收藏 0 点赞 0 评论 0
private static void test(final Encoding enc, final byte[] expected,
                         boolean end) {
    System.err.println(enc);
    AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
                                     end);
    byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
    AudioFloatConverter conv = AudioFloatConverter.getConverter(af);

    conv.toByteArray(FLOATS, bytes);

    if (!Arrays.equals(bytes, expected)) {
        System.err.println("Actual: " + Arrays.toString(bytes));
        System.err.println("Expected: " + Arrays.toString(expected));
        throw new RuntimeException();
    }

    float[] floats = new float[bytes.length / af.getFrameSize()];
    conv.toFloatArray(bytes, floats);

    if (!Arrays.equals(floats, FLOATS)) {
        System.err.println("Actual: " + Arrays.toString(floats));
        System.err.println("Expected: " + Arrays.toString(FLOATS));
        throw new RuntimeException();
    }
}
Bits16ToFromFloatArray.java 文件源码 项目:openjdk9 阅读 21 收藏 0 点赞 0 评论 0
private static void test(final Encoding enc, final byte[] expected,
                         boolean end) {
    System.err.println("enc = " + enc);
    AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
                                     end);
    byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
    AudioFloatConverter conv = AudioFloatConverter.getConverter(af);

    conv.toByteArray(FLOATS, bytes);

    if (!Arrays.equals(bytes, expected)) {
        System.err.println("Actual: " + Arrays.toString(bytes));
        System.err.println("Expected: " + Arrays.toString(expected));
        throw new RuntimeException();
    }

    float[] floats = new float[bytes.length / af.getFrameSize()];
    conv.toFloatArray(bytes, floats);

    if (!Arrays.equals(floats, FLOATS)) {
        System.err.println("Actual: " + Arrays.toString(floats));
        System.err.println("Expected: " + Arrays.toString(FLOATS));
        throw new RuntimeException();
    }
}
Bits8ToFromFloatArray.java 文件源码 项目:openjdk9 阅读 17 收藏 0 点赞 0 评论 0
private static void test(final Encoding enc, final byte[] expected) {
    AudioFormat af = new AudioFormat(enc, 44100, SIZE, 1, SIZE / 8, 44100,
                                     true);
    byte[] bytes = new byte[FLOATS.length * af.getFrameSize()];
    AudioFloatConverter conv = AudioFloatConverter.getConverter(af);

    conv.toByteArray(FLOATS, bytes);

    if (!Arrays.equals(bytes, expected)) {
        System.err.println("Actual: " + Arrays.toString(bytes));
        System.err.println("Expected: " + Arrays.toString(expected));
        throw new RuntimeException();
    }

    float[] floats = new float[bytes.length / af.getFrameSize()];
    conv.toFloatArray(bytes, floats);

    if (!Arrays.equals(floats, FLOATS)) {
        System.err.println("Actual: " + Arrays.toString(floats));
        System.err.println("Expected: " + Arrays.toString(FLOATS));
        throw new RuntimeException();
    }
}
PCM_FLOAT_support.java 文件源码 项目:openjdk9 阅读 26 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    // 1st checks Encoding.PCM_FLOAT is available
    pcmFloatEnc = Encoding.PCM_FLOAT;

    Encoding[] encodings = AudioSystem.getTargetEncodings(pcmFloatEnc);
    out("conversion from PCM_FLOAT to " + encodings.length + " encodings:");
    for (Encoding e: encodings) {
        out("  - " + e);
    }
    if (encodings.length == 0) {
        testFailed = true;
    }

    test(Encoding.PCM_SIGNED);
    test(Encoding.PCM_UNSIGNED);

    if (testFailed) {
        throw new Exception("test failed");
    }
    out("test passed.");
}
StretchedAudioInputStream.java 文件源码 项目:pumpernickel 阅读 19 收藏 0 点赞 0 评论 0
/** Create a StretchedAudioInputStream that distorts the incoming
 * audio so it matches a fixed number of frames.
 * 
 * @param in the AudioInputStream to stretch.
 * @param frames the number of frames the input stream should be stretched to.
 * @throws IOException if an IO problem occurs.
 */
public static StretchedAudioInputStream create(AudioInputStream in,long frames) throws IOException {
    AudioFormat format = in.getFormat();
    if(!(format.getEncoding().equals(Encoding.PCM_SIGNED) ||
            format.getEncoding().equals(Encoding.PCM_UNSIGNED) ))
        throw new IllegalArgumentException("the audio input must be PCM-encoded data (found "+format.getEncoding()+")");

    PipedInputStream pipedIn = new PipedInputStream();
    PipedOutputStream pipedOut = new PipedOutputStream(pipedIn);

    /** One flaw with this model is that we always generate ALL the
     * transformed data: even if the entity working with pipedIn
     * is trying to skip large chunks of data.
     */

    Thread thread = new StretchThread(in, format, frames, pipedOut);
    thread.start();
    return new StretchedAudioInputStream( pipedIn, format, frames);
}
AudioFloatFormatConverter.java 文件源码 项目:jdk8u_jdk 阅读 18 收藏 0 点赞 0 评论 0
public AudioInputStream getAudioInputStream(Encoding targetEncoding,
        AudioInputStream sourceStream) {
    if (sourceStream.getFormat().getEncoding().equals(targetEncoding))
        return sourceStream;
    AudioFormat format = sourceStream.getFormat();
    int channels = format.getChannels();
    Encoding encoding = targetEncoding;
    float samplerate = format.getSampleRate();
    int bits = format.getSampleSizeInBits();
    boolean bigendian = format.isBigEndian();
    if (targetEncoding.equals(Encoding.PCM_FLOAT))
        bits = 32;
    AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
            channels, channels * bits / 8, samplerate, bigendian);
    return getAudioInputStream(targetFormat, sourceStream);
}
PCM_FLOAT_support.java 文件源码 项目:jdk8u_jdk 阅读 24 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    // 1st checks Encoding.PCM_FLOAT is available
    pcmFloatEnc = Encoding.PCM_FLOAT;

    Encoding[] encodings = AudioSystem.getTargetEncodings(pcmFloatEnc);
    out("conversion from PCM_FLOAT to " + encodings.length + " encodings:");
    for (Encoding e: encodings) {
        out("  - " + e);
    }
    if (encodings.length == 0) {
        testFailed = true;
    }

    test(Encoding.PCM_SIGNED);
    test(Encoding.PCM_UNSIGNED);

    if (testFailed) {
        throw new Exception("test failed");
    }
    out("test passed.");
}
AudioFloatFormatConverter.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 20 收藏 0 点赞 0 评论 0
public AudioInputStream getAudioInputStream(Encoding targetEncoding,
        AudioInputStream sourceStream) {
    if (sourceStream.getFormat().getEncoding().equals(targetEncoding))
        return sourceStream;
    AudioFormat format = sourceStream.getFormat();
    int channels = format.getChannels();
    Encoding encoding = targetEncoding;
    float samplerate = format.getSampleRate();
    int bits = format.getSampleSizeInBits();
    boolean bigendian = format.isBigEndian();
    if (targetEncoding.equals(Encoding.PCM_FLOAT))
        bits = 32;
    AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
            channels, channels * bits / 8, samplerate, bigendian);
    return getAudioInputStream(targetFormat, sourceStream);
}
PCM_FLOAT_support.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 20 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    // 1st checks Encoding.PCM_FLOAT is available
    pcmFloatEnc = Encoding.PCM_FLOAT;

    Encoding[] encodings = AudioSystem.getTargetEncodings(pcmFloatEnc);
    out("conversion from PCM_FLOAT to " + encodings.length + " encodings:");
    for (Encoding e: encodings) {
        out("  - " + e);
    }
    if (encodings.length == 0) {
        testFailed = true;
    }

    test(Encoding.PCM_SIGNED);
    test(Encoding.PCM_UNSIGNED);

    if (testFailed) {
        throw new Exception("test failed");
    }
    out("test passed.");
}
TGMixer.java 文件源码 项目:TuxGuitar-1.3.1-fork 阅读 17 收藏 0 点赞 0 评论 0
public TGMixer() {
    super(new Line.Info(Mixer.class));

    this.lines = new HashMap<Class<?>, Line>();
    this.sourceLineInfo = new ArrayList<DataLine.Info>();
    this.targetLineInfo = new ArrayList<DataLine.Info>();

    List<AudioFormat> formats = new ArrayList<AudioFormat>();
    for (int channels = 1; channels <= 2; channels++) {
        formats.add(new AudioFormat(Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, 8, channels, channels, AudioSystem.NOT_SPECIFIED, false)); 
        formats.add(new AudioFormat(Encoding.PCM_UNSIGNED, AudioSystem.NOT_SPECIFIED, 8, channels, channels, AudioSystem.NOT_SPECIFIED, false));
            for (int bits = 16; bits < 32; bits += 8) {
                formats.add(new AudioFormat(Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, bits, channels, channels * bits / 8, AudioSystem.NOT_SPECIFIED, false));
                formats.add(new AudioFormat(Encoding.PCM_UNSIGNED, AudioSystem.NOT_SPECIFIED, bits, channels, channels * bits / 8, AudioSystem.NOT_SPECIFIED, false));
                formats.add(new AudioFormat(Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, bits, channels, channels * bits / 8, AudioSystem.NOT_SPECIFIED, true));
                formats.add(new AudioFormat(Encoding.PCM_UNSIGNED, AudioSystem.NOT_SPECIFIED, bits, channels, channels * bits / 8, AudioSystem.NOT_SPECIFIED, true));
            }
            formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4, AudioSystem.NOT_SPECIFIED, false));
            formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4, AudioSystem.NOT_SPECIFIED, true));
            formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8, AudioSystem.NOT_SPECIFIED, false));
            formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8, AudioSystem.NOT_SPECIFIED, true));
        }

        this.sourceLineInfo.add(new DataLine.Info(SourceDataLine.class, formats.toArray(new AudioFormat[formats.size()]), AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED));
}
AudioFloatFormatConverter.java 文件源码 项目:TuxGuitar-1.3.1-fork 阅读 21 收藏 0 点赞 0 评论 0
public AudioInputStream getAudioInputStream(Encoding targetEncoding,
        AudioInputStream sourceStream) {
    if (sourceStream.getFormat().getEncoding().equals(targetEncoding))
        return sourceStream;
    AudioFormat format = sourceStream.getFormat();
    int channels = format.getChannels();
    Encoding encoding = targetEncoding;
    float samplerate = format.getSampleRate();
    int bits = format.getSampleSizeInBits();
    boolean bigendian = format.isBigEndian();
    if (targetEncoding.equals(AudioFloatConverter.PCM_FLOAT))
        bits = 32;
    AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
            channels, channels * bits / 8, samplerate, bigendian);
    return getAudioInputStream(targetFormat, sourceStream);
}


问题


面经


文章

微信
公众号

扫码关注公众号