本文整理汇总了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);
}
示例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() );
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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);
}
示例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())));
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
}
示例14: BasicAudioOut
import javax.sound.sampled.AudioFormat; //导入方法依赖的package包/类
public BasicAudioOut(AudioFormat format, int bufferSize)
{
this.format = format;
buffer = new MultiChannelBuffer(bufferSize, format.getChannels());
}
示例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);
}