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


Java AudioFormat.getChannels方法代碼示例

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


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

示例1: getAudioInputStream

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:17,代碼來源:AudioFloatFormatConverter.java

示例2: getAudioInputStream

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
/**
 */
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 getAudioInputStream( targetFormat, sourceStream );

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

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:23,代碼來源:PCMtoPCMCodec.java

示例3: byte2float

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
/**
 * @param output an array of float[] arrays
 * @param allowAddChannel if true, and output has fewer channels than
 *            format, then only output.length channels are filled
 * @throws ArrayIndexOutOfBoundsException if output does not
 *             format.getChannels() elements
 * @see #byte2float(byte[] input, int inByteOffset, Object[] output, int
 *      outOffset, int frameCount, AudioFormat format, boolean
 *      allowAddChannel)
 */
public static void byte2float(byte[] input, int inByteOffset,
		Object[] output, int outOffset, int frameCount, AudioFormat format,
		boolean allowAddChannel) {

	int channels = format.getChannels();
	if (!allowAddChannel && channels > output.length) {
		channels = output.length;
	}
	if (output.length < channels) {
		throw new ArrayIndexOutOfBoundsException(
				"too few channel output array");
	}
	for (int channel = 0; channel < channels; channel++) {
		float[] data = (float[]) output[channel];
		if (data.length < frameCount + outOffset) {
			data = new float[frameCount + outOffset];
			output[channel] = data;
		}

		byte2floatGeneric(input, inByteOffset, format.getFrameSize(), data,
				outOffset, frameCount, format);
		inByteOffset += format.getFrameSize() / format.getChannels();
	}
}
 
開發者ID:JacobRoth,項目名稱:romanov,代碼行數:35,代碼來源:FloatSampleTools.java

示例4: validateFormat

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
/**
 * Tests that format contains the same data as were provided to the fake
 * stream.
 */
private static void validateFormat(final byte bits, final int rate,
                                   final int channel,
                                   final AudioFormat format) {

    if (Float.compare(format.getSampleRate(), rate) != 0) {
        System.out.println("Expected: " + rate);
        System.out.println("Actual: " + format.getSampleRate());
        throw new RuntimeException();
    }
    if (format.getChannels() != channel) {
        System.out.println("Expected: " + channel);
        System.out.println("Actual: " + format.getChannels());
        throw new RuntimeException();
    }
    int frameSize = ((bits + 7) / 8) * channel;
    if (format.getFrameSize() != frameSize) {
        System.out.println("Expected: " + frameSize);
        System.out.println("Actual: " + format.getFrameSize());
        throw new RuntimeException();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:RecognizeHugeAuFiles.java

示例5: getPCMConvertedAudioInputStream

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
public static AudioInputStream getPCMConvertedAudioInputStream(AudioInputStream ais) {
    // we can't open the device for non-PCM playback, so we have
    // convert any other encodings to PCM here (at least we try!)
    AudioFormat af = ais.getFormat();

    if( (!af.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) &&
        (!af.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED))) {

        try {
            AudioFormat newFormat =
                new AudioFormat( AudioFormat.Encoding.PCM_SIGNED,
                                 af.getSampleRate(),
                                 16,
                                 af.getChannels(),
                                 af.getChannels() * 2,
                                 af.getSampleRate(),
                                 Platform.isBigEndian());
            ais = AudioSystem.getAudioInputStream(newFormat, ais);
        } catch (Exception e) {
            if (Printer.err) e.printStackTrace();
            ais = null;
        }
    }

    return ais;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:27,代碼來源:Toolkit.java

示例6: toLittleEndian

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
private AudioInputStream toLittleEndian(AudioInputStream ais) {
    AudioFormat format = ais.getFormat();
    AudioFormat targetFormat = new AudioFormat(format.getEncoding(), format
            .getSampleRate(), format.getSampleSizeInBits(), format
            .getChannels(), format.getFrameSize(), format.getFrameRate(),
            false);
    return AudioSystem.getAudioInputStream(targetFormat, ais);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:WaveFloatFileWriter.java

示例7: isFullySpecifiedAudioFormat

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
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())));
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:35,代碼來源:Toolkit.java

示例8: isConversionSupported

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
@Override
public boolean isConversionSupported(AudioFormat targetFormat,
                                     AudioFormat sourceFormat) {
    Objects.requireNonNull(targetFormat);
    if (AudioFloatConverter.getConverter(sourceFormat) == null)
        return false;
    if (AudioFloatConverter.getConverter(targetFormat) == null)
        return false;
    if (sourceFormat.getChannels() <= 0)
        return false;
    if (targetFormat.getChannels() <= 0)
        return false;
    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:AudioFloatFormatConverter.java

示例9: isConversionSupported

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
public boolean isConversionSupported(AudioFormat targetFormat,
        AudioFormat sourceFormat) {
    if (AudioFloatConverter.getConverter(sourceFormat) == null)
        return false;
    if (AudioFloatConverter.getConverter(targetFormat) == null)
        return false;
    if (sourceFormat.getChannels() <= 0)
        return false;
    if (targetFormat.getChannels() <= 0)
        return false;
    return true;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:13,代碼來源:AudioFloatFormatConverter.java

示例10: AudioFloatInputStreamResampler

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
public AudioFloatInputStreamResampler(AudioFloatInputStream ais,
        AudioFormat format) {
    this.ais = ais;
    AudioFormat sourceFormat = ais.getFormat();
    targetFormat = new AudioFormat(sourceFormat.getEncoding(), format
            .getSampleRate(), sourceFormat.getSampleSizeInBits(),
            sourceFormat.getChannels(), sourceFormat.getFrameSize(),
            format.getSampleRate(), sourceFormat.isBigEndian());
    nrofchannels = targetFormat.getChannels();
    Object interpolation = format.getProperty("interpolation");
    if (interpolation != null && (interpolation instanceof String)) {
        String resamplerType = (String) interpolation;
        if (resamplerType.equalsIgnoreCase("point"))
            this.resampler = new SoftPointResampler();
        if (resamplerType.equalsIgnoreCase("linear"))
            this.resampler = new SoftLinearResampler2();
        if (resamplerType.equalsIgnoreCase("linear1"))
            this.resampler = new SoftLinearResampler();
        if (resamplerType.equalsIgnoreCase("linear2"))
            this.resampler = new SoftLinearResampler2();
        if (resamplerType.equalsIgnoreCase("cubic"))
            this.resampler = new SoftCubicResampler();
        if (resamplerType.equalsIgnoreCase("lanczos"))
            this.resampler = new SoftLanczosResampler();
        if (resamplerType.equalsIgnoreCase("sinc"))
            this.resampler = new SoftSincResampler();
    }
    if (resampler == null)
        resampler = new SoftLinearResampler2(); // new
    // SoftLinearResampler2();
    pitch[0] = sourceFormat.getSampleRate() / format.getSampleRate();
    pad = resampler.getPadding();
    pad2 = pad * 2;
    ibuffer = new float[nrofchannels][buffer_len + pad2];
    ibuffer2 = new float[nrofchannels * buffer_len];
    ibuffer_index = buffer_len + pad;
    ibuffer_len = buffer_len;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:39,代碼來源:SoftMixingDataLine.java

示例11: getOtherBits

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
public static AudioFormat getOtherBits(AudioFormat format, int newBits) {
    boolean isSigned = format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED);
    return new AudioFormat(format.getSampleRate(),
                           newBits,
                           format.getChannels(),
                           isSigned,
                           (newBits>8)?format.isBigEndian():false);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:PlugHwMonoAnd8bitAvailable.java

示例12: AudioFloatInputStreamResampler

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
AudioFloatInputStreamResampler(AudioFloatInputStream ais,
        AudioFormat format) {
    this.ais = ais;
    AudioFormat sourceFormat = ais.getFormat();
    targetFormat = new AudioFormat(sourceFormat.getEncoding(), format
            .getSampleRate(), sourceFormat.getSampleSizeInBits(),
            sourceFormat.getChannels(), sourceFormat.getFrameSize(),
            format.getSampleRate(), sourceFormat.isBigEndian());
    nrofchannels = targetFormat.getChannels();
    Object interpolation = format.getProperty("interpolation");
    if (interpolation != null && (interpolation instanceof String)) {
        String resamplerType = (String) interpolation;
        if (resamplerType.equalsIgnoreCase("point"))
            this.resampler = new SoftPointResampler();
        if (resamplerType.equalsIgnoreCase("linear"))
            this.resampler = new SoftLinearResampler2();
        if (resamplerType.equalsIgnoreCase("linear1"))
            this.resampler = new SoftLinearResampler();
        if (resamplerType.equalsIgnoreCase("linear2"))
            this.resampler = new SoftLinearResampler2();
        if (resamplerType.equalsIgnoreCase("cubic"))
            this.resampler = new SoftCubicResampler();
        if (resamplerType.equalsIgnoreCase("lanczos"))
            this.resampler = new SoftLanczosResampler();
        if (resamplerType.equalsIgnoreCase("sinc"))
            this.resampler = new SoftSincResampler();
    }
    if (resampler == null)
        resampler = new SoftLinearResampler2(); // new
                                                // SoftLinearResampler2();
    pitch[0] = sourceFormat.getSampleRate() / format.getSampleRate();
    pad = resampler.getPadding();
    pad2 = pad * 2;
    ibuffer = new float[nrofchannels][buffer_len + pad2];
    ibuffer2 = new float[nrofchannels * buffer_len];
    ibuffer_index = buffer_len + pad;
    ibuffer_len = buffer_len;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:39,代碼來源:AudioFloatFormatConverter.java

示例13: open

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
public void open(AudioFormat format, byte[] data, int offset, int bufferSize)
        throws LineUnavailableException {
    synchronized (control_mutex) {
        if (isOpen()) {
            throw new IllegalStateException(
                    "Clip is already open with format " + getFormat()
                            + " and frame lengh of " + getFrameLength());
        }
        if (AudioFloatConverter.getConverter(format) == null)
            throw new IllegalArgumentException("Invalid format : "
                    + format.toString());
        if (bufferSize % format.getFrameSize() != 0)
            throw new IllegalArgumentException(
                    "Buffer size does not represent an integral number of sample frames!");

        if (data != null) {
            this.data = Arrays.copyOf(data, data.length);
        }
        this.offset = offset;
        this.bufferSize = bufferSize;
        this.format = format;
        this.framesize = format.getFrameSize();

        loopstart = 0;
        loopend = -1;
        loop_sg = true;

        if (!mixer.isOpen()) {
            mixer.open();
            mixer.implicitOpen = true;
        }

        outputformat = mixer.getFormat();
        out_nrofchannels = outputformat.getChannels();
        in_nrofchannels = format.getChannels();

        open = true;

        mixer.getMainMixer().openLine(this);
    }

}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:43,代碼來源:SoftMixingClip.java

示例14: BasicAudioOut

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
public BasicAudioOut(AudioFormat format, int bufferSize)
{
	this.format = format;
	buffer = new MultiChannelBuffer(bufferSize, format.getChannels());
}
 
開發者ID:JacobRoth,項目名稱:romanov,代碼行數:6,代碼來源:BasicAudioOut.java

示例15: millisecondsToBytes

import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
public int millisecondsToBytes(AudioFormat fmt, int time)
{
	return (int)(time*(fmt.getSampleRate()*fmt.getChannels()*fmt.getSampleSizeInBits())/8000.0);
}
 
開發者ID:mahozad,項目名稱:jlayer,代碼行數:5,代碼來源:JavaSoundAudioDevice.java


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