本文整理汇总了Java中javax.sound.sampled.AudioFormat.getSampleRate方法的典型用法代码示例。如果您正苦于以下问题:Java AudioFormat.getSampleRate方法的具体用法?Java AudioFormat.getSampleRate怎么用?Java AudioFormat.getSampleRate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.sampled.AudioFormat
的用法示例。
在下文中一共展示了AudioFormat.getSampleRate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: getSignOrEndianChangedFormat
import javax.sound.sampled.AudioFormat; //导入方法依赖的package包/类
protected static AudioFormat getSignOrEndianChangedFormat(AudioFormat format) {
boolean isSigned = format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED);
boolean isUnsigned = format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED);
if (format.getSampleSizeInBits() > 8 && isSigned) {
// if this is PCM_SIGNED and 16-bit or higher, then try with endian-ness magic
return new AudioFormat(format.getEncoding(),
format.getSampleRate(), format.getSampleSizeInBits(), format.getChannels(),
format.getFrameSize(), format.getFrameRate(), !format.isBigEndian());
}
else if (format.getSampleSizeInBits() == 8 && (isSigned || isUnsigned)) {
// if this is PCM and 8-bit, then try with signed-ness magic
return new AudioFormat(isSigned?AudioFormat.Encoding.PCM_UNSIGNED:AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate(), format.getSampleSizeInBits(), format.getChannels(),
format.getFrameSize(), format.getFrameRate(), format.isBigEndian());
}
return null;
}
示例4: getAudioInputStream
import javax.sound.sampled.AudioFormat; //导入方法依赖的package包/类
@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() );
}
}
示例5: 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;
}
示例6: isFullySpecifiedPCMFormat
import javax.sound.sampled.AudioFormat; //导入方法依赖的package包/类
static boolean isFullySpecifiedPCMFormat(AudioFormat format) {
if (!format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)
&& !format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED)) {
return false;
}
if ((format.getFrameRate() <= 0)
|| (format.getSampleRate() <= 0)
|| (format.getSampleSizeInBits() <= 0)
|| (format.getFrameSize() <= 0)
|| (format.getChannels() <= 0)) {
return false;
}
return true;
}
示例7: getOtherChannels
import javax.sound.sampled.AudioFormat; //导入方法依赖的package包/类
public static AudioFormat getOtherChannels(AudioFormat format, int newChannels) {
int newFrameSize;
if (newChannels <= 0 || format.getChannels() <= 0 || format.getFrameSize() <= 0) {
newFrameSize = -1;
} else {
newFrameSize = format.getFrameSize() / format.getChannels() * newChannels;
}
return new AudioFormat(format.getEncoding(),
format.getSampleRate(),
format.getSampleSizeInBits(),
newChannels,
newFrameSize,
format.getFrameRate(),
format.isBigEndian());
}
示例8: getAudioSample
import javax.sound.sampled.AudioFormat; //导入方法依赖的package包/类
public AudioSample getAudioSample(float[] left, float[] right, AudioFormat format, int bufferSize)
{
FloatSampleBuffer sample = new FloatSampleBuffer(2, left.length, format.getSampleRate());
System.arraycopy(left, 0, sample.getChannel(0), 0, left.length);
System.arraycopy(right, 0, sample.getChannel(1), 0, right.length);
return getAudioSampleImp(sample, format, bufferSize);
}
示例9: 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;
}
示例10: AudioFloatInputStreamChannelMixer
import javax.sound.sampled.AudioFormat; //导入方法依赖的package包/类
AudioFloatInputStreamChannelMixer(AudioFloatInputStream ais,
int targetChannels) {
this.sourceChannels = ais.getFormat().getChannels();
this.targetChannels = targetChannels;
this.ais = ais;
AudioFormat format = ais.getFormat();
targetFormat = new AudioFormat(format.getEncoding(), format
.getSampleRate(), format.getSampleSizeInBits(),
targetChannels, (format.getFrameSize() / sourceChannels)
* targetChannels, format.getFrameRate(), format
.isBigEndian());
}
示例11: newSimpleFFTSample_dist
import javax.sound.sampled.AudioFormat; //导入方法依赖的package包/类
public static SF2Sample newSimpleFFTSample_dist(SF2Soundbank sf2,
String name, double[] data, double base, double preamp) {
int fftsize = data.length / 2;
AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
double basefreq = (base / fftsize) * format.getSampleRate() * 0.5;
randomPhase(data);
ifft(data);
data = realPart(data);
for (int i = 0; i < data.length; i++) {
data[i] = (1 - Math.exp(-Math.abs(data[i] * preamp)))
* Math.signum(data[i]);
}
normalize(data, 0.9);
float[] fdata = toFloat(data);
fdata = loopExtend(fdata, fdata.length + 512);
fadeUp(fdata, 80);
byte[] bdata = toBytes(fdata, format);
/*
* Create SoundFont2 sample.
*/
SF2Sample sample = new SF2Sample(sf2);
sample.setName(name);
sample.setData(bdata);
sample.setStartLoop(256);
sample.setEndLoop(fftsize + 256);
sample.setSampleRate((long) format.getSampleRate());
double orgnote = (69 + 12)
+ (12 * Math.log(basefreq / 440.0) / Math.log(2));
sample.setOriginalPitch((int) orgnote);
sample.setPitchCorrection((byte) (-(orgnote - (int) orgnote) * 100.0));
sf2.addResource(sample);
return sample;
}
示例12: 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())));
}
}
示例13: getAudioFileFormat
import javax.sound.sampled.AudioFormat; //导入方法依赖的package包/类
/**
* Returns the AudioFileFormat describing the file that will be written from this AudioInputStream.
* Throws IllegalArgumentException if not supported.
*/
private AudioFileFormat getAudioFileFormat(Type type, AudioInputStream stream) {
if (!isFileTypeSupported(type, stream)) {
throw new IllegalArgumentException("File type " + type + " not supported.");
}
AudioFormat streamFormat = stream.getFormat();
AudioFormat.Encoding encoding = streamFormat.getEncoding();
if (AudioFormat.Encoding.PCM_UNSIGNED.equals(encoding)) {
encoding = AudioFormat.Encoding.PCM_SIGNED;
}
// We always write big endian au files, this is by far the standard
AudioFormat format = new AudioFormat(encoding,
streamFormat.getSampleRate(),
streamFormat.getSampleSizeInBits(),
streamFormat.getChannels(),
streamFormat.getFrameSize(),
streamFormat.getFrameRate(), true);
int fileSize;
if (stream.getFrameLength() != AudioSystem.NOT_SPECIFIED) {
fileSize = (int)stream.getFrameLength()*streamFormat.getFrameSize() + AuFileFormat.AU_HEADERSIZE;
} else {
fileSize = AudioSystem.NOT_SPECIFIED;
}
return new AuFileFormat(Type.AU, fileSize, format,
(int) stream.getFrameLength());
}
示例14: 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);
}
示例15: newSimpleFFTSample
import javax.sound.sampled.AudioFormat; //导入方法依赖的package包/类
public static SF2Sample newSimpleFFTSample(SF2Soundbank sf2, String name,
double[] data, double base, int fadeuptime) {
int fftsize = data.length / 2;
AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
double basefreq = (base / fftsize) * format.getSampleRate() * 0.5;
randomPhase(data);
ifft(data);
data = realPart(data);
normalize(data, 0.9);
float[] fdata = toFloat(data);
fdata = loopExtend(fdata, fdata.length + 512);
fadeUp(fdata, fadeuptime);
byte[] bdata = toBytes(fdata, format);
/*
* Create SoundFont2 sample.
*/
SF2Sample sample = new SF2Sample(sf2);
sample.setName(name);
sample.setData(bdata);
sample.setStartLoop(256);
sample.setEndLoop(fftsize + 256);
sample.setSampleRate((long) format.getSampleRate());
double orgnote = (69 + 12)
+ (12 * Math.log(basefreq / 440.0) / Math.log(2));
sample.setOriginalPitch((int) orgnote);
sample.setPitchCorrection((byte) (-(orgnote - (int) orgnote) * 100.0));
sf2.addResource(sample);
return sample;
}