public class AudioFormat extends Object
AudioFormat
是类指定一个特定的安排,在一个健全的数据流。通过检查存储在音频格式中的信息,您可以发现如何在二进制声音数据中解释比特。
每一数据线都有一个与它的数据流相关联的音频格式。源(回放)数据线的音频格式表示什么样的数据线预计将接收输出。对于一个目标(捕获)数据线,音频格式指定可以从该行读取的数据的种类。声音文件也有音频格式,当然。的
类封装到另外一个AudioFileFormat
AudioFormat
,文件的具体信息。同样,一个
有AudioInputStream
AudioFormat
。
的AudioFormat
类适应一些常见的声音文件的编码技术,包括脉冲编码调制(PCM),μ律编码,和A律编码。这些编码技术是预定义的,但服务提供商可以创建新的编码类型。编码一个特定的格式,采用的是由其encoding
字段命名。
除了编码,音频格式还包括其他属性,进一步指定数据的精确排列。这些包括信道的数目,采样速率,样本大小,字节顺序,帧速率和帧大小。声音可能有不同数量的音频通道:一个用于单声道,两个立体声。采样率测量了每通道每秒的声压的“快照”(样本)的多少。(如果声音是立体声,而不是单声道,两个样本实际上是测量在每个时刻的时间:一个为左声道,另一个为正确的通道;然而,采样率仍然测量每通道的数量,所以率是相同的,无论通道的数量。这是一个标准使用的术语)的样本大小表示有多少位是用来存储每个快照;8和16是典型的值。16位样本(或任何其他样本大小大于一个字节),字节顺序是重要的;每个样本的字节排列的“小端”或“大端”风格。如PCM编码,帧由所有通道的样品在给定的时间点,所以一帧的大小(以字节为单位)等于一个样本的大小(以字节为单位)的通道数倍。然而,随着编码帧可以包含一系列的样品一束压缩数据的一些其他种类,以及额外的,非样本数据。对于这样的编码,在解码成PCM采样率和样本大小的参考数据,所以它们是完全不同的帧速率和帧大小。
一个AudioFormat
对象可以包括一组属性。房地产是一对键和值:关键是String
型,相关的属性值是一个任意的对象。属性指定附加格式规范,如压缩格式的比特率。属性主要用来作为一种工具来传输音频格式的附加信息和来自服务提供商的信息。因此,在matches(AudioFormat)
方法忽略性能。然而,依靠安装服务商的方法,如(AudioFormat, AudioFormat) isConversionSupported
可以考虑性能,取决于各自的服务提供者实现。
下表列出了服务提供商应该使用的一些常见属性,如果适用的话:
Property key | Value type | 描述 |
---|---|---|
"bitrate" | Integer |
average bit rate in bits per second |
"vbr" | Boolean |
true , if the file is encoded in variable bit rate (VBR) |
"quality" | Integer |
encoding/conversion quality, 1..100 |
鼓励服务提供商(插件)的供应商,寻求其他已经建立的属性在第三方插件的信息,并遵循相同的约定。
DataLine.getFormat()
,
AudioInputStream.getFormat()
,
AudioFileFormat
,
FormatConversionProvider
Modifier and Type | Class and Description |
---|---|
static class |
AudioFormat.Encoding
Encoding 类名称的数据表示用于音频流的具体类型。
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
bigEndian
指示音频数据存储在大端或小端序。
|
protected int |
channels
此格式的音频信道的数量(单声道的1,立体声的2)。
|
protected AudioFormat.Encoding |
encoding
这种格式使用的音频编码技术。
|
protected float |
frameRate
每秒播放或记录的帧的数目,用于具有此格式的声音。
|
protected int |
frameSize
有此格式的声音的每一帧中的字节数。
|
protected float |
sampleRate
每秒播放或记录的样本数,为具有此格式的声音。
|
protected int |
sampleSizeInBits
有此格式的声音的每个样本中的比特数。
|
Constructor and Description |
---|
AudioFormat(AudioFormat.Encoding encoding, float sampleRate, int sampleSizeInBits, int channels, int frameSize, float frameRate, boolean bigEndian)
构建与给定的参数
AudioFormat 。
|
AudioFormat(AudioFormat.Encoding encoding, float sampleRate, int sampleSizeInBits, int channels, int frameSize, float frameRate, boolean bigEndian, Map<String,Object> properties)
构建与给定的参数
AudioFormat 。
|
AudioFormat(float sampleRate, int sampleSizeInBits, int channels, boolean signed, boolean bigEndian)
构建一个线性PCM编码和给定参数的
AudioFormat 。
|
Modifier and Type | Method and Description |
---|---|
int |
getChannels()
获取信道数。
|
AudioFormat.Encoding |
getEncoding()
获取在此格式中的声音的编码类型。
|
float |
getFrameRate()
每秒帧中的帧速率。
|
int |
getFrameSize()
以字节获取帧大小。
|
Object |
getProperty(String key)
获取由键指定的属性值。
|
float |
getSampleRate()
获得样本率。
|
int |
getSampleSizeInBits()
获取样本的大小。
|
boolean |
isBigEndian()
指示音频数据存储在大端或小端字节序。
|
boolean |
matches(AudioFormat format)
指示此格式是否与指定的格式匹配。
|
Map<String,Object> |
properties()
获取一个属性不可修改的Map。
|
String |
toString()
返回一个字符串,描述的格式,如:“PCM签署22050赫兹16位单大端”。
|
protected AudioFormat.Encoding encoding
protected float sampleRate
protected int sampleSizeInBits
protected int channels
protected int frameSize
protected float frameRate
protected boolean bigEndian
public AudioFormat(AudioFormat.Encoding encoding, float sampleRate, int sampleSizeInBits, int channels, int frameSize, float frameRate, boolean bigEndian)
AudioFormat
。编码指定用来表示数据的约定。其他参数是在
class description
进一步解释。
encoding
-音频编码技术
sampleRate
-每秒采样数
sampleSizeInBits
在每个样本的位数
channels
-通道数(1单、2立体声,等等)
frameSize
-在每帧中的字节数
frameRate
-每秒的帧数
bigEndian
-指示是否为单一样本的数据存储在大端字节序(
false
意味着小端)
public AudioFormat(AudioFormat.Encoding encoding, float sampleRate, int sampleSizeInBits, int channels, int frameSize, float frameRate, boolean bigEndian, Map<String,Object> properties)
AudioFormat
。编码指定用来表示数据的约定。其他参数是在
class description
进一步解释。
encoding
-音频编码技术
sampleRate
-每秒采样数
sampleSizeInBits
在每个样本的位数
channels
-通道数(1单、2立体声,等等)
frameSize
-在每帧中的字节数
frameRate
-每秒的帧数
bigEndian
-指示是否为单一样本的数据存储在大端字节序(
false
意味着小端)
properties
-含有格式
Map<String,Object>
对象属性
public AudioFormat(float sampleRate, int sampleSizeInBits, int channels, boolean signed, boolean bigEndian)
AudioFormat
。帧大小设置为从每个通道中包含一个示例所需的字节数,并且将该帧速率设置为采样速率。
sampleRate
-每秒采样数
sampleSizeInBits
在每个样本的位数
channels
-通道数(1单、2立体声,等等)
signed
指示数据是否有符号或无符号
bigEndian
-指示是否为单一样本的数据存储在大端字节序(
false
意味着小端)
public AudioFormat.Encoding getEncoding()
public float getSampleRate()
AudioSystem.isConversionSupported
)或功能(例如
DataLine.Info.getFormats
),对
AudioSystem.NOT_SPECIFIED
意味着任何采样率的采样率是可以接受的。
AudioSystem.NOT_SPECIFIED
也回来时,采样率不是这个音频格式定义。
AudioSystem.NOT_SPECIFIED
getFrameRate()
,
AudioSystem.NOT_SPECIFIED
public int getSampleSizeInBits()
AudioSystem.isConversionSupported
)或功能(例如
DataLine.Info.getFormats
),样本大小
AudioSystem.NOT_SPECIFIED
意味着任何样本大小是可以接受的。
AudioSystem.NOT_SPECIFIED
也回来时,样本大小是不是这个音频格式定义。
AudioSystem.NOT_SPECIFIED
getFrameSize()
,
AudioSystem.NOT_SPECIFIED
public int getChannels()
AudioSystem.isConversionSupported
)或功能(例如
DataLine.Info.getFormats
),一个
AudioSystem.NOT_SPECIFIED
意味着任何返回值(正)通道的数量是可以接受的。
AudioSystem.NOT_SPECIFIED
AudioSystem.NOT_SPECIFIED
public int getFrameSize()
AudioSystem.isConversionSupported
)或功能(例如
DataLine.Info.getFormats
),帧大小
AudioSystem.NOT_SPECIFIED
意味着任何帧的大小是可以接受的。
AudioSystem.NOT_SPECIFIED
还回来时的帧大小是不是这个音频格式定义。
AudioSystem.NOT_SPECIFIED
getSampleSizeInBits()
,
AudioSystem.NOT_SPECIFIED
public float getFrameRate()
AudioSystem.isConversionSupported
)或功能(例如
DataLine.Info.getFormats
),一个
AudioSystem.NOT_SPECIFIED
意味着任何帧速率是可接受的帧速率。
AudioSystem.NOT_SPECIFIED
也返回时的帧速率不为这种音频格式定义。
AudioSystem.NOT_SPECIFIED
getSampleRate()
,
AudioSystem.NOT_SPECIFIED
public boolean isBigEndian()
true
如果数据存储在大端字节序,
false
如果小端
public Map<String,Object> properties()
class description
进一步解释。
Map<String,Object>
对象。如果没有确认属性,则返回一个空的Map。
getProperty(String)
public Object getProperty(String key)
class description
进一步解释。
如果指定的属性不为特定的文件格式定义,此方法返回null
。
key
-预期性能的关键
null
如果属性不存在。
properties()
public boolean matches(AudioFormat format)
AudioSystem.NOT_SPECIFIED
。字节顺序(大端或小端)必须相同,如果样本大小大于一个字节。
format
格式的测试赛
true
格式相匹配的一
false
指定,否则。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.