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

Toolkit.java 文件源码 项目:openjdk-jdk10 阅读 27 收藏 0 点赞 0 评论 0
static void isFullySpecifiedAudioFormat(AudioFormat format) {
    if (!format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)
        && !format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED)
        && !format.getEncoding().equals(AudioFormat.Encoding.ULAW)
        && !format.getEncoding().equals(AudioFormat.Encoding.ALAW)) {
        // we don't know how to verify possibly non-linear encodings
        return;
    }
    if (format.getFrameRate() <= 0) {
        throw new IllegalArgumentException("invalid frame rate: "
                                           +((format.getFrameRate()==-1)?
                                             "NOT_SPECIFIED":String.valueOf(format.getFrameRate())));
    }
    if (format.getSampleRate() <= 0) {
        throw new IllegalArgumentException("invalid sample rate: "
                                           +((format.getSampleRate()==-1)?
                                             "NOT_SPECIFIED":String.valueOf(format.getSampleRate())));
    }
    if (format.getSampleSizeInBits() <= 0) {
        throw new IllegalArgumentException("invalid sample size in bits: "
                                           +((format.getSampleSizeInBits()==-1)?
                                             "NOT_SPECIFIED":String.valueOf(format.getSampleSizeInBits())));
    }
    if (format.getFrameSize() <= 0) {
        throw new IllegalArgumentException("invalid frame size: "
                                           +((format.getFrameSize()==-1)?
                                             "NOT_SPECIFIED":String.valueOf(format.getFrameSize())));
    }
    if (format.getChannels() <= 0) {
        throw new IllegalArgumentException("invalid number of channels: "
                                           +((format.getChannels()==-1)?
                                             "NOT_SPECIFIED":String.valueOf(format.getChannels())));
    }
}
Minim.java 文件源码 项目:romanov 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Loads the requested file into an {@link AudioPlayer} with the request
 * buffer size.
 * 
 * @param filename
 *            the file or URL you want to load
 * @param bufferSize
 *            int: the sample buffer size you want, which determines the 
 *            size of the left, right, and mix AudioBuffer fields of the 
 *            returned AudioPlayer.
 * 
 * @return an <code>AudioPlayer</code> with a sample buffer of the requested
 *         size, or null if we were unable to load the file
 */
public AudioPlayer loadFile(String filename, int bufferSize)
{
    AudioPlayer player          = null;
    AudioRecordingStream rec    = mimp.getAudioRecordingStream( filename, bufferSize, false );
    if ( rec != null )
    {
        AudioFormat format  = rec.getFormat();
        AudioOut out        = mimp.getAudioOutput( format.getChannels(),
                                                   bufferSize, 
                                                   format.getSampleRate(),
                                                   format.getSampleSizeInBits() );

        if ( out != null )
        {
            player = new AudioPlayer( rec, out );
        }
        else
        {
            rec.close();
        }
    }

    if ( player != null )
    {
        addSource( player );
    }
    else
    {
        error( "Couldn't load the file " + filename );
    }

    return player;
}
PCMtoPCMCodec.java 文件源码 项目:jdk8u-jdk 阅读 17 收藏 0 点赞 0 评论 0
/**
 */
public AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat){

    if( sourceFormat.getEncoding().equals( AudioFormat.Encoding.PCM_SIGNED ) ||
        sourceFormat.getEncoding().equals( AudioFormat.Encoding.PCM_UNSIGNED ) ) {

            AudioFormat.Encoding encs[] = new AudioFormat.Encoding[2];
            encs[0] = AudioFormat.Encoding.PCM_SIGNED;
            encs[1] = AudioFormat.Encoding.PCM_UNSIGNED;
            return encs;
        } else {
            return new AudioFormat.Encoding[0];
        }
}
ManualTestEchoCancel2.java 文件源码 项目:rcom 阅读 18 收藏 0 点赞 0 评论 0
public static AudioFormat getFormat() {
    float sampleRate = 8000;
    int sampleSizeInBits = 16;
    int channels = 1;
    boolean signed = true;
    // The platform default byte order
    boolean bigEndian = ByteOrder.nativeOrder()==ByteOrder.BIG_ENDIAN;
    return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian);
}
DirectAudioDevice.java 文件源码 项目:openjdk-jdk10 阅读 25 收藏 0 点赞 0 评论 0
@Override
public void open(AudioFormat format, byte[] data, int offset, int bufferSize)
    throws LineUnavailableException {

    // $$fb part of fix for 4679187: Clip.open() throws unexpected Exceptions
    Toolkit.isFullySpecifiedAudioFormat(format);
    Toolkit.validateBuffer(format.getFrameSize(), bufferSize);

    byte[] newData = new byte[bufferSize];
    System.arraycopy(data, offset, newData, 0, bufferSize);
    open(format, newData, bufferSize / format.getFrameSize());
}
RecognizeHugeWaveExtFiles.java 文件源码 项目:openjdk-jdk10 阅读 18 收藏 0 点赞 0 评论 0
/**
 * Tests the {@code AudioFileFormat} fetched from the fake header.
 * <p>
 * Note that the frameLength and byteLength are stored as int which means
 * that {@code AudioFileFormat} will store the data above {@code MAX_INT} as
 * NOT_SPECIFIED.
 */
private static void testAFF(final int[] type, final int rate,
                            final int channel, final long size)
        throws Exception {
    final byte[] header = createHeader(type, rate, channel, size);
    final ByteArrayInputStream fake = new ByteArrayInputStream(header);
    final AudioFileFormat aff = AudioSystem.getAudioFileFormat(fake);
    final AudioFormat format = aff.getFormat();

    if (aff.getType() != AudioFileFormat.Type.WAVE) {
        throw new RuntimeException("Error");
    }

    final long frameLength = size / format.getFrameSize();
    if (frameLength <= Integer.MAX_VALUE) {
        if (aff.getFrameLength() != frameLength) {
            System.err.println("Expected: " + frameLength);
            System.err.println("Actual: " + aff.getFrameLength());
            throw new RuntimeException();
        }
    } else {
        if (aff.getFrameLength() != AudioSystem.NOT_SPECIFIED) {
            System.err.println("Expected: " + AudioSystem.NOT_SPECIFIED);
            System.err.println("Actual: " + aff.getFrameLength());
            throw new RuntimeException();
        }
    }
    validateFormat(type[1], rate, channel, aff.getFormat());
}
MicThread.java 文件源码 项目:tcc-rpg 阅读 19 收藏 0 点赞 0 评论 0
public MicThread(ObjectOutputStream toServer) throws LineUnavailableException {
    this.toServer = toServer;
    //open microphone line, an exception is thrown in case of error
    AudioFormat af = SoundPacket.defaultFormat;
    DataLine.Info info = new DataLine.Info(TargetDataLine.class, null);
    mic = (TargetDataLine) (AudioSystem.getLine(info));
    mic.open(af);
    mic.start();
}
ManualTestEchoCancel.java 文件源码 项目:rcom 阅读 18 收藏 0 点赞 0 评论 0
public static AudioFormat getFormat() {
    float sampleRate = 8000;
    int sampleSizeInBits = 16;
    int channels = 1;
    boolean signed = true;
    // The platform default byte order
    boolean bigEndian = ByteOrder.nativeOrder()==ByteOrder.BIG_ENDIAN;
    return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian);
}
AlawCodec.java 文件源码 项目:openjdk-jdk10 阅读 17 收藏 0 点赞 0 评论 0
@Override
public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){
    Objects.requireNonNull(sourceFormat);
    if( (targetEncoding.equals( AudioFormat.Encoding.PCM_SIGNED ) && sourceFormat.getEncoding().equals( AudioFormat.Encoding.ALAW)) ||
        (targetEncoding.equals( AudioFormat.Encoding.ALAW) && sourceFormat.getEncoding().equals( AudioFormat.Encoding.PCM_SIGNED)) ) {
            return getOutputFormats( sourceFormat );
        } else {
            return new AudioFormat[0];
        }
}
AudioFloatFormatConverter.java 文件源码 项目:openjdk-jdk10 阅读 19 收藏 0 点赞 0 评论 0
@Override
public AudioInputStream getAudioInputStream(AudioFormat targetFormat,
                                            AudioInputStream sourceStream) {
    if (!isConversionSupported(targetFormat, sourceStream.getFormat()))
        throw new IllegalArgumentException("Unsupported conversion: "
                + sourceStream.getFormat().toString() + " to "
                + targetFormat.toString());
    return getAudioInputStream(targetFormat, AudioFloatInputStream
            .getInputStream(sourceStream));
}


问题


面经


文章

微信
公众号

扫码关注公众号