本文整理匯總了Java中javax.sound.sampled.AudioFormat.getFrameRate方法的典型用法代碼示例。如果您正苦於以下問題:Java AudioFormat.getFrameRate方法的具體用法?Java AudioFormat.getFrameRate怎麽用?Java AudioFormat.getFrameRate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.sound.sampled.AudioFormat
的用法示例。
在下文中一共展示了AudioFormat.getFrameRate方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例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: 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())));
}
}
示例4: 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());
}
示例5: 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;
}
示例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: getOtherEndianOrSign
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
public static AudioFormat getOtherEndianOrSign(AudioFormat format) {
AudioFormat.Encoding newEnc = null;
boolean newEndian = format.isBigEndian();
boolean isSigned = format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED);
boolean isUnsigned = format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED);
if ((isSigned || isUnsigned) && format.getSampleSizeInBits() > 0) {
if (format.getSampleSizeInBits() == 8) {
// return the other signed'ness
if (isSigned) {
newEnc = AudioFormat.Encoding.PCM_UNSIGNED;
} else {
newEnc = AudioFormat.Encoding.PCM_SIGNED;
}
} else {
newEnc = format.getEncoding();
newEndian = !newEndian;
}
if (newEnc != null) {
return new AudioFormat(newEnc, format.getSampleRate(),
format.getSampleSizeInBits(),
format.getChannels(),
format.getFrameSize(),
format.getFrameRate(),
newEndian);
}
}
return null;
}
示例8: 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());
}
示例9: open
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
public void open(AudioFormat format) throws LineUnavailableException {
if (bufferSize == -1)
bufferSize = ((int) (format.getFrameRate() / 2))
* format.getFrameSize();
open(format, bufferSize);
}
示例10: determineProperties
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
/**
* Determines Properties when the File/URL/InputStream is opened.
*/
private void determineProperties() {
logger.info("Entered determineProperties()!\n");
// Add AudioFileFormat properties.
// Expect if it is null(something bad happened).
if (audioFileFormat == null)
return;
if (! ( audioFileFormat instanceof TAudioFileFormat ))
audioProperties = new HashMap<>();
else {
// Tritonus SPI compliant audio file format.
audioProperties = ( (TAudioFileFormat) audioFileFormat ).properties();
// Clone the Map because it is not mutable.
audioProperties = deepCopy(audioProperties);
}
// Add JavaSound properties.
if (audioFileFormat.getByteLength() > 0)
audioProperties.put("audio.length.bytes", audioFileFormat.getByteLength());
if (audioFileFormat.getFrameLength() > 0)
audioProperties.put("audio.length.frames", audioFileFormat.getFrameLength());
if (audioFileFormat.getType() != null)
audioProperties.put("audio.type", audioFileFormat.getType());
// AudioFormat properties.
AudioFormat audioFormat = audioFileFormat.getFormat();
if (audioFormat.getFrameRate() > 0)
audioProperties.put("audio.framerate.fps", audioFormat.getFrameRate());
if (audioFormat.getFrameSize() > 0)
audioProperties.put("audio.framesize.bytes", audioFormat.getFrameSize());
if (audioFormat.getSampleRate() > 0)
audioProperties.put("audio.samplerate.hz", audioFormat.getSampleRate());
if (audioFormat.getSampleSizeInBits() > 0)
audioProperties.put("audio.samplesize.bits", audioFormat.getSampleSizeInBits());
if (audioFormat.getChannels() > 0)
audioProperties.put("audio.channels", audioFormat.getChannels());
// Tritonus SPI compliant audio format.
if (audioFormat instanceof TAudioFormat)
audioProperties.putAll( ( (TAudioFormat) audioFormat ).properties());
// Add SourceDataLine
audioProperties.put("basicplayer.sourcedataline", sourceDataLine);
// Keep this final reference for the lambda expression
final Map<String,Object> audioPropertiesCopy = audioProperties;
// Notify all registered StreamPlayerListeners
listeners.forEach(listener -> listener.opened(dataSource, audioPropertiesCopy));
logger.info("Exited determineProperties()!\n");
}
示例11: bytes2Ms
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
public static long bytes2Ms(long bytes, AudioFormat format) {
return (long) (bytes/format.getFrameRate()*1000/format.getFrameSize());
}
示例12: bytes2Ms
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
public static long bytes2Ms(long bytes, AudioFormat format) {
return (long) (bytes / format.getFrameRate() * 1000
/ format.getFrameSize());
}
示例13: bytes2millis
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
static long bytes2millis(AudioFormat format, long bytes) {
return (long) (bytes / format.getFrameRate() * 1000.0f / format.getFrameSize());
}
示例14: micros2bytes
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
static long micros2bytes(AudioFormat format, long micros) {
long result = (long) (micros * format.getFrameRate() / 1000000.0f * format.getFrameSize());
return align(result, format.getFrameSize());
}